Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add React Navigation support #22

Merged
merged 11 commits into from
Dec 12, 2023
Merged

Conversation

rakeshpetit
Copy link
Contributor

@rakeshpetit rakeshpetit commented Nov 24, 2023

This PR is an attempt to add React Navigation and a stack navigator to the scaffolded Expo app.

Todo

  • Test yarn thoughtbelt navigation which I couldn't do.

Success flow

image

'npx expo install react-native-screens react-native-safe-area-context',
);
}
// what if it is not expo?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do we do for non Expo projects?

Copy link
Contributor

@codeofdiego codeofdiego Dec 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we already have support for react-native-cli? Or just Expo? If the project is not expo we just go through the bare workflow with install react-native-screens react-native-safe-area-context but we might need to be sensitive to what is the package manager being used, like we do in this PR.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our philosophy so far has been to try to support Expo and bare RN, but I'd say we are only doing active testing against Expo at this point. But yes, I agree with Diego that if the project is not Expo, we should just do what the React Navigation docs recommend. If we use our addDependency util, it will handle picking the right package manager.

@rakeshpetit rakeshpetit force-pushed the add-react-navigation-command branch from e732ac6 to ff8d262 Compare December 11, 2023 10:57
@rakeshpetit
Copy link
Contributor Author

@stevehanson - I updated the tests and everything passes fine on the generated app but thoughtbelt still seems to complain on the CI. Hope to pair and resolve this.

@rakeshpetit rakeshpetit force-pushed the add-react-navigation-command branch from ff8d262 to d187d88 Compare December 11, 2023 13:26
@rakeshpetit
Copy link
Contributor Author

@stevehanson - I updated the tests and everything passes fine on the generated app but thoughtbelt still seems to complain on the CI. Hope to pair and resolve this.

I think I've fixed that in the latest update.

@rakeshpetit
Copy link
Contributor Author

Things work well on my local machine but fails on the CI 😞

@codeofdiego
Copy link
Contributor

@rakeshpetit Can you try adding the file name "./**/*.tsx" to "include": ["./**/*.ts", "./**/*.tsx"], in tsconfig.json?

import { Home } from '../App';

test('renders', () => {
expect(true).toBe(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this expectation required to make something work?

export function Home() {
return (
<View style={styles.container}>
<Text>Open up App.js to start working on your app!</Text>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<Text>Open up App.js to start working on your app!</Text>
<Text>Open up App.tsx to start working on your app!</Text>

Just a typo in the App file extension :)

@rakeshpetit
Copy link
Contributor Author

@rakeshpetit Can you try adding the file name "./**/*.tsx" to "include": ["./**/*.ts", "./**/*.tsx"], in tsconfig.json?

Adding __tests__ to tsconfig solved the problem in commit

@rakeshpetit rakeshpetit force-pushed the add-react-navigation-command branch from 81f63ed to 6b95dc5 Compare December 11, 2023 15:22
@rakeshpetit rakeshpetit changed the title WIP - Add React Navigation support Add React Navigation support Dec 11, 2023
@rakeshpetit rakeshpetit marked this pull request as ready for review December 11, 2023 15:59
Copy link

@stevehanson stevehanson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking great! I left a few comments and would be happy to discuss or pair. A couple other thoughts that come to mind:

  • There are a few ways to type React Navigation projects. Do we want to set that up? (I vote yes! but could be a separate PR). I'm a strong believer that rigid types are essential for navigation, since some tests tend to mock out navigation calls and therefore never test that it works! I have a typing approach that worked fairly well for a recent project that I'd be happy to share
  • I'm curious what our thoughts are on eventually taking this a step further and implementing bottom tabs (probably after asking the user if they want them?) or a login screen. This isn't for this PR but would be an interesting discussion. It seems this functionality would help projects get off the ground quickly

);
}

export default function App() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we create a new app using thoughtbelt, we will want to generate an App.tsx that has all of our providers and tools configured, including React Navigation, global state provider, styling provider, etc. To me, since this file will be tied to many different commands, it would make more sense for the creation of this file to be a step at the end of the createApp command, independent of any one command.

If we run thoughtbelt navigation independently, we will not want to create a new App.tsx in that case, though it would likely be helpful to include some output directing the user to wrap their app in a NavigationContainer. What do you think?

We don't yet have a mechanism for detecting if a given command is running independently as opposed to being a part of the main createApp (or other) command .

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened a draft PR here #25 .

);
}

function RootStackNavigator() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually create a src/navigators directory for these. Curious what you prefer here? Ideally, thoughtbelt will be opinionated and create a file structure that makes sense as the app grows.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great comment. I wanted us to have this discussion in this PR and intentionally put all the navigators in App.tsx. Let's pair on this.

@rakeshpetit rakeshpetit force-pushed the add-react-navigation-command branch from 93ccb2a to e1b83d9 Compare December 12, 2023 17:07
- Refactor navigators to be in a navigators folder
- Add navigator types and global types
- Add HomeScreen
@stevehanson
Copy link

Taking a look at this now to see what's left to get it to the finish line.

Copy link
Contributor

@fridaland fridaland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@stevehanson stevehanson merged commit f536334 into main Dec 12, 2023
2 checks passed
@stevehanson stevehanson deleted the add-react-navigation-command branch December 12, 2023 21:57
Copy link

@stevehanson stevehanson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants