Skip to content

Instantly share code, notes, and snippets.

@bitttttten
Last active March 21, 2020 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bitttttten/3fb58392fe3d578fbe4c1300f48042b0 to your computer and use it in GitHub Desktop.
Save bitttttten/3fb58392fe3d578fbe4c1300f48042b0 to your computer and use it in GitHub Desktop.
const RecipesScreen = () => {
return (
<>
<StatusBar />
<Stack.Navigator
initialRouteName="Recipes"
>
<Stack.Screen
name="Recipes"
component={Recipes}
/>
<Stack.Screen
name="Filters"
component={Filters}
/>
<Stack.Screen
name="AddRecipeToWeek"
component={AddRecipeToWeekScreen}
/>
<Stack.Screen
name="Recipe"
component={RecipeScreen}
/>
</Stack.Navigator>
</>
)
}
export const Tabs: React.FC = () => {
const theme = useTheme()
const { t } = useTranslation()
return (
<Tab.Navigator
initialRouteName="Home"
backBehavior="initialRoute"
>
<Tab.Screen
name="Home"
component={HomeScreen}
/>
<Tab.Screen
name="Recipes"
component={RecipesScreen}
/>
<Tab.Screen
name="MenuPlanner"
component={MenuPlannerScreen}
/>
<Tab.Screen
name="ShoppingList"
component={ShoppingListScreen}
/>
</Tab.Navigator>
)
}
const AppStack = () => {
return (
<Drawer.Navigator
drawerContent={p => <UserSettings {...p} />}
drawerStyle={{ width: `90%` }}
>
<Drawer.Screen name="Tabs" component={Tabs} />
</Drawer.Navigator>
)
}
const App = () => {
const navigationRef = useRef();
const [hasProcessedDeepLinking, setHasProcessedDeepLinking] = useState(false);
const [initialState, setInitialState] = useState();
const { getInitialState } = useLinking(navigationRef, {
prefixes: [Linking.makeUrl("/"), "https://myapp.app", "myapp://"],
config: {
Recipes: {
initialRouteName: "Recipes",
screens: {
Recipes: "recipes",
Recipe: "recipe/:slug"
}
},
Login: "login/:code"
}
});
useEffect(() => {
const doWork = async () => {
try {
const state = await Promise.race([
getInitialState(),
new Promise(resolve =>
// Timeout in 150ms if `getInitialState` doesn't resolve
// Workaround for https://github.com/facebook/react-native/issues/25675
setTimeout(resolve, 150)
)
]);
if (state !== undefined) {
setInitialState(state as any);
}
} catch (e) {
console.error(e);
}
setHasProcessedDeepLinking(true);
};
doWork();
}, [getInitialState]);
if (!hasProcessedDeepLinking) {
return <AppLoading />;
}
return (
<NavigationContainer ref={navigationRef} initialState={initialState}>
<AppStack />
</NavigationContainer>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment