Created
September 24, 2016 00:21
-
-
Save anhducbkhn/0facffea144fb7f8623a3aa21a998427 to your computer and use it in GitHub Desktop.
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
/** | |
* Sample React Native App | |
* https://github.com/facebook/react-native | |
* @flow | |
*/ | |
import React, { Component, PropTypes } from 'react'; | |
import { | |
AppRegistry, | |
StyleSheet, | |
Text, | |
View, | |
Image, | |
TextInput, | |
NavigatorIOS, | |
TouchableHighlight, | |
Navigator | |
} from 'react-native'; | |
import MyScene from './MyScene'; | |
class AwesomeProject extends Component { | |
render() { | |
return ( | |
<Navigator | |
initialRoute={{ title: 'My Initial Scene', index: 0 }} | |
renderScene={(route, navigator) => | |
<MyScene | |
title={route.title} | |
// Function to call when a new scene should be displayed | |
onForward={ () => { | |
const nextIndex = route.index + 1; | |
navigator.push({ | |
title: 'Scene ' + nextIndex, | |
index: nextIndex, | |
}); | |
}} | |
// Function to call to go back to the previous scene | |
onBack={() => { | |
if (route.index > 0) { | |
navigator.pop(); | |
} | |
}} | |
/> | |
} | |
/> | |
) | |
} | |
} | |
AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject); |
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
import React, { Component, PropTypes } from 'react'; | |
import { View, Text, TouchableHighlight } from 'react-native'; | |
export default class MyScene extends Component | |
{ | |
static propTypes = { | |
title: PropTypes.string.isRequired, | |
onForward: PropTypes.func.isRequired, | |
onBack: PropTypes.func.isRequired, | |
} | |
render() { | |
return ( | |
<View> | |
<Text>Current Scene: { this.props.title }</Text> | |
<TouchableHighlight onPress={this.props.onForward}> | |
<Text>Tap me to load the next scene</Text> | |
</TouchableHighlight> | |
<TouchableHighlight onPress={this.props.onBack}> | |
<Text>Tap me to go back</Text> | |
</TouchableHighlight> | |
</View> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment