Created
May 14, 2017 13:57
-
-
Save drmas/f402de63d5eec62fe527352fa8c819c7 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 } from 'react'; | |
import { | |
AppRegistry, | |
StyleSheet, | |
Text, | |
View, | |
TextInput, | |
ListView | |
} from 'react-native'; | |
const ds = new ListView.DataSource({ | |
rowHasChanged: (r1, r2) => r1 !== r2 | |
}) | |
const data = ['Add item', 'Delete item'] | |
class Project extends Component { | |
state = { | |
dataSource: ds.cloneWithRows(data) | |
} | |
renderRow = (rowData) => { | |
return ( | |
<View style={styles.itemContainer} > | |
<Text style={styles.item} >{rowData}</Text> | |
</View> | |
) | |
} | |
onChangeText = (text) => { | |
this.setState({ | |
value: text | |
}) | |
} | |
onSubmitEditing = () => { | |
data = [this.state.value, ...data]; | |
this.setState({ | |
dataSource: ds.cloneWithRows(data), | |
value: '' | |
}) | |
} | |
render() { | |
return ( | |
<View style={styles.container}> | |
<Text style={styles.welcome}> | |
TODO | |
</Text> | |
<TextInput | |
style={styles.textInput} | |
placeholder='Add item todo' | |
onChangeText={this.onChangeText} | |
onSubmitEditing={this.onSubmitEditing} | |
value={this.state.value} | |
/> | |
<ListView | |
dataSource={this.state.dataSource} | |
renderRow={this.renderRow} | |
/> | |
</View> | |
); | |
} | |
} | |
const styles = StyleSheet.create({ | |
container: { | |
flex: 1, | |
alignItems: 'stretch', | |
backgroundColor: '#fff', | |
}, | |
welcome: { | |
fontSize: 20, | |
textAlign: 'center', | |
marginTop: 22, | |
}, | |
instructions: { | |
textAlign: 'center', | |
color: '#333333', | |
marginBottom: 5, | |
}, | |
textInput: { | |
height: 50, | |
padding: 8, | |
borderWidth: 1, | |
borderColor: '#eaeaea', | |
margin: 8 | |
}, | |
itemContainer: { | |
padding: 8, | |
borderBottomWidth: 1, | |
borderColor: '#eaeaea' | |
}, | |
item: { | |
fontSize: 18 | |
} | |
}); | |
AppRegistry.registerComponent('Project', () => Project); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment