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'})}
            />
        ),
    }
}


0
0

React Native技术精讲与高质量上线App开发

一个真实的上线项目,一次完整的开发过程,全面掌握React Native技术

1577 学习 · 727 问题

查看课程