[英]Weird behaviour of TextInput on android react native
我有一個注冊表單,當用戶將文本輸入聚焦並彈出鍵盤時,我想在其中清除文本輸入。
此行為在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>
);
}
}
在這方面的任何幫助將是巨大的。
問題可能是您設置了TextInput
value
屬性。 如果設置了value
,它將覆蓋您嘗試在其中寫入的所有內容。 您應該改用defaultValue
屬性。
UPDATE清除文本是已知問題,但已標記為已修復。 如果您仍然遇到問題,請嘗試https://github.com/nikolaiwarner/react-native-text-input-reset
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.