Skip to content

[0.57] [Android] DatePickerAndroid doesn't open because of null minDate #21253

Closed
MaxInMoon/react-native
#1
@MaxInMoon

Description

@MaxInMoon

Environment

  React Native Environment Info:
    System:
      OS: macOS High Sierra 10.13.6
      CPU: x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
      Memory: 55.30 MB / 8.00 GB
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 10.10.0 - /usr/local/bin/node
      Yarn: 1.9.4 - /usr/local/bin/yarn
      npm: 6.4.1 - /usr/local/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 11.4, macOS 10.13, tvOS 11.4, watchOS 4.3
    IDEs:
      Android Studio: 3.0 AI-171.4443003
      Xcode: 9.4.1/9F2000 - /usr/bin/xcodebuild
    npmPackages:
      react: ^16.5.1 => 16.5.1 
      react-native: ^0.57.0 => 0.57.0 
    npmGlobalPackages:
      react-native-cli: 2.0.1
      react-native-git-upgrade: 0.2.7

Description

Problem: when no minDate is provided, the DatePickerAndroid won't open because of this error:

Cannot read property 'getMonth' of null

For info, I use react-native-modal-datetime-picker, itself using DatePickerAndroid.

Cause

See the _toMillis function below.

function _toMillis(options: Object, key: string) {
  const dateVal = options[key];
  // Is it a Date object?
  if (typeof dateVal === 'object' && typeof dateVal.getMonth === 'function') {
    options[key] = dateVal.getTime();
  }
}

if (typeof dateVal === 'object' && typeof dateVal.getMonth === 'function') doesn't block when dateVal is null. Cause typeof null is object (wtf!?)

Reproducible Demo

I can provide a reproducible demo, but I want first to have your opinion about the issue I described above.

Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions