Android上TextInput的怪异行为反应了本机

时间:2018-08-18 12:11:32

标签: javascript android react-native textinput

我有一个注册表单,我想在用户将其聚焦并弹出键盘时清除文本输入。

此行为在iOS上工作正常,但是在android上,首先是clearTextOnFocus无法正常工作,其次我无法在地址文本输入中输入任何内容,我想知道这里出了什么问题,因为这在iOS上非常完美

export default class SignupScreen extends Component {
static navigationOptions = {
    title: strings.signup,
    headerTintColor:'black'
};
constructor(props) {
    super(props);
    this.state = { loading:true,loginText:strings.username,pwdText:strings.password,nameText:strings.name,phoneNoText:strings.phone,addressText:strings.address,lineIdText:strings.line,loading:false };



}

render() {
    const { navigate } = this.props.navigation;
    return (


        <ImageBackground
            source={require('./images/marble.jpg')}
            style={styles.backgroundImage}>

            <KeyboardAwareScrollView>

                <View style={styles.container}>
                    <Spinner visible={this.state.loading} textContent={"Loading..."} textStyle={{color: '#FFF'}} />

                    <Image style = {styles.logoFit} resizeMode="contain"  source={require('./images/Logo1.png')}/>

                    <View>
                        <TextInput clearTextOnFocus={true} style={styles.textInput} value={this.state.loginText }
                                   onChangeText={(textInputValue1) => this.setState({loginText:textInputValue1})} keyboardType='email-address' ></TextInput>

                        <TextInput clearTextOnFocus={true} style={styles.textInput} value={this.state.pwdText}
                                   onChangeText={(textInputValue2) => this.setState({pwdText:textInputValue2})}></TextInput>

                        <TextInput clearTextOnFocus={true} style={styles.textInput} value={this.state.phoneNoText}
                                   onChangeText={(textInputValue) => this.setState({phoneNoText:textInputValue})}></TextInput>

                        <TextInput clearTextOnFocus={true} style={styles.textInput} value={this.state.nameText}
                                   onChangeText={(textInputValue) => this.setState({nameText:textInputValue})}></TextInput>

                        <TextInput clearTextOnFocus={true} style={styles.textInput} value={this.state.addressText}
                                   onChangeText={(textInputValue) => this.setState({adressText:textInputValue})}></TextInput>

                        <TextInput clearTextOnFocus={true} style={styles.textInput} value={this.state.lineIdText}
                                   onChangeText={(textInputValue) => this.setState({lineIdText:textInputValue})}></TextInput>


                    </View>
                    <View style={styles.buttonSection}>
                        <TouchableOpacity onPress = {this.onSignup}>
                            <View style = { styles.donebutton}>
                                <Text style = {{color: 'white'}}>{strings.signup}</Text>
                            </View>
                        </TouchableOpacity>
                    </View>
                </View>

            </KeyboardAwareScrollView>
     </ImageBackground>


    );
}
}

任何朝着这个方向的帮助都会很棒。

1 个答案:

答案 0 :(得分:1)

问题可能是您设置了value的{​​{1}}属性。如果设置了TextInput,它将覆盖您尝试在其中编写的所有内容。您应该改用value属性。

更新 清除文本是已知问题,但已标记为已修复。如果您仍然遇到问题,请尝试example