Skip to content

Instantly share code, notes, and snippets.

@browniefed
Created February 9, 2018 04:18
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 browniefed/9fef57ca8fd1b14af42cf26c978cd5f3 to your computer and use it in GitHub Desktop.
Save browniefed/9fef57ca8fd1b14af42cf26c978cd5f3 to your computer and use it in GitHub Desktop.
import React from "react";
import { StyleSheet, Text, View, TouchableOpacity } from "react-native";
import { StackNavigator } from "react-navigation";
const Home = ({ navigation }) => {
return (
<View style={styles.container}>
<TouchableOpacity onPress={() => navigation.push("OtherStack")}>
// push will only go to "OtherStack" but because we are now inside of "OtherStack" and it's new nested StackNavigator. There is no "OtherStack" just "Meow" and "Blue".
// If we do "navigate" instead it would keep navigating forever
<Text>Go To Profile</Text>
</TouchableOpacity>
</View>
);
};
const Profile = ({ navigation }) => {
return (
<View style={styles.container}>
<TouchableOpacity onPress={() => navigation.goBack()}>
<Text>Go Back</Text>
</TouchableOpacity>
</View>
);
};
const Other = StackNavigator({
Blue: {
screen: Home,
},
Meow: {
screen: Profile,
},
});
const RootNavigator = StackNavigator({
Home: {
screen: Home,
},
Profile: {
screen: Profile,
},
OtherStack: {
screen: Other
},
});
export default class App extends React.Component {
render() {
return <RootNavigator />;
}
}
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