-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Conversation
src/commands/navigation.ts
Outdated
'npx expo install react-native-screens react-native-safe-area-context', | ||
); | ||
} | ||
// what if it is not expo? |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
e732ac6
to
ff8d262
Compare
@stevehanson - I updated the tests and everything passes fine on the generated app but |
ff8d262
to
d187d88
Compare
I think I've fixed that in the latest update. |
Things work well on my local machine but fails on the CI 😞 |
@rakeshpetit Can you try adding the file name |
import { Home } from '../App'; | ||
|
||
test('renders', () => { | ||
expect(true).toBe(true); |
There was a problem hiding this comment.
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?
templates/reactNavigation/App.tsx
Outdated
export function Home() { | ||
return ( | ||
<View style={styles.container}> | ||
<Text>Open up App.js to start working on your app!</Text> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<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 :)
Adding |
81f63ed
to
6b95dc5
Compare
There was a problem hiding this 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
templates/reactNavigation/App.tsx
Outdated
); | ||
} | ||
|
||
export default function App() { |
There was a problem hiding this comment.
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 .
There was a problem hiding this comment.
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 .
templates/reactNavigation/App.tsx
Outdated
); | ||
} | ||
|
||
function RootStackNavigator() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
93ccb2a
to
e1b83d9
Compare
- Refactor navigators to be in a navigators folder - Add navigator types and global types - Add HomeScreen
Taking a look at this now to see what's left to get it to the finish line. |
Co-authored-by: Frida Casas <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work!
This PR is an attempt to add React Navigation and a stack navigator to the scaffolded Expo app.
Todo
yarn thoughtbelt navigation
which I couldn't do.Success flow