Skip to content

Instantly share code, notes, and snippets.

@emeraldsanto
Last active September 4, 2021 03:55
Show Gist options
  • Select an option

  • Save emeraldsanto/f42af0c32fd76a95f7ac2321a4b1d478 to your computer and use it in GitHub Desktop.

Select an option

Save emeraldsanto/f42af0c32fd76a95f7ac2321a4b1d478 to your computer and use it in GitHub Desktop.
Achieving type safe deep linking in React Native with react-navigation #10
// SomeStack.tsx
export const SomeStackConfiguration = makeNavigator({
name: 'SomeStack',
type: 'stack',
screens: {
[Screen.One]: { screen: ScreenOne },
[Screen.Two]: { screen: ScreenTwo },
[Screen.Three]: { screen: ScreenThree, options: { /* ... */ } },
// ...
},
linking: {
path: 'some-stack',
initialRouteName: Screen.One,
screens: {
[Screen.One]: 'screen-one',
[Screen.Two]: 'screen-two',
[Screen.Three]: 'screen-three/:someParameter',
// ...
},
},
});
// SomeTab.tsx
const Tab = createBottomTabNavigator();
export const SomeTabConfiguration = makeNavigator({
name: 'SomeTab',
type: 'tab',
screens: {
[Screen.One]: { screen: ScreenOne },
[Screen.Two]: { screen: ScreenTwo },
[Screen.Three]: { screen: ScreenThree, options: { /* ... */ } },
// ...
},
linking: {
path: 'some-tab',
initialRouteName: Screen.One,
screens: {
[Screen.One]: 'screen-one',
[Screen.Two]: 'screen-two',
[Screen.Three]: 'screen-three/:someParameter',
// ...
},
},
render(config) {
const { theme } = useSomeThemeProvider();
<Tab.Navigator screenOptions={config.options}>
{/* Render your screens as you wish */}
</Tab.Navigator>
},
});
// RootStack.tsx
const RootStackConfiguration = makeNavigator({
name: 'RootStack',
type: 'stack',
screens: {
[SomeStackConfiguration.name]: { screen: SomeStackConfiguration.render },
[SomeTabConfiguration.name]: { screen: SomeTabConfiguration.render }
},
linking: {
screens: {
[SomeStackConfiguration.name]: { screen: SomeStackConfiguration.linking },
[SomeTabConfiguration.name]: { screen: SomeTabConfiguration.linking }
}
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment