Skip to content

Instantly share code, notes, and snippets.

@marshyon
Created January 13, 2023 13:11
Show Gist options
  • Save marshyon/17891d58647c035b661c54ddde8f4510 to your computer and use it in GitHub Desktop.
Save marshyon/17891d58647c035b661c54ddde8f4510 to your computer and use it in GitHub Desktop.
react native tab and stack ( combined ) navigation
npm install react-navigation-stack @react-native-community/masked-view react-native-gesture-handler @react-navigation/stack

at top of app.js is

import 'react-native-gesture-handler';

see https://reactnavigation.org/docs/stack-navigator/

Note: If you are building for Android or iOS, do not skip this step, or your app may crash in production even if it works fine in development. This is not applicable to other platforms.

import 'react-native-gesture-handler';
import { StyleSheet, Text, View } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
const Tab = createBottomTabNavigator();
const Stack = createStackNavigator()
function StackNavHome() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>This is the Stack Navigation Home</Text>
</View>
);
}
function SettingsScreen() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Settings!</Text>
</View>
);
}
function MyStack() {
return (
<Stack.Navigator>
<Stack.Screen name="Stack Nav Home" component={StackNavHome} />
</Stack.Navigator>
);
}
export function TabNavigator() {
return (
<Tab.Navigator>
<Tab.Screen name='Home' component={MyStack}/>
<Tab.Screen name="Settings" component={SettingsScreen} />
</Tab.Navigator>
)
}
export default function App() {
return (
<NavigationContainer>
<TabNavigator />
</NavigationContainer>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment