Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
MaxInMoon opened this issue Sep 21, 2018 · 1 comment · Fixed by MaxInMoon/react-native#1
Closed
Labels
Platform: Android Android applications. Resolution: Locked This issue was locked by the bot.

Comments

@MaxInMoon
Copy link

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

@RSNara
Copy link
Contributor

RSNara commented Sep 24, 2018

Nice catch! This looks like a bug with _toMillis. Looks like we need to use something similar to _.isObjectLike here.

Would you like to launch a PR to fix this? If so, feel free to add me as a reviewer.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Platform: Android Android applications. Resolution: Locked This issue was locked by the bot.
Projects
None yet
3 participants