@react-native-community/datetimepicker 在 iOS 设备上的时间表现异常

huangapple go评论68阅读模式
英文:

Stange behavior of time in @react-native-community/datetimepicker IOS device

问题

我在使用@react-native-community/datetimepicker的IOS设备上遇到了一个非常奇怪的问题,当使用"TIME"模式时。每当我更改时间,它会自动恢复到实际时间,更改后时间重置。请问我该如何解决这个问题?

注意:这个问题只在IOS设备上出现。

附上快速检查的snack链接:

https://snack.expo.dev/@dedevelopers/date-time-picker-issue

英文:

I am having a very strange issue in the IOS device for @react-native-community/datetimepicker while using "TIME" mode.

Whenever I change the time it automatically reverted back to the actual time, time reset on changing. Can you please guide how I can fix this issue?

NOTE: ITS ONLY HAVING ISSUE WITH IOS DEVICES.

>Attach is the link to the snack so that you can check quickly.

https://snack.expo.dev/@dedevelopers/date-time-picker-issue

答案1

得分: 1

要保留date,您需要在onChange回调函数中更新DatePicker中的当前日期,如下所示:

const onChange = (event, selectedDate) => {
  const currentDate = selectedDate;
  setDate(new Date(selectedDate));
  // 其他操作...
}

您可以检查这个修复的示例,基于您的需求:这里

英文:

To keep the date you need to update the current date in the DatePicker in the onChange callback function like this:

  const onChange = (event, selectedDate) => {
    const currentDate = selectedDate;
    setDate(new Date(selectedDate));
   ....
}

You can check this fixed snack based on yours @react-native-community/datetimepicker 在 iOS 设备上的时间表现异常 from here

huangapple
  • 本文由 发表于 2023年3月1日 13:04:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/75599764.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定