Skip to content

Instantly share code, notes, and snippets.

@yuizho
Last active August 14, 2016 15:23
Show Gist options
  • Save yuizho/d11d19ebf234aca0079ce29f2ec395aa to your computer and use it in GitHub Desktop.
Save yuizho/d11d19ebf234aca0079ce29f2ec395aa to your computer and use it in GitHub Desktop.
ReactNative TextInputのチュートリアル
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, {Component} from 'react';
import {
AppRegistry,
StyleSheet,
Text,
Image,
TextInput,
View,
} from 'react-native';
class AwesomeProject extends Component {
constructor(props) {
super(props);
this.state = {
text: ''
};
}
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
{
// JSの論理演算子の使い方について
// http://qiita.com/Imamotty/items/bc659569239379dded55
this.state.text.split(' ').map((word) => word && '🍕').join(' ')
}
</Text>
<Text style={styles.welcome}>
{this.state.text}
</Text>
<TextInput style={styles.textInput}
// functionを登録してやってみたが、
// this.setStateが見えないみたいでエラーになった
onChangeText={(text) => this.setState({text})}/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
},
textInput: {
height: 40,
borderColor: 'gray',
borderWidth: 1,
},
});
AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment