Skip to content

[flow-strict] Flow strict-local in TimePickerAndroid.android.js #22154

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

Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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.
Expand All @@ -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<Object> {
static async open(options: Options): Promise<TimePickerAndroidEvent> {
return TimePickerModule.open(options);
}

/**
* A time has been selected.
*/
static get timeSetAction() {
static getTimeSetAction(): string {
Copy link
Contributor

@RSNara RSNara Nov 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of changing this getter into a function, which breaks the public API of this component, let's instead turn it into a covariant static property, which makes it read-only:

static +timeSetAction = 'timeSetAction'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RSNara Thank you for your advice. I've modified this.

return 'timeSetAction';
}
/**
* The dialog has been dismissed.
*/
static get dismissedAction() {
static getDismissedAction(): string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use a covariant static property here as well:

static +dismissedAction = 'dismissedAction';

return 'dismissedAction';
}
}
Expand Down
4 changes: 2 additions & 2 deletions RNTester/js/TimePickerAndroidExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions ReactAndroid/src/androidTest/js/TimePickerDialogTestModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
},
Expand Down