【问题标题】:React Native DatePicker with TextInput使用 TextInput 反应原生 DatePicker
【发布时间】:2020-12-22 23:30:49
【问题描述】:

我目前正在制作一个移动应用程序,其中一部分是收集用户数据。在单击文本字段后,我一直坚持让 DatePicker 显示在屏幕上。我曾尝试使用 onFocus 道具,但它似乎无法正常工作,并且不会在控制台中引发任何错误。这是我尝试使用的代码:

 const showDatePicker = () => {
       return(
           <DateTimePicker
               value={date}
               mode='date'
               is24Hour={true}
               display="spinner"
               onChange={onChange}
           />
       )
   }
    <View style={styles.inputContainer}>
                                <FontAwesome name="user-circle-o" color={'#808080'} size={20}/>
                                <TextInput onFocus={() => showDatePicker()} style={styles.input} placeholder="Date Of Birth"
                                />
                            </View>

为了给这个问题提供一些额外的背景信息,我使用了一种模式,它作为一种收集数据的形式。任何帮助或提示表示赞赏。

【问题讨论】:

    标签: react-native datepicker textinput


    【解决方案1】:

    您可以用&lt;Pressable /&gt; 包装TextInput

    <Pressable onPress={() => showDatePicker()}>
        <TextInput />
    </Pressable>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-06
      • 2020-08-10
      • 2015-12-31
      • 1970-01-01
      • 1970-01-01
      • 2021-08-20
      • 2021-04-18
      • 1970-01-01
      相关资源
      最近更新 更多