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 Bottom Tabs (rebased) #35

Merged
merged 28 commits into from
Apr 26, 2024
Merged

Conversation

adriantoddross
Copy link
Contributor

@adriantoddross adriantoddross commented Mar 13, 2024

  • Add reactNavigation, and reactNavigationBottomTabs files into boilerplate template
  • Set up app with bottom tab navigation by default
  • Remove addNavigation command and its tests

Rebase of #28.

@adriantoddross
Copy link
Contributor Author

Still need to:

  • Fix type errors in bottomTabs template
  • Set up confirm prompt for bottomTabs

@adriantoddross adriantoddross marked this pull request as ready for review March 26, 2024 19:45
@adriantoddross
Copy link
Contributor Author

This is ready for review! Looking forward to your feedback.

@adriantoddross
Copy link
Contributor Author

I'm seeing test errors after setting up a new app with bottom tabs now:

console.error
    Warning: An update to ForwardRef inside a test was not wrapped in act(...).

    When testing, code that causes React state updates should be wrapped into act(...):

    act(() => {
      /* fire events that update state */
    });
    /* assert on the output */

    This ensures that you're testing the behavior the user would see in the browser. Learn more at https://reactjs.org/link/wrap-tests-with-act
....
ReferenceError: You are trying to access a property or method of the Jest environment after it has been torn down. From src/__tests__/App.test.tsx.

      at Timeout.now [as _onTimeout] (node_modules/react-native/jest/setup.js:48:55)

And an error from the test in the App.test.tsx file directly:

`loadSingleFontAsync` expected resource of type `Asset` from expo-asset on native

      10 | // tests can be wrapped with appropriate providers, mocks can be supplied, etc
      11 | export default function render(element: ReactElement): RenderAPI {
    > 12 |   return TestingLibraryRender(
         |                              ^
      13 |     <NavigationContainer>{element}</NavigationContainer>,
      14 |   );
      15 | }

      at node_modules/expo-font/src/FontLoader.ts:46:11

@adriantoddross
Copy link
Contributor Author

Got the Jest errors resolved.

@stevehanson
Copy link

@adriantoddross I'm taking a look at this now! Is it ok if I push up some changes directly to this branch?

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 a great start! Since my time is limited to only reviewing on Fridays, I went ahead and implemented some suggested changes in a branch based off of yours. With the complexity of the feature and the number of small things to point out, it was more efficient this way than to have back-and-forth.

See the diff here along with a description of the changes in the commit message. Happy to circle back on any of the changes from there. If you want to use my commit, you can pull it in with git cherry-pick da2bfc9, or feel free to ping me about any thoughts or questions!

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.

Thanks again for working on this! Leaving some more feedback since I didn't have time for a full review on Friday. I hope this is enough to go on if you're working on this this week.

@@ -0,0 +1,19 @@
import { NavigationContainer } from '@react-navigation/native';

Choose a reason for hiding this comment

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

templates/boilerplate already includes this file, and we don't want to overwrite it when installing React Navigation. What changes were needed here? Is it possible to instead use the CODEGEN:BELT:PROVIDERS injection point? I believe Diego's open Push Notifications PR, #34, might use this is you're looking for an example.

Choose a reason for hiding this comment

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

Since I think it will simplify things considerably, I also am in favor of removing addNavigation as a top-level CLI command and only supporting installing it in new apps (i.e. as part of createApp). For existing apps, it seems like we would have to make a lot of assumptions for how they're structured to be able to install something as foundational as navigation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with removing addNavigation as a top level CLI. I'll need to come back and take look at the CODEGEN:BELT:PROVIDERS injection bit here.

Choose a reason for hiding this comment

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

I think I lean toward installing React Navigation with bottom tabs for all new apps and not having it be configurable in Belt for now. This seems simpler to build into Belt, and users can always remove the bottom tabs if desired, or we could add support for making bottom tabs optional in Belt down the road.

If we install React Navigation (plus bottom tabs) as part of createApp, then the navigation code can just be part of templates/boilerplate, and we wouldn't need to do any injection.

@adriantoddross
Copy link
Contributor Author

This is a great start! Since my time is limited to only reviewing on Fridays, I went ahead and implemented some suggested changes in a branch based off of yours. With the complexity of the feature and the number of small things to point out, it was more efficient this way than to have back-and-forth.

See the diff here along with a description of the changes in the commit message. Happy to circle back on any of the changes from there. If you want to use my commit, you can pull it in with git cherry-pick da2bfc9, or feel free to ping me about any thoughts or questions!

Nice! I'm on Space Station this week and will take a look!

adriantoddross and others added 5 commits April 9, 2024 12:39
* Rename RootNavigator to TabNavigator
* Create higher level RootNavigator that can have screens outside tabs
* Switch from Material Bottom Tabs to regular Bottom Tabs navigator. Our
  experience is mostly with the regular navigator, but I'm open to
  exploring the Material version in a future PR. For this PR, there were
  some odd styles coming through, and taps weren't always recognized
  for some reason.
* Update navigator types
* Update screens to use useNavigation and useRoute. This helps provide a
  consistent experience whether we're in the top-level screen component
  that gets the navigation and route params, or we're down lower in the
  stack
@adriantoddross adriantoddross force-pushed the atr&wl-nav-bottom-tabs branch from 69a3906 to 9e45bcf Compare April 9, 2024 19:43
@adriantoddross
Copy link
Contributor Author

adriantoddross commented Apr 9, 2024

This is ready for another look. It feels a bit easier to digest and review now.

Seems like most of the work that was left on this was removing addNavigation and updating the dependencies in the boilerplate template needed for bottom tab navigation. Is that right? @stevehanson

I've pulled in your work and made those changes. I'm not sure how our tests should change or what we should add.

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 @adriantoddross! I'm going to go ahead and merge!

@stevehanson stevehanson merged commit ab38f6b into main Apr 26, 2024
2 checks passed
@stevehanson stevehanson deleted the atr&wl-nav-bottom-tabs branch April 26, 2024 14:17
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.

3 participants