Navigation
Navigation is used in your native app to naviage users between different screens. Most Apps will have multiple screens and this template handles navigation by using React Navigation.
Read the detailed react navigation documentation before implementing navigations between your screens.
The template comes with an example navigation implementation which you can find in src/Navigations/index.tsx
1
const MainNavigator = () => {
2
const isDark = useColorScheme() === "dark";
3
return (
4
<NavigationContainer>
5
<Stack.Navigator initialRouteName="Home">
6
<Stack.Screen
7
name="Home"
8
component={HomeScreen}
9
options={{ headerShown: false }}
10
/>
11
<Stack.Screen
12
name="Details"
13
component={DetailsScreen}
14
options={{
15
headerStyle: {
16
backgroundColor: isDark ? Colors.darker : Colors.white,
17
},
18
headerTitleStyle: {
19
color: isDark ? Colors.white : Colors.black,
20
},
21
}}
22
/>
23
</Stack.Navigator>
24
</NavigationContainer>
25
);
26
};
Copied!
Referred above is the main navigations for the template. You can customize the navigations based on your needs. If your app contains a logged in state you might also need to implement two different navigations based on the user state and conditionally render the navigation at src/App.tsx like this :
1
const App = () => {
2
const isDarkMode = useColorScheme() === "dark";
3
4
const backgroundStyle = {
5
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
6
flex: 1,
7
};
8
9
const store = configureAppStore();
10
11
const [isLogedIn, setIsLogedIn] = useState(false);
12
13
const checkLoggedInstate = async () => {
14
const state = await AsyncStorage.getItem("USER_TOKEN");
15
setIsLogedIn(Boolean(state));
16
SplashScreen.hide();
17
};
18
19
useEffect(() => {
20
checkLoggedInstate();
21
}, []);
22
23
return (
24
<Provider store={store}>
25
<SafeAreaView style={backgroundStyle}>
26
<StatusBar barStyle={isDarkMode ? "light-content" : "dark-content"} />
27
{isLogedIn ? <MainNavigator /> : <LogedOutNavigator />}
28
</SafeAreaView>
29
</Provider>
30
);
31
};
Copied!
Copy link