[英]React Native TextInput doesn't increase height at correct content length
[英]React Native doesn't show Datepicker from TextInput
我想知道是否可以在按下TextInput時顯示datepicker模式。
我正在使用TouchableWithoutFeedback
和TextInput
。 如果我使用Text
,它會很好地工作,但是當我使用TextInput時,不會顯示datepicker模式。
我使用TextInput的原因是因為我想使用underlineColorAndroid
prop。
這是代碼
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
,它將彈出日期選擇器模式,然后我可以從模式中選擇日期。
您只需要在TextInput的onFocus
道具中調用showPicker
函數即可。 像那樣:
<TextInput onFocus = {this.showPicker.bind(this, 'simple', { date: this.state.simpleDate })}>
如果我的想法與您的目標不符,請原諒我。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.