2017-04-13 8 views
0

状態に応じてスタイルが変更されるTextInputがあります。React Native:TextInputスタイルが変更されたときにテキストが失われる

<TextInput 
      autoCapitalize="characters" 
      defaultValue={this.props.name} 
      onChangeText={(text) => { this.handleChangeText(text); }} 
      onEndEditing={this.handleTextSubmit} 
      placeholder={this.props.dictionary.Identification__placeholder} 
      placeholderTextColor={color.WHITE} 
      ref={(component) => { this.textInput = component; }} 
      style={[ 
       defaultStyles.input, 
       styles.input, 
       this.state.keyboardIsVisible && styles.inputSelected, 
      ]} 
      underlineColorAndroid="rgba(0,0,0,0)" 
      /> 

スタイルが変更されると、TextInputの現在の値が消去されるという問題があります。この動作を修正する方法はありますか?

答えて

1

handleTextChangeとは何ですか? value={this.state.inputText}のようなvalueプロパティを持ち、その値をhandleTextChangeで更新する必要があります。

+0

handleTextChangeは、状態の値を更新します。 'value = {this.state.inputText}'は私の問題を解決しました。ありがとう、私はこれをやるのをやめなかった。 –

関連する問題