diff options
author | dan <dan.abramov@gmail.com> | 2025-06-09 20:29:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-09 22:29:53 +0300 |
commit | f93896346269b117556b13898eba9c162d6098b6 (patch) | |
tree | ac1468a21a4683db39327371110a96cdfa8afe48 /src/Navigation.tsx | |
parent | 42c4da1ec7f2ad560ef1dbf7477da02b1ed8ad2c (diff) | |
download | voidsky-f93896346269b117556b13898eba9c162d6098b6.tar.zst |
Update react-navigation (#5967)
Diffstat (limited to 'src/Navigation.tsx')
-rw-r--r-- | src/Navigation.tsx | 104 |
1 files changed, 42 insertions, 62 deletions
diff --git a/src/Navigation.tsx b/src/Navigation.tsx index 8b981df7c..2f26c0971 100644 --- a/src/Navigation.tsx +++ b/src/Navigation.tsx @@ -103,7 +103,7 @@ import { import {Wizard} from '#/screens/StarterPack/Wizard' import TopicScreen from '#/screens/Topic' import {VideoFeed} from '#/screens/VideoFeed' -import {useTheme} from '#/alf' +import {type Theme, useTheme} from '#/alf' import { EmailDialogScreenID, useEmailDialogControl, @@ -127,7 +127,7 @@ const Tab = createBottomTabNavigator<BottomTabNavigatorParams>() /** * These "common screens" are reused across stacks. */ -function commonScreens(Stack: typeof HomeTab, unreadCountLabel?: string) { +function commonScreens(Stack: typeof Flat, unreadCountLabel?: string) { const title = (page: MessageDescriptor) => bskyTitle(i18n._(page), unreadCountLabel) @@ -500,6 +500,10 @@ function TabsNavigator() { <Tab.Screen name="HomeTab" getComponent={() => HomeTabNavigator} /> <Tab.Screen name="SearchTab" getComponent={() => SearchTabNavigator} /> <Tab.Screen + name="MessagesTab" + getComponent={() => MessagesTabNavigator} + /> + <Tab.Screen name="NotificationsTab" getComponent={() => NotificationsTabNavigator} /> @@ -507,29 +511,26 @@ function TabsNavigator() { name="MyProfileTab" getComponent={() => MyProfileTabNavigator} /> - <Tab.Screen - name="MessagesTab" - getComponent={() => MessagesTabNavigator} - /> </Tab.Navigator> ) } +function screenOptions(t: Theme) { + return { + fullScreenGestureEnabled: true, + headerShown: false, + contentStyle: t.atoms.bg, + } as const +} + function HomeTabNavigator() { const t = useTheme() return ( - <HomeTab.Navigator - screenOptions={{ - animationDuration: 285, - gestureEnabled: true, - fullScreenGestureEnabled: true, - headerShown: false, - contentStyle: t.atoms.bg, - }}> + <HomeTab.Navigator screenOptions={screenOptions(t)} initialRouteName="Home"> <HomeTab.Screen name="Home" getComponent={() => HomeScreen} /> <HomeTab.Screen name="Start" getComponent={() => HomeScreen} /> - {commonScreens(HomeTab)} + {commonScreens(HomeTab as typeof Flat)} </HomeTab.Navigator> ) } @@ -538,15 +539,10 @@ function SearchTabNavigator() { const t = useTheme() return ( <SearchTab.Navigator - screenOptions={{ - animationDuration: 285, - gestureEnabled: true, - fullScreenGestureEnabled: true, - headerShown: false, - contentStyle: t.atoms.bg, - }}> + screenOptions={screenOptions(t)} + initialRouteName="Search"> <SearchTab.Screen name="Search" getComponent={() => SearchScreen} /> - {commonScreens(SearchTab as typeof HomeTab)} + {commonScreens(SearchTab as typeof Flat)} </SearchTab.Navigator> ) } @@ -555,19 +551,14 @@ function NotificationsTabNavigator() { const t = useTheme() return ( <NotificationsTab.Navigator - screenOptions={{ - animationDuration: 285, - gestureEnabled: true, - fullScreenGestureEnabled: true, - headerShown: false, - contentStyle: t.atoms.bg, - }}> + screenOptions={screenOptions(t)} + initialRouteName="Notifications"> <NotificationsTab.Screen name="Notifications" getComponent={() => NotificationsScreen} options={{requireAuth: true}} /> - {commonScreens(NotificationsTab as typeof HomeTab)} + {commonScreens(NotificationsTab as typeof Flat)} </NotificationsTab.Navigator> ) } @@ -576,23 +567,16 @@ function MyProfileTabNavigator() { const t = useTheme() return ( <MyProfileTab.Navigator - screenOptions={{ - animationDuration: 285, - gestureEnabled: true, - fullScreenGestureEnabled: true, - headerShown: false, - contentStyle: t.atoms.bg, - }}> + screenOptions={screenOptions(t)} + initialRouteName="MyProfile"> <MyProfileTab.Screen - // @ts-ignore // TODO: fix this broken type in ProfileScreen - name="MyProfile" + // MyProfile is not in AllNavigationParams - asserting as Profile at least + // gives us typechecking for initialParams -sfn + name={'MyProfile' as 'Profile'} getComponent={() => ProfileScreen} - initialParams={{ - name: 'me', - hideBackButton: true, - }} + initialParams={{name: 'me', hideBackButton: true}} /> - {commonScreens(MyProfileTab as typeof HomeTab)} + {commonScreens(MyProfileTab as unknown as typeof Flat)} </MyProfileTab.Navigator> ) } @@ -601,13 +585,8 @@ function MessagesTabNavigator() { const t = useTheme() return ( <MessagesTab.Navigator - screenOptions={{ - animationDuration: 285, - gestureEnabled: true, - fullScreenGestureEnabled: true, - headerShown: false, - contentStyle: t.atoms.bg, - }}> + screenOptions={screenOptions(t)} + initialRouteName="Messages"> <MessagesTab.Screen name="Messages" getComponent={() => MessagesScreen} @@ -616,7 +595,7 @@ function MessagesTabNavigator() { animationTypeForReplace: route.params?.animation ?? 'push', })} /> - {commonScreens(MessagesTab as typeof HomeTab)} + {commonScreens(MessagesTab as typeof Flat)} </MessagesTab.Navigator> ) } @@ -634,13 +613,7 @@ const FlatNavigator = () => { return ( <Flat.Navigator screenListeners={screenListeners} - screenOptions={{ - animationDuration: 285, - gestureEnabled: true, - fullScreenGestureEnabled: true, - headerShown: false, - contentStyle: t.atoms.bg, - }}> + screenOptions={screenOptions(t)}> <Flat.Screen name="Home" getComponent={() => HomeScreen} @@ -666,7 +639,7 @@ const FlatNavigator = () => { getComponent={() => HomeScreen} options={{title: title(msg`Home`)}} /> - {commonScreens(Flat as typeof HomeTab, numUnread)} + {commonScreens(Flat, numUnread)} </Flat.Navigator> ) } @@ -773,7 +746,14 @@ function RoutesContainer({children}: React.PropsWithChildren<{}>) { logModuleInitTime() onReady() logger.metric('router:navigate', {}, {statsig: false}) - }}> + }} + // WARNING: Implicit navigation to nested navigators is depreciated in React Navigation 7.x + // However, there's a fair amount of places we do that, especially in when popping to the top of stacks. + // See BottomBar.tsx for an example of how to handle nested navigators in the tabs correctly. + // I'm scared of missing a spot (esp. with push notifications etc) so let's enable this legacy behaviour for now. + // We will need to confirm we handle nested navigators correctly by the time we migrate to React Navigation 8.x + // -sfn + navigationInChildEnabled> {children} </NavigationContainer> </> |