Last active
March 2, 2022 16:00
-
-
Save Stringsaeed/eb1ba3450417d5ef2ea4926b48cc1fb1 to your computer and use it in GitHub Desktop.
Revisions
-
Stringsaeed revised this gist
Mar 2, 2022 . 1 changed file with 52 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,54 @@ ### useGetFirstTime #### Description: React Hook used for when user first time opens the app so if you want to show tutorial modal or load only onboarding stack in react-navigation & react-native #### Usage: ```tsx import React, { useEffect } from "react"; import { NavigationContainer } from "@react-navigation/native"; import { createStackNavigator } from "@react-navigation/stack"; const OnBoardingStack = createStackNavigator(); const AppStack = createStackNavigation(); const OnboardingNavigator = ({ setFirstTime }) => { useEffect(() => { setFirstTime(); }, [setFirstTime]); return ( <OnBoardingStack.Navigator> <OnBoardingStack.Screen name="onBoarding1" component={OnBoardingOneScreen} /> <OnBoardingStack.Screen name="onBoarding2" component={OnBoardingTwoScreen} /> </OnBoardingStack.Navigator> ); }; const AppNavigator = () => { return ( <AppStack.Navigator> <AppStack.Screen name="App1" component={AppOneScreen} /> <AppStack.Screen name="App2" component={AppTwoScreen} /> </AppStack.Navigator> ); }; const App = () => { const [firstTime, setFirstTime] = useGetFirstTime(); return ( <NavigationContainer> {firstTime ? <OnboardingNavigator /> : <AppNavigator />} </NavigationContainer> ); }; export default App; ``` -
Stringsaeed revised this gist
Mar 2, 2022 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ ### useGetFirstTime #### Description React Hook used for when user first time opens the app so if you want to show tutorial modal or load only onboarding stack in react-navigation & react-native -
Stringsaeed revised this gist
Mar 2, 2022 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1,3 @@ ### useGetFirstTime #react-native #react -
Stringsaeed renamed this gist
Mar 2, 2022 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Stringsaeed renamed this gist
Mar 2, 2022 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Stringsaeed revised this gist
Mar 2, 2022 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ -
Stringsaeed revised this gist
Mar 2, 2022 . No changes.There are no files selected for viewing
-
Stringsaeed revised this gist
Mar 2, 2022 . No changes.There are no files selected for viewing
-
Stringsaeed revised this gist
Mar 2, 2022 . No changes.There are no files selected for viewing
-
Stringsaeed revised this gist
Mar 2, 2022 . No changes.There are no files selected for viewing
-
Stringsaeed revised this gist
Mar 2, 2022 . 1 changed file with 9 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,28 +1,28 @@ import { useCallback, useLayoutEffect, useState } from "react"; import { useAsyncStorage } from "@react-native-async-storage/async-storage"; const useGetFirstTime = () => { const [firstTime, setFirstTime] = useState(false); const { getItem, setItem } = useAsyncStorage("FirstTime"); const readItemFromStorage = useCallback(async () => { const item = await getItem(); setFirstTime(!item); }, [getItem]); const setModalVisited = useCallback(async () => { setFirstTime(true); await setItem(true); }, [setItem]); // using useLayoutEffect to avoid re-rendering // so it get value before view mounts // of course, the modal won't mount before // we check for layout height or the position. useLayoutEffect(() => { readItemFromStorage(); }, [readItemFromStorage]); return [firstTime, setModalVisited]; }; export default useGetFirstTime; -
Stringsaeed created this gist
Mar 2, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ import { useCallback, useLayoutEffect, useState } from "react"; import { useAsyncStorage } from "@react-native-async-storage/async-storage"; const useGetFirstTimeTipping = () => { const [firstTimeTipping, setFirstTimeTipping] = useState(false); const { getItem, setItem } = useAsyncStorage("TippingModalVisited"); const readItemFromStorage = useCallback(async () => { const item = await getItem(); setFirstTimeTipping(!item); }, [getItem]); const setTippingModalVisited = useCallback(async () => { setFirstTimeTipping(true); await setItem(true); }, [setItem]); // using useLayoutEffect to avoid re-rendering // so it get value before view mounts // of course the modal won't mount before // we check for layout height or the position. useLayoutEffect(() => { readItemFromStorage(); }, [readItemFromStorage]); return [firstTimeTipping, setTippingModalVisited]; }; export default useGetFirstTimeTipping;