@react-navigation/native#getFocusedRouteNameFromRoute TypeScript Examples
The following examples show how to use
@react-navigation/native#getFocusedRouteNameFromRoute.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StackNavigator.tsx From sellflow with MIT License | 4 votes |
export default function StackNavigator() {
let { authToken } = useAuth();
let { data: userData } = useGetAuthenticatedUser();
let { isRTL } = useTheme();
function getTabSceneName(route: Pick<Route<string>, 'key' | 'name'>) {
const routeName = getFocusedRouteNameFromRoute(route) || 'HomeTab';
return routeName;
}
return (
<Stack.Navigator
screenOptions={headerOptions}
headerMode="screen"
initialRouteName={'Home'}
>
<Stack.Screen
name="Home"
component={TabNavigator}
options={({ navigation, route }) => {
let tabScene = getTabSceneName(route);
if (tabScene === 'HomeTab') {
return {
title:
authToken && userData?.authenticatedUser.firstName
? `${t('Hello')}, ${userData.authenticatedUser.firstName}`
: t('Hello'),
headerLeft: () => <LocalizationPicker />,
headerRight: () => (
<HeaderIconButton
icon="cart"
onPress={() => navigation.navigate('ShoppingCart')}
/>
),
headerStyle: {
shadowColor: COLORS.transparent,
elevation: 0,
},
};
} else if (tabScene === 'WishlistTab') {
return {
headerLeft: () => null,
title: t('Wishlist'),
};
} else {
return authToken
? {
headerLeft: () => null,
title: t('My Profile'),
}
: {
headerLeft: () =>
!authToken && (
<HeaderIconButton
icon={isRTL ? 'chevron-right' : 'chevron-left'}
onPress={() => navigation.navigate('HomeTab')}
/>
),
title: '',
headerStyle: {
shadowColor: COLORS.transparent,
elevation: 0,
},
};
}
}}
/>
<Stack.Screen
name="Auth"
component={AuthScene}
options={() => ({
title: t('Welcome'),
headerStyle: {
shadowColor: COLORS.transparent,
elevation: 0,
},
})}
/>
<Stack.Screen
name="ForgotPassword"
component={ForgotPasswordScene}
options={() => ({
title: t('Forgot Password'),
cardStyle: {
backgroundColor: COLORS.white,
},
})}
/>
<Stack.Screen
name="AddressManagement"
component={AddressManagementScene}
options={() => ({
title: t('Manage Addresses'),
})}
/>
<Stack.Screen name="AddEditAddress" component={AddEditAddressScene} />
<Stack.Screen
name="EditProfile"
component={EditProfileScene}
options={() => ({
title: t('Edit Profile'),
})}
/>
<Stack.Screen
name="OrderHistory"
component={OrderHistoryScene}
options={() => ({
title: t('Order History'),
cardStyle: {
backgroundColor: COLORS.darkWhite,
},
})}
/>
<Stack.Screen
name="OrderDetails"
component={OrderDetailsScene}
options={() => ({
title: t('Order Details'),
})}
/>
<Stack.Screen
name="ProductDetails"
component={ProductDetailsScene}
options={({ navigation }) => ({
title: t('Product Details'),
headerRight: () => (
<HeaderIconButton
icon="cart"
onPress={() => navigation.navigate('ShoppingCart')}
/>
),
})}
/>
<Stack.Screen
name="ShoppingCart"
component={ShoppingCartScene}
options={() => ({
title: t('Shopping Cart'),
})}
/>
<Stack.Screen
name="ProductCollection"
component={ProductCollectionScene}
options={({ route }) => ({
title: route.params.collection.title,
})}
/>
<Stack.Screen
name="SearchResults"
component={SearchResultsScene}
options={() => ({
title: t('Search Results'),
})}
/>
<Stack.Screen
name="Checkout"
component={CheckoutScene}
options={() => ({
title: t('Checkout'),
})}
/>
<Stack.Screen name="WebView" component={WebViewScene} />
<Stack.Screen
name="OrderPlacedConfirmation"
component={OrderPlacedConfirmationScene}
options={() => ({
title: t('Order Placed'),
headerLeft: () => null,
})}
/>
</Stack.Navigator>
);
}