onChangeText : 사용자의 input 값 변경 시 호출
onSubmitEditing : 텍스트 제출 시 호출될 함수를 받는다
onFocus
cf. Android text selection에서 주의할 점
Note that on Android performing text selection in an input can change the app's activity windowSoftInputMode param to adjustResize.
This may cause issues with components that have position: 'absolute' while the keyboard is active. To avoid this behavior either specify windowSoftInputMode in AndroidManifest.xml ( https://developer.android.com/guide/topics/manifest/activity-element.html ) or control this param programmatically with native code.
import React, { useState } from 'react';
import { Text, TextInput, View } from 'react-native';
const PizzaTranslator = () => {
const [text, setText] = useState('');
//text가 계속 바뀌니까 state에 저장
return (
<View style={{padding: 10}}>
<TextInput
style={{height: 40}}
placeholder="Type here to translate!"
onChangeText={newText => setText(newText)}
defaultValue={text}
/>
<Text style={{padding: 10, fontSize: 42}}>
{text.split(' ').map((word) => word && '🍕').join(' ')}
//띄어쓰기는 피자로 번역하지 않기 위해 && 사용
</Text>
</View>
);
}
export default PizzaTranslator;