Skip to content

Instantly share code, notes, and snippets.

@chongiscool
Created August 16, 2018 14:06
Show Gist options
  • Save chongiscool/d2a1acc53da71786d33c83ed9f281640 to your computer and use it in GitHub Desktop.
Save chongiscool/d2a1acc53da71786d33c83ed9f281640 to your computer and use it in GitHub Desktop.
Create a stack navigator with some routes and navigate between those routes.
import React from 'react'
import {
StyleSheet,
View,
Text,
Platform,
TouchableOpacity, Button
} from 'react-native'
import { Ionicons, FontAwesome } from '@expo/vector-icons'
import {
createBottomTabNavigator,
createMaterialTopTabNavigator,
createStackNavigator,
createDrawerNavigator,
TabBarBottom, tabBarIcon } from 'react-navigation'
import Detail from './Detail'
export default class App extends React.Component {
render() {
return(
<RootStack />
)
}
}
const Home = ({ navigation }) => (
<View style={styles.container}>
<Text style={styles.text}>Home Screen!</Text>
<TouchableOpacity onPress={() => navigation.navigate('Detail')}>
<Text style={styles.detailText}>Go to Detail</Text>
</TouchableOpacity>
</View>
);
const Detail = ({ navigation }) => {
<View style={styles.container}>
<Text>Details Screen!</Text>
<TouchableOpacity onPress={() => navigation.navigate('Home')}>
<Text style={styles.detailText}>Go to Home</Text>
</TouchableOpacity>
<Text style={{fontSize: 30}}>---------</Text>
<TouchableOpacity onPress={() => navigation.push('Detail', {
itemId: Math.floor(Math.random() * 100),
})}>
<Text style={styles.detailText}>Go to Detail again</Text>
</TouchableOpacity>
<Text style={{fontSize: 30}}>---------</Text>
<TouchableOpacity onPress={() => navigation.goBack()}>
<Text style={styles.detailText}>Go Back</Text>
</TouchableOpacity>
</View>
}
const RootStack = createStackNavigator({
Home: Home,
Detail: Detail
},{
initialRouteName: 'Home',
})
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
marginLeft: 10,
marginRight: 10
},
text: {
color: 'red'
},
detailText: {
color: 'blue'
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment