Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix flow error
  • Loading branch information
nissy-dev committed Nov 4, 2018
commit 5e70ce9c6ccc2a484e2ea26341cf7e3dda861016
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 DatePickerModuleOpen =
| {|
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<DatePickerModuleOpen> {
const optionsMs = options;
if (optionsMs) {
_toMillis(options, 'date');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@

'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<Object> {
return Promise.reject({
message: 'DatePickerAndroid is not supported on this platform.',
});
Expand Down