TextInput 会取消编辑问题
来源:2-5 StackNavigator精讲-4

小小猿先生
2018-05-06
<TextInput
style={styles.input}
onChangeText={text=> {
setParams({title: text});
}}
/>
在设置 title 的时候, TextInput 会自动的 取消编辑状态,这个是为什么?
写回答
1回答
-
CrazyCodeBoy
2018-05-07
可参考代码:
const {navigation} = this.props; const {state, setParams} = navigation; const {params} = state; const showText = params.mode === 'edit' ? '正在编辑' : '编辑完成'; return <View style={{flex: 1, backgroundColor: "gray",}}> <Text style={styles.text}>欢迎来到Page3</Text> <Text style={styles.showText}>{showText}</Text> <TextInput style={styles.input} onChangeText={text=>{ setParams({title:text}) }} /> </View>
navigationOptions: (props) => {//在这里定义每个页面的导航属性,动态配置 const {navigation} = props; const {state, setParams} = navigation; const {params} = state; return { title: params.title ? params.title : 'This is Page3', headerRight: ( <Button title={params.mode === 'edit' ? '保存' : '编辑'} onPress={() => setParams({mode: params.mode === 'edit' ? '' : 'edit'})} /> ), } }
00
相似问题