Skip to content

Instantly share code, notes, and snippets.

@pfulop
Created August 30, 2016 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pfulop/45c2bd4942f5a2a74be04b94c640f11d to your computer and use it in GitHub Desktop.
Save pfulop/45c2bd4942f5a2a74be04b94c640f11d to your computer and use it in GitHub Desktop.
//@flow
import React, { Component,PropTypes } from 'react';
import {
Platform,
StyleSheet,
TextInput,
View,
Text,
TouchableNativeFeedback,
TouchableHighlight
} from 'react-native';
class AddItem extends Component {
constructor(props) {
super(props);
this.state = { text: 'I will be added' };
}
render() {
var TouchableElement = TouchableHighlight;
if (Platform.OS === 'android') {
TouchableElement = TouchableNativeFeedback;
}
return (
<View style={styles.container}>
<TextInput
style={styles.textInput}
onChangeText={(text) => this.setState({text})}
value={this.state.text}
/>
<TouchableElement
style={styles.button}
onPress={() => this.props.pushItem(this.state.text)}>
<View>
<Text>ADD!</Text>
</View>
</TouchableElement>
</View>
);
}
}
var styles = StyleSheet.create({
container: {
padding: 10,
flexDirection:'row',
flexWrap: 'wrap',
alignItems: 'center',
flex: 1
},
textInput: {
fontSize: 19,
fontWeight: 'bold',
borderWidth: 0,
flex: 1,
},
button: {
textAlign:'center',
},
});
AddItem.propTypes={
pushItem: PropTypes.func.isRequired
}
export default AddItem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment