React Native 不显示来自 TextInput 的 Datepicker

Web*_*ter 3 javascript android ios reactjs react-native

我想知道是否可以在按下 TextInput 时显示日期选择器模式。

我正在使用TouchableWithoutFeedbackTextInput。如果我使用它效果很好Text,但是当我使用 TextInput 时,日期选择器模式不会显示。

我使用 TextInput 的原因是因为我想使用underlineColorAndroid道具。

这是代码

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>
Run Code Online (Sandbox Code Playgroud)

目标是每当我按下/点击TextInput,就会弹出日期选择器模式了,然后我可以选择从模式的日期。

Ngu*_*àng 5

你只需要showPickeronFocusTextInput 的 props 中调用函数。像那样:

<TextInput onFocus = {this.showPicker.bind(this, 'simple', { date: this.state.simpleDate })}>
Run Code Online (Sandbox Code Playgroud)

如果我的想法不符合您的目标,请原谅我。