Skip to content

Instantly share code, notes, and snippets.

@rahgurung
Created August 16, 2022 16:10
Show Gist options
  • Save rahgurung/92508a14d4a97010f53f7fc5d2b64935 to your computer and use it in GitHub Desktop.
Save rahgurung/92508a14d4a97010f53f7fc5d2b64935 to your computer and use it in GitHub Desktop.
import * as React from 'react';
import {Text, Button} from 'react-native';
import {NavigationContainer} from '@react-navigation/native';
import {createNativeStackNavigator} from '@react-navigation/native-stack';
// Our Screens
function Screen1({navigation}) {
return (
<>
<Text>Screen 1</Text>
<Button
title="Go to Screen 2"
onPress={() => navigation.navigate('Screen2')}
/>
</>
);
}
function Screen2({navigation}) {
return (
<>
<Text>Screen 2</Text>
<Button
title="Go to Screen 1"
onPress={() => navigation.navigate('Screen1')}
/>
</>
);
}
// Initialize the Stack navigator
const Stack = createNativeStackNavigator();
function StackNavigation() {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="Screen1" component={Screen1} />
<Stack.Screen name="Screen2" component={Screen2} />
</Stack.Navigator>
</NavigationContainer>
);
}
export default StackNavigation;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment