【发布时间】:2017-02-09 07:45:51
【问题描述】:
我想知道是否可以在按下 TextInput 时显示日期选择器模式。
我正在使用TouchableWithoutFeedback 和TextInput。如果我使用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>
目标是每当我按下/点击TextInput时,它会弹出日期选择器模式,然后我可以从模式中选择日期。
【问题讨论】:
标签: javascript android ios reactjs react-native