Created
October 26, 2015 12:54
-
-
Save wrburgess/f3e436ee278917f32380 to your computer and use it in GitHub Desktop.
index.ios.js
This file contains hidden or 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
var React = require('react-native'); | |
var { | |
Text, | |
View, | |
TouchableHighlight, | |
AppRegistry, | |
StyleSheet | |
} = React; | |
var StopWatch = React.createClass({ | |
getInitialState: function(){ | |
return { | |
timeElapsed: null | |
} | |
}, | |
render: function() { | |
return <View style={styles.container}> | |
<View style={[styles.header, this.border('yellow')]}> | |
<View style={[styles.timerWrapper, this.border('red')]}> | |
<Text> | |
00:00.00 | |
</Text> | |
</View> | |
<View style={[styles.buttonWrapper, this.border('green')]}> | |
{this.startStopButton()} | |
{this.lapButton()} | |
</View> | |
</View> | |
<View style={[styles.footer, this.border('blue')]}> | |
<Text> | |
I am a list of Laps | |
</Text> | |
</View> | |
</View> | |
}, | |
startStopButton: function() { | |
return <TouchableHighlight | |
underlayColor="gray" | |
onPress={this.handleStartPress} | |
> | |
<Text> | |
Start | |
</Text> | |
</TouchableHighlight> | |
}, | |
lapButton: function() { | |
return <View> | |
<Text> | |
Lap | |
</Text> | |
</View> | |
}, | |
handleStartPress: function() { | |
var startTime = new Date(); | |
this.setState({ | |
timeElapsed: new Date() - startTime | |
}); | |
}, | |
border: function(color){ | |
return { | |
borderColor: color, | |
borderWidth: 4 | |
} | |
} | |
}); | |
var styles = StyleSheet.create({ | |
container: { | |
flex: 1, // Fill the entire the screen | |
alignItems: 'stretch' | |
}, | |
header: { // Yellow | |
flex: 1 | |
}, | |
footer: { // Blue | |
flex: 1 | |
}, | |
timerWrapper: { // Red | |
flex: 5, // takes up 5/8ths of the available space | |
justifyContent: 'center', | |
alignItems: 'center' | |
}, | |
buttonWrapper: { // Green | |
flex: 3, // takes up 3/8ths of the available space | |
flexDirection: 'row', | |
justifyContent: 'space-around', | |
alignItems: 'center' | |
} | |
}); | |
AppRegistry.registerComponent('stopwatch', () => StopWatch); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment