improve navigation types

This commit is contained in:
Samuel Newman
2025-05-28 12:17:25 +03:00
parent 4625c0bda1
commit 0e0110aa13
2 changed files with 12 additions and 14 deletions
+11 -13
View File
@@ -127,7 +127,7 @@ const Tab = createBottomTabNavigator<BottomTabNavigatorParams>()
/** /**
* These "common screens" are reused across stacks. * 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) => const title = (page: MessageDescriptor) =>
bskyTitle(i18n._(page), unreadCountLabel) bskyTitle(i18n._(page), unreadCountLabel)
@@ -530,7 +530,7 @@ function HomeTabNavigator() {
}}> }}>
<HomeTab.Screen name="Home" getComponent={() => HomeScreen} /> <HomeTab.Screen name="Home" getComponent={() => HomeScreen} />
<HomeTab.Screen name="Start" getComponent={() => HomeScreen} /> <HomeTab.Screen name="Start" getComponent={() => HomeScreen} />
{commonScreens(HomeTab)} {commonScreens(HomeTab as typeof Flat)}
</HomeTab.Navigator> </HomeTab.Navigator>
) )
} }
@@ -548,7 +548,7 @@ function SearchTabNavigator() {
contentStyle: t.atoms.bg, contentStyle: t.atoms.bg,
}}> }}>
<SearchTab.Screen name="Search" getComponent={() => SearchScreen} /> <SearchTab.Screen name="Search" getComponent={() => SearchScreen} />
{commonScreens(SearchTab as typeof HomeTab)} {commonScreens(SearchTab as typeof Flat)}
</SearchTab.Navigator> </SearchTab.Navigator>
) )
} }
@@ -570,7 +570,7 @@ function NotificationsTabNavigator() {
getComponent={() => NotificationsScreen} getComponent={() => NotificationsScreen}
options={{requireAuth: true}} options={{requireAuth: true}}
/> />
{commonScreens(NotificationsTab as typeof HomeTab)} {commonScreens(NotificationsTab as typeof Flat)}
</NotificationsTab.Navigator> </NotificationsTab.Navigator>
) )
} }
@@ -588,15 +588,13 @@ function MyProfileTabNavigator() {
contentStyle: t.atoms.bg, contentStyle: t.atoms.bg,
}}> }}>
<MyProfileTab.Screen <MyProfileTab.Screen
// @ts-ignore // TODO: fix this broken type in ProfileScreen // MyProfile is not in AllNavigationParams - asserting as Profile at least
name="MyProfile" // gives us typechecking for initialParams -sfn
name={'MyProfile' as 'Profile'}
getComponent={() => ProfileScreen} getComponent={() => ProfileScreen}
initialParams={{ initialParams={{name: 'me', hideBackButton: true}}
name: 'me',
hideBackButton: true,
}}
/> />
{commonScreens(MyProfileTab as typeof HomeTab)} {commonScreens(MyProfileTab as unknown as typeof Flat)}
</MyProfileTab.Navigator> </MyProfileTab.Navigator>
) )
} }
@@ -621,7 +619,7 @@ function MessagesTabNavigator() {
animationTypeForReplace: route.params?.animation ?? 'push', animationTypeForReplace: route.params?.animation ?? 'push',
})} })}
/> />
{commonScreens(MessagesTab as typeof HomeTab)} {commonScreens(MessagesTab as typeof Flat)}
</MessagesTab.Navigator> </MessagesTab.Navigator>
) )
} }
@@ -672,7 +670,7 @@ const FlatNavigator = () => {
getComponent={() => HomeScreen} getComponent={() => HomeScreen}
options={{title: title(msg`Home`)}} options={{title: title(msg`Home`)}}
/> />
{commonScreens(Flat as typeof HomeTab, numUnread)} {commonScreens(Flat, numUnread)}
</Flat.Navigator> </Flat.Navigator>
) )
} }
+1 -1
View File
@@ -92,7 +92,7 @@ export type NotificationsTabNavigatorParams = CommonNavigatorParams & {
} }
export type MyProfileTabNavigatorParams = CommonNavigatorParams & { export type MyProfileTabNavigatorParams = CommonNavigatorParams & {
MyProfile: undefined MyProfile: {name: 'me'; hideBackButton: true}
} }
export type MessagesTabNavigatorParams = CommonNavigatorParams & { export type MessagesTabNavigatorParams = CommonNavigatorParams & {