Created
July 4, 2017 13:54
-
-
Save Louiefigz/b1941b9951a57c6b5f5ca4c5b9a4f330 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
import React from 'react'; | |
import { ScrollView, Text, StyleSheet, View, TextInput, ListView } from 'react-native'; | |
export default class App extends React.Component { | |
constructor(){ | |
super(); | |
const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2}); | |
this.state={ | |
input:'', | |
restaurants:[], | |
dataSource: ds.cloneWithRows([ | |
'John', 'Joel', 'James', 'Jimmy', 'Jackson', 'Jillian', 'Julie', 'Devin' | |
]) | |
} | |
// in your constructor method | |
this.onSubmitHandler = this.onSubmitHandler.bind(this); | |
} | |
componentWillMount(){ | |
const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2}); | |
this.setState({ | |
propsDataSource: ds.cloneWithRows(this.props.text) | |
}) | |
} | |
onSubmitHandler(e){ | |
// Make a state change here | |
} | |
render() { | |
return ( | |
<View> | |
<TextInput | |
style={styles.input} | |
placeholder="Feed Me" | |
onChangeText={(text) => this.setState({text})} | |
onSubmitEditing={this.onSubmitHandler} | |
/> | |
<View style={styles.background}> | |
<ListView | |
dataSource={this.state.dataSource} | |
renderRow={(rowData) => <Text style={styles.font}>{rowData}</Text>} | |
/> | |
<ListView | |
dataSource={this.state.propsDataSource} | |
renderRow={(rowData) => <Text style={styles.font}>{rowData}</Text>} | |
/> | |
</View> | |
</View> | |
); | |
} | |
} | |
const styles = StyleSheet.create({ | |
background:{ | |
alignItems: 'center' | |
}, | |
font:{ | |
fontSize: 30, | |
}, | |
input:{ | |
height: 40, marginTop:30, borderColor: 'gray', borderWidth: 1, textAlign: 'center' | |
} | |
}) | |
App.defaultProps = { | |
text: ['Burger King', 'McDonalds', 'Red Lobster', | |
'Dennys', 'Wendys', 'White Castle', 'popeyes'] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment