React Native Windows: value except only Date as object, onchange not triggered if unselect date

未关闭
#807 1 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
javascript, react-native, typescript
领域
frontend, mobile

调研方向

Start in the Windows picker implementation, datetimepicker.windows.js, and trace how sharedPropsValidation handles value and how onChange is called when the selected date is cleared. The report names utils.js as the validation location; check its tests and the Windows picker tests first. Done means null or undefined can be used as the value and clearing a date fires onChange; the issue has gone 873 days without a comment.

由索引模型根据 Issue 内容生成。

描述

Bug report

Summary

datetimepicker.windows.js
  1. I want to set undefined or null as date value but it is prevented by validation. If i comment that line eveything is working fine.
  2. If unselect the date in the datepicker by clicking on the current selected date, the onChange Event is never fired. So i never know how the state of the picker is.

Reproducible sample code

<DateTimePicker
      style={styles.datePicker}
      value={null} // NOT POSSIBLE to set NULL
      display="calendar"
      firstDayOfWeek={1}
      onChange={(event: DateTimePickerEvent, date?: Date) => {
          // NOT FIRED if unselect the date
      }}
      onError={(arg: Error) => console.log('GKU Date Error', arg)}/>

Steps to reproduce

--

Describe what you expected to happen:

  1. Null as initial value should be allows
  2. Validation for value in utils.js should be removed because it is already checked. And if i remove the init validation (sharedPropsValidation) everything works fine:

export default function RNDateTimePickerQWE(
  props: WindowsNativeProps,
): React.Node {
  sharedPropsValidation({value: props?.value}); // **REMOVING THIS LINE FIXES THE ISSUE** 

  const localProps = {
    dayOfWeekFormat: props.dayOfWeekFormat,
    dateFormat: props.dateFormat,
    firstDayOfWeek: props.firstDayOfWeek,
    maxDate: props.maximumDate ? props.maximumDate.getTime() : undefined, // time in milliseconds
    minDate: props.minimumDate ? props.minimumDate.getTime() : undefined, // time in milliseconds
    onChange: props.onChange,
    placeholderText: props.placeholderText,
    selectedDate: props.value ? props.value.getTime() : undefined, // time in milliseconds
    style: [styles.rnDatePicker, props.style],
  };

...

Environment info

npx react-native info output:

System:
  OS: Windows 10 10.0.22621
  CPU: (16) x64 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
  Memory: 13.63 GB / 31.73 GB
Binaries:
  Node:
    version: 16.19.1
    path: C:\Program Files\nodejs\node.EXE
  Yarn:
    version: 3.6.0
    path: C:\Program Files (x86)\Yarn\bin\yarn.CMD
  npm:
    version: 8.19.3
    path: C:\Program Files\nodejs\npm.CMD
  Watchman: Not Found
SDKs:
  Android SDK: Not Found
  Windows SDK:
    AllowDevelopmentWithoutDevLicense: Enabled
    AllowAllTrustedApps: Enabled
    Versions:
      - 10.0.18362.0
      - 10.0.19041.0
      - 10.0.22000.0
      - 10.0.22621.0
IDEs:
  Android Studio: AI-222.4459.24.2221.10121639
  Visual Studio:
    - 17.5.33502.453 (Visual Studio Community 2022)
    - 16.11.33423.256 (Visual Studio Community 2019)
Languages:
  Java: Not Found
  Ruby: Not Found
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.72.4
    wanted: 0.72.4
  react-native-windows:
    installed: 0.72.7
    wanted: 0.72.7
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

datetimepicker version: 4.5.0

React Native Windows

主要语言
JavaScript
星标
2.9k
派生
459
平均合并
4 天 16 小时
30 天内合并 PR
5

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

react-native-datetimepicker/datetimepicker 的其他 Issue

查看 react-native-datetimepicker/datetimepicker 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。