You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native实现点击TextInput唤起Date Picker的方法

解决TextInput点击唤起日期选择器的问题

你的问题核心是React Native的TextInput组件不支持onclick属性,需要替换为框架提供的正确属性,同时为了避免点击时弹出不必要的软键盘,还需补充配置项,具体修改方案如下:

基础实现(禁止输入仅唤起选择器)

<TextInput
  style={styles.forminput}
  label=" Date of Birth"
  value=""
  onPress={displayDatepicker} // 替换错误的onclick为onPress
  editable={false} // 禁止编辑,避免弹出系统键盘
  showSoftInputOnFocus={false} // 确保聚焦时不触发软键盘
/>

进阶实现(允许编辑但点击唤起选择器)

如果需要保留TextInput的编辑能力,同时点击时唤起日期选择器,可以改用onFocus事件:

<TextInput
  style={styles.forminput}
  label=" Date of Birth"
  value=""
  onFocus={displayDatepicker} // 聚焦时唤起日期选择器
  showSoftInputOnFocus={false} // 阻止软键盘弹出
/>

内容的提问来源于stack exchange,提问作者vivek kn

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 03:50:21