Created
May 30, 2017 03:34
-
-
Save ridgeO/95d0f697035879fe989fded99997b1c3 to your computer and use it in GitHub Desktop.
Code snippets from ReactNav application as featured in http://platypus.is/posts/4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# App.js | |
... | |
class GreenScreen extends Component { | |
static navigationOptions = { | |
title: 'Green' | |
} | |
render() { | |
return( | |
<View style={styles.green}> | |
<Text style={styles.text}>This is the Green Screen</Text> | |
</View> | |
); | |
} | |
} | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# App.js | |
... | |
import { | |
... | |
TouchableHighlight | |
} from 'react-native'; | |
... | |
class GreenScreen extends Component { | |
static navigationOptions = { | |
title: 'Green' | |
} | |
render() { | |
return( | |
<View style={styles.green}> | |
<Text style={styles.text}>This is the Green Screen</Text> | |
<TouchableHighlight | |
style={styles.button} | |
onPress={() => this.props.navigation.navigate('Red')} | |
> | |
<Text style={styles.text}>Go to Red</Text> | |
</TouchableHighlight> | |
</View> | |
); | |
} | |
} | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Styles.js | |
... | |
green: { | |
flex: 1, | |
alignItems: 'center', | |
justifyContent: 'center', | |
backgroundColor: 'green' | |
}, | |
red: { | |
flex: 1, | |
alignItems: 'center', | |
justifyContent: 'center', | |
backgroundColor: 'red' | |
}, | |
blue: { | |
flex: 1, | |
alignItems: 'center', | |
justifyContent: 'center', | |
backgroundColor: 'blue' | |
}, | |
purple: { | |
flex: 1, | |
alignItems: 'center', | |
justifyContent: 'center', | |
backgroundColor: 'purple' | |
}, | |
text: { | |
color: 'white', | |
fontSize: 20 | |
} | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# index.ios.js and index.android.js | |
import './App.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# App.js | |
'use strict'; | |
import React, { Component } from 'react'; | |
import { | |
AppRegistry, | |
StyleSheet, | |
View, | |
Text | |
} from 'react-native'; | |
import styles from './Styles.js'; | |
class ReactNav extends Component { | |
render() { | |
return ( | |
<View style={styles.container}> | |
<Text>Hello World</Text> | |
</View> | |
); | |
} | |
} | |
AppRegistry.registerComponent('ReactNav', () => ReactNav); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# App.js | |
... | |
class GreenScreen extends Component { | |
render() { | |
return( | |
<View style={styles.green}> | |
<Text style={styles.text}>This is the Green Screen</Text> | |
</View> | |
); | |
} | |
} | |
class RedScreen extends Component { | |
render() { | |
return( | |
<View style={styles.red}> | |
<Text style={styles.text}>This is the Red Screen</Text> | |
</View> | |
); | |
} | |
} | |
class BlueScreen extends Component { | |
render() { | |
return( | |
<View style={styles.blue}> | |
<Text style={styles.text}>This is the Blue Screen</Text> | |
</View> | |
); | |
} | |
} | |
class PurpleScreen extends Component { | |
render() { | |
return( | |
<View style={styles.purple}> | |
<Text style={styles.text}>This is the Purple Screen</Text> | |
</View> | |
); | |
} | |
} | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Styles.js | |
'use strict'; | |
import { StyleSheet } from 'react-native'; | |
const styles = StyleSheet.create({ | |
container: { | |
flex: 1, | |
alignItems: 'center', | |
justifyContent: 'center' | |
} | |
}) | |
export default styles; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment