Skip to content

Instantly share code, notes, and snippets.

@artyorsh
Created May 30, 2020 15:55
Show Gist options
  • Save artyorsh/c691b564ddac4c4d061fd9039da9442d to your computer and use it in GitHub Desktop.
Save artyorsh/c691b564ddac4c4d061fd9039da9442d to your computer and use it in GitHub Desktop.
React Navigation 5 - Basic Switch Navigator
import React from 'react';
import { View } from 'react-native';
import { useNavigationBuilder, TabRouter, NavigationHelpersContext, createNavigatorFactory } from '@react-navigation/native';
interface SwitchNavigatorProps {
children: React.ReactNode;
}
const SwitchNavigator = (props: SwitchNavigatorProps): React.ReactElement => {
const { state, navigation, descriptors } = useNavigationBuilder(TabRouter, props);
return (
<NavigationHelpersContext.Provider value={navigation}>
<View style={{ flex: 1 }}>
{descriptors[state.routes[state.index].key].render()}
</View>
</NavigationHelpersContext.Provider>
);
};
export const createSwitchNavigator = createNavigatorFactory(SwitchNavigator);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment