2017-02-09 5 views
1

TextInputが押されているときにdatepickerモーダルを表示できるかどうかは疑問です。React NativeがTextInputのDatepickerを表示しない

私はTouchableWithoutFeedbackTextInputを使用しています。 Textを使用するとうまく動作しますが、TextInputを使用すると、datepickerモーダルが表示されません。

TextInputを使用している理由は、underlineColorAndroid propを使用したいからです。ここで

目的は私が/ TextInputをクリックして押したときに、それはDatePickerのモーダルアップをポップし、その後、私は、モーダルから日付を選択することができているコード

showPicker = async (stateKey, options) => { 
    try { 
     const newState = {}; 
     const { action, year, month, day } = await DatePickerAndroid.open(options); 
     if (action === DatePickerAndroid.dismissedAction) { 
     newState[stateKey + 'Text'] = 'dismissed'; 
     } else { 
     const date = new Date(year, month, day); 
     newState[stateKey + 'Text'] = date.toLocaleDateString(); 
     newState[stateKey + 'Date'] = date; 
     } 
     this.setState(newState); 
    } catch ({ code, message }) { 
     console.warn(`Error in example '${stateKey}': `, message); 
    } 
    }; 

<TouchableWithoutFeedback 
      onPress={this.showPicker.bind(this, 'simple', { date: this.state.simpleDate })} 
      > 
      <TextInput 
       placeholder="Where the event held*" 
       onFocus={() => this.onFocus()} 
       onFocus={() => this.onFocus()} 
       style={{ 
       height: 60, backgroundColor: this.state.backgroundColor, color: this.state.color 
       }} 
       value={this.state.simpleText} 
      /> 
      </TouchableWithoutFeedback> 

です。

答えて

2

TextInputのonFocus小道にshowPickerの機能があります。このように:

私の考えがあなたの目的に合わない場合は、私を許してください。

+0

こんにちは、ありがとう、それは動作しますが、テキスト入力はまだ編集可能ですが、私は編集可能にfalseを設定しようとしましたが、showPicker関数はトリガーされませんでした。 – Webster

+1

こんにちは、 'dismissKeyboard'から 'DismissKeyboard 'をインポートしようとすると、' on '' props'で 'DismissKeyboard()'関数を呼び出すことができます。 –

+0

大丈夫よ、あなたは私の一日を救った。ありがとう!! – Webster

関連する問題