Skip to content

Commit

Permalink
Flow strict in DatePickerAndroid.android.js, DatePickerAndroid.ios.js (
Browse files Browse the repository at this point in the history
…facebook#22106)

Summary:
Related to facebook#22100

Turn Flow strict mode on for DatePickerAndroid

- [x] npm run prettier
- [ ] npm run flow-check-ios
- [ ] npm run flow-check-android

This error was happend facebook#22101 facebook#22048

[GENERAL] [ENHANCEMENT] [Components/DatePickerAndroid/DatePickerAndroid.android.js] - Flow strict mode
[GENERAL] [ENHANCEMENT] [Components/DatePickerAndroid/DatePickerAndroid.ios.js] - Flow strict mode
Pull Request resolved: facebook#22106

Reviewed By: TheSavior

Differential Revision: D12919276

Pulled By: RSNara

fbshipit-source-id: 79672b2894435ca3c9988fefee3685700a8d8936
  • Loading branch information
nissy-dev authored and facebook-github-bot committed Dec 26, 2018
1 parent 19d69f9 commit 60f3b53
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,38 @@
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
* @flow strict-local
*/

'use strict';

const DatePickerModule = require('NativeModules').DatePickerAndroid;

type Options = $ReadOnly<{|
date?: ?(Date | number),
minDate?: ?(Date | number),
maxDate?: ?(Date | number),
mode?: ?('calender' | 'spinner' | 'default'),
|}>;

type DatePickerOpenAction =
| {|
action: 'dateSetAction',
year: number,
month: number,
day: number,
|}
| {|
action: 'dismissedAction',
year: typeof undefined,
month: typeof undefined,
day: typeof undefined,
|};

/**
* Convert a Date to a timestamp.
*/
function _toMillis(options: Object, key: string) {
function _toMillis(options: Options, key: string) {
const dateVal = options[key];
// Is it a Date object?
if (typeof dateVal === 'object' && typeof dateVal.getMonth === 'function') {
Expand Down Expand Up @@ -65,7 +86,7 @@ class DatePickerAndroid {
* Note the native date picker dialog has some UI glitches on Android 4 and lower
* when using the `minDate` and `maxDate` options.
*/
static async open(options: Object): Promise<Object> {
static async open(options: Options): Promise<DatePickerOpenAction> {
const optionsMs = options;
if (optionsMs) {
_toMillis(options, 'date');
Expand All @@ -78,15 +99,11 @@ class DatePickerAndroid {
/**
* A date has been selected.
*/
static get dateSetAction() {
return 'dateSetAction';
}
static dateSetAction = 'dateSetAction';
/**
* The dialog has been dismissed.
*/
static get dismissedAction() {
return 'dismissedAction';
}
static dismissedAction = 'dismissedAction';
}

module.exports = DatePickerAndroid;
11 changes: 9 additions & 2 deletions Libraries/Components/DatePickerAndroid/DatePickerAndroid.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
* @flow strict-local
*/

'use strict';

type Options = $ReadOnly<{|
date?: ?(Date | number),
minDate?: ?(Date | number),
maxDate?: ?(Date | number),
mode?: ?('calender' | 'spinner' | 'default'),
|}>;

const DatePickerAndroid = {
async open(options: Object): Promise<Object> {
async open(options: Options): Promise<void> {
return Promise.reject({
message: 'DatePickerAndroid is not supported on this platform.',
});
Expand Down

0 comments on commit 60f3b53

Please sign in to comment.