From f26b9ee777389d2599e9bf0583cab387e322aa90 Mon Sep 17 00:00:00 2001 From: Tnarita0000 Date: Tue, 6 Nov 2018 02:45:38 +0900 Subject: [PATCH 1/3] Flow strict-local in TimePickerAndroid.android.js --- .../TimePickerAndroid.android.js | 25 ++++++++++++++++--- RNTester/js/TimePickerAndroidExample.js | 4 +-- .../js/TimePickerDialogTestModule.js | 4 +-- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/Libraries/Components/TimePickerAndroid/TimePickerAndroid.android.js b/Libraries/Components/TimePickerAndroid/TimePickerAndroid.android.js index bdb29421f89d0e..7290c59253a7bb 100644 --- a/Libraries/Components/TimePickerAndroid/TimePickerAndroid.android.js +++ b/Libraries/Components/TimePickerAndroid/TimePickerAndroid.android.js @@ -5,13 +5,15 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow + * @flow strict-local */ 'use strict'; const TimePickerModule = require('NativeModules').TimePickerAndroid; +import type {SyntheticEvent} from 'CoreEventTypes'; + /** * Opens the standard Android time picker dialog. * @@ -32,6 +34,21 @@ const TimePickerModule = require('NativeModules').TimePickerAndroid; * } * ``` */ +type Options = { + hour: number, + minute: number, + is24Hour: boolean, + mode: 'clock' | 'spinner' | 'default', +}; + +type TimePickerAndroidEvent = SyntheticEvent< + $ReadOnly<{| + action: string, + hour: number, + minute: number, + |}>, +>; + class TimePickerAndroid { /** * Opens the standard Android time picker dialog. @@ -52,20 +69,20 @@ class TimePickerAndroid { * still be resolved with action being `TimePickerAndroid.dismissedAction` and all the other keys * being undefined. **Always** check whether the `action` before reading the values. */ - static async open(options: Object): Promise { + static async open(options: Options): Promise { return TimePickerModule.open(options); } /** * A time has been selected. */ - static get timeSetAction() { + static getTimeSetAction(): string { return 'timeSetAction'; } /** * The dialog has been dismissed. */ - static get dismissedAction() { + static getDismissedAction(): string { return 'dismissedAction'; } } diff --git a/RNTester/js/TimePickerAndroidExample.js b/RNTester/js/TimePickerAndroidExample.js index e2b56d9dcc6cc7..746623ccf15865 100644 --- a/RNTester/js/TimePickerAndroidExample.js +++ b/RNTester/js/TimePickerAndroidExample.js @@ -40,11 +40,11 @@ class TimePickerAndroidExample extends React.Component { try { const {action, minute, hour} = await TimePickerAndroid.open(options); const newState = {}; - if (action === TimePickerAndroid.timeSetAction) { + if (action === TimePickerAndroid.getTimeSetAction) { newState[stateKey + 'Text'] = _formatTime(hour, minute); newState[stateKey + 'Hour'] = hour; newState[stateKey + 'Minute'] = minute; - } else if (action === TimePickerAndroid.dismissedAction) { + } else if (action === TimePickerAndroid.getDismissedAction) { newState[stateKey + 'Text'] = 'dismissed'; } this.setState(newState); diff --git a/ReactAndroid/src/androidTest/js/TimePickerDialogTestModule.js b/ReactAndroid/src/androidTest/js/TimePickerDialogTestModule.js index 3c179fd4ee1c9f..3063bc05686a47 100644 --- a/ReactAndroid/src/androidTest/js/TimePickerDialogTestModule.js +++ b/ReactAndroid/src/androidTest/js/TimePickerDialogTestModule.js @@ -26,9 +26,9 @@ var TimePickerDialogTestModule = { showTimePickerDialog: function(options) { TimePickerAndroid.open(options).then( ({action, hour, minute}) => { - if (action === TimePickerAndroid.timeSetAction) { + if (action === TimePickerAndroid.getTimeSetAction) { RecordingModule.recordTime(hour, minute); - } else if (action === TimePickerAndroid.dismissedAction) { + } else if (action === TimePickerAndroid.getDismissedAction) { RecordingModule.recordDismissed(); } }, From ac37a442876ebbb2a0b7d1d16b1b0567e86ce9db Mon Sep 17 00:00:00 2001 From: Tnarita0000 Date: Tue, 6 Nov 2018 07:47:55 +0900 Subject: [PATCH 2/3] Replace getter function into static property --- .../TimePickerAndroid/TimePickerAndroid.android.js | 8 ++------ RNTester/js/TimePickerAndroidExample.js | 4 ++-- .../src/androidTest/js/TimePickerDialogTestModule.js | 4 ++-- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/Libraries/Components/TimePickerAndroid/TimePickerAndroid.android.js b/Libraries/Components/TimePickerAndroid/TimePickerAndroid.android.js index 7290c59253a7bb..9325f94f7d508b 100644 --- a/Libraries/Components/TimePickerAndroid/TimePickerAndroid.android.js +++ b/Libraries/Components/TimePickerAndroid/TimePickerAndroid.android.js @@ -76,15 +76,11 @@ class TimePickerAndroid { /** * A time has been selected. */ - static getTimeSetAction(): string { - return 'timeSetAction'; - } + static timeSetAction = 'timeSetAction'; /** * The dialog has been dismissed. */ - static getDismissedAction(): string { - return 'dismissedAction'; - } + static dismissedAction = 'dismissedAction'; } module.exports = TimePickerAndroid; diff --git a/RNTester/js/TimePickerAndroidExample.js b/RNTester/js/TimePickerAndroidExample.js index 746623ccf15865..e2b56d9dcc6cc7 100644 --- a/RNTester/js/TimePickerAndroidExample.js +++ b/RNTester/js/TimePickerAndroidExample.js @@ -40,11 +40,11 @@ class TimePickerAndroidExample extends React.Component { try { const {action, minute, hour} = await TimePickerAndroid.open(options); const newState = {}; - if (action === TimePickerAndroid.getTimeSetAction) { + if (action === TimePickerAndroid.timeSetAction) { newState[stateKey + 'Text'] = _formatTime(hour, minute); newState[stateKey + 'Hour'] = hour; newState[stateKey + 'Minute'] = minute; - } else if (action === TimePickerAndroid.getDismissedAction) { + } else if (action === TimePickerAndroid.dismissedAction) { newState[stateKey + 'Text'] = 'dismissed'; } this.setState(newState); diff --git a/ReactAndroid/src/androidTest/js/TimePickerDialogTestModule.js b/ReactAndroid/src/androidTest/js/TimePickerDialogTestModule.js index 3063bc05686a47..3c179fd4ee1c9f 100644 --- a/ReactAndroid/src/androidTest/js/TimePickerDialogTestModule.js +++ b/ReactAndroid/src/androidTest/js/TimePickerDialogTestModule.js @@ -26,9 +26,9 @@ var TimePickerDialogTestModule = { showTimePickerDialog: function(options) { TimePickerAndroid.open(options).then( ({action, hour, minute}) => { - if (action === TimePickerAndroid.getTimeSetAction) { + if (action === TimePickerAndroid.timeSetAction) { RecordingModule.recordTime(hour, minute); - } else if (action === TimePickerAndroid.getDismissedAction) { + } else if (action === TimePickerAndroid.dismissedAction) { RecordingModule.recordDismissed(); } }, From ee83ffb59d5c73ee65cc343a12b002bfe2200b12 Mon Sep 17 00:00:00 2001 From: Tnarita0000 Date: Tue, 6 Nov 2018 21:12:32 +0900 Subject: [PATCH 3/3] modified to isolate file --- .../TimePickerAndroid.android.js | 17 +---------- .../TimePickerAndroidTypes.js | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 16 deletions(-) create mode 100644 Libraries/Components/TimePickerAndroid/TimePickerAndroidTypes.js diff --git a/Libraries/Components/TimePickerAndroid/TimePickerAndroid.android.js b/Libraries/Components/TimePickerAndroid/TimePickerAndroid.android.js index 9325f94f7d508b..e51ea72e024cda 100644 --- a/Libraries/Components/TimePickerAndroid/TimePickerAndroid.android.js +++ b/Libraries/Components/TimePickerAndroid/TimePickerAndroid.android.js @@ -12,7 +12,7 @@ const TimePickerModule = require('NativeModules').TimePickerAndroid; -import type {SyntheticEvent} from 'CoreEventTypes'; +import type {Options, TimePickerAndroidEvent} from './TimePickerAndroidTypes'; /** * Opens the standard Android time picker dialog. @@ -34,21 +34,6 @@ import type {SyntheticEvent} from 'CoreEventTypes'; * } * ``` */ -type Options = { - hour: number, - minute: number, - is24Hour: boolean, - mode: 'clock' | 'spinner' | 'default', -}; - -type TimePickerAndroidEvent = SyntheticEvent< - $ReadOnly<{| - action: string, - hour: number, - minute: number, - |}>, ->; - class TimePickerAndroid { /** * Opens the standard Android time picker dialog. diff --git a/Libraries/Components/TimePickerAndroid/TimePickerAndroidTypes.js b/Libraries/Components/TimePickerAndroid/TimePickerAndroidTypes.js new file mode 100644 index 00000000000000..d19a7887853569 --- /dev/null +++ b/Libraries/Components/TimePickerAndroid/TimePickerAndroidTypes.js @@ -0,0 +1,28 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @flow strict-local + */ + +'use strict'; + +import type {SyntheticEvent} from 'CoreEventTypes'; + +export type Options = { + hour: number, + minute: number, + is24Hour: boolean, + mode: 'clock' | 'spinner' | 'default', +}; + +export type TimePickerAndroidEvent = SyntheticEvent< + $ReadOnly<{| + action: string, + hour: number, + minute: number, + |}>, +>;