简体   繁体   English

使用 react native 和 expo 创建自定义日期选择器

[英]Create a custom date picker with react native and expo

I would like to create a box to select the date as in the attached photo.我想为 select 创建一个框,日期如附图所示。 What do you recommend to create something similar in react native with expo?你建议用 expo 创建类似的东西?

I tried using MUI's Mobile DatePicker API, but it doesn't work, errors occur.我尝试使用 MUI 的 Mobile DatePicker API,但它不起作用,出现错误。

在此处输入图像描述

https://www.npmjs.com/package/@react-native-community/datetimepicker https://www.npmjs.com/package/@react-native-community/datetimepicker

Works with Expo.适用于 Expo。 Static version set at 3.xx (something version 3). Static 版本设置为 3.xx(版本 3)。 So you won't have the full functionality that is described on their docs, but you'll have enough.因此,您不会拥有他们文档中描述的全部功能,但您将拥有足够的功能。

expo install @react-native-community/datetimepicker

instead of npm to ensure you get the compatible version.而不是 npm 以确保您获得兼容版本。

This library can be a bit difficult to work with.这个库可能有点难以使用。 The main suggestion I have for you is to create a custom component on your own that looks like your design.我对您的主要建议是您自己创建一个看起来像您的设计的自定义组件。 Then wrap it with a TouchableOpacity and onPress set the DateTimePicker to show its modal.然后用 TouchableOpacity 包装它并 onPress 设置 DateTimePicker 以显示其模式。 Grab the value you need from the onChange result, and pass it to your local state.从 onChange 结果中获取您需要的值,并将其传递给您的本地 state。 Dont try anything fancy after that because as I mentioned earlier, the library is difficult to work with and really fights hard against any customization.在那之后不要尝试任何花哨的东西,因为正如我之前提到的,这个库很难使用,并且真的很难与任何定制作斗争。 It works well though and will certainly solve your problem.它虽然运作良好,但肯定会解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM