From fb7b2d353356f67a3149c19ad733d46ec6842767 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Osadnik?= Date: Wed, 10 Jul 2019 05:37:03 -0700 Subject: [PATCH] Change returning value of DirectEventHandler and BubblingEventHandler to void Summary: returning type of Bubbling and Direct Event should be always void of Promise (if async). Other situations shouldn't be permitted. Reformated all cases when it the function wasn't void. Reviewed By: rickhanlonii Differential Revision: D16165962 fbshipit-source-id: 7c1377c3ed4bd54a431a13e5bcda4f7ec0adf4dc --- .../DrawerLayoutAndroid.android.js | 30 +++++++++---------- .../RefreshControl/RefreshControl.js | 2 +- .../SegmentedControlIOS.ios.js | 2 +- Libraries/Modal/Modal.js | 16 +++++----- Libraries/Types/CodegenTypes.js | 4 +-- 5 files changed, 25 insertions(+), 29 deletions(-) diff --git a/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js b/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js index 31dcf36dc93..9023c5f4811 100644 --- a/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js +++ b/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js @@ -28,7 +28,7 @@ const DRAWER_STATES = ['Idle', 'Dragging', 'Settling']; import type {ViewStyleProp} from '../../StyleSheet/StyleSheet'; import type {ColorValue} from '../../StyleSheet/StyleSheetTypes'; -import type {SyntheticEvent} from '../../Types/CoreEventTypes'; +import type {DirectEventHandler} from '../../Types/CodegenTypes'; import type { MeasureOnSuccessCallback, MeasureInWindowOnSuccessCallback, @@ -37,17 +37,9 @@ import type { type DrawerStates = 'Idle' | 'Dragging' | 'Settling'; -type DrawerStateEvent = SyntheticEvent< - $ReadOnly<{| - drawerState: number, - |}>, ->; - -type DrawerSlideEvent = SyntheticEvent< - $ReadOnly<{| - offset: number, - |}>, ->; +type DrawerSlideEvent = $ReadOnly<{| + offset: number, +|}>; type Props = $ReadOnly<{| /** @@ -93,7 +85,7 @@ type Props = $ReadOnly<{| /** * Function called whenever there is an interaction with the navigation view. */ - onDrawerSlide?: ?(event: DrawerSlideEvent) => mixed, + onDrawerSlide?: ?DirectEventHandler, /** * Function called when the drawer state has changed. The drawer can be in 3 states: @@ -176,7 +168,13 @@ class DrawerLayoutAndroid extends React.Component { state = {statusBarBackgroundColor: null}; render() { - const {onDrawerStateChanged, renderNavigationView, ...props} = this.props; + const { + onDrawerStateChanged, + renderNavigationView, + onDrawerOpen, + onDrawerClose, + ...props + } = this.props; const drawStatusBar = Platform.Version >= 21 && this.props.statusBarBackgroundColor; const drawerViewWrapper = ( @@ -233,7 +231,7 @@ class DrawerLayoutAndroid extends React.Component { ); } - _onDrawerSlide = (event: DrawerSlideEvent) => { + _onDrawerSlide = event => { if (this.props.onDrawerSlide) { this.props.onDrawerSlide(event); } @@ -254,7 +252,7 @@ class DrawerLayoutAndroid extends React.Component { } }; - _onDrawerStateChanged = (event: DrawerStateEvent) => { + _onDrawerStateChanged = event => { if (this.props.onDrawerStateChanged) { this.props.onDrawerStateChanged( DRAWER_STATES[event.nativeEvent.drawerState], diff --git a/Libraries/Components/RefreshControl/RefreshControl.js b/Libraries/Components/RefreshControl/RefreshControl.js index c0eea823b81..773d73d2490 100644 --- a/Libraries/Components/RefreshControl/RefreshControl.js +++ b/Libraries/Components/RefreshControl/RefreshControl.js @@ -81,7 +81,7 @@ export type RefreshControlProps = $ReadOnly<{| /** * Called when the view starts refreshing. */ - onRefresh?: ?() => mixed, + onRefresh?: ?() => void, /** * Whether the view should be indicating an active refresh. diff --git a/Libraries/Components/SegmentedControlIOS/SegmentedControlIOS.ios.js b/Libraries/Components/SegmentedControlIOS/SegmentedControlIOS.ios.js index a98e26e909b..f438b1b8573 100644 --- a/Libraries/Components/SegmentedControlIOS/SegmentedControlIOS.ios.js +++ b/Libraries/Components/SegmentedControlIOS/SegmentedControlIOS.ios.js @@ -43,7 +43,7 @@ type SegmentedControlIOSProps = $ReadOnly<{| /** * Callback that is called when the user taps a segment */ - onChange?: ?(event: SyntheticEvent) => mixed, + onChange?: ?(event: SyntheticEvent) => void, /** * Callback that is called when the user taps a segment; * passes the segment's value as an argument diff --git a/Libraries/Modal/Modal.js b/Libraries/Modal/Modal.js index fad0538e45c..38e77f34f83 100644 --- a/Libraries/Modal/Modal.js +++ b/Libraries/Modal/Modal.js @@ -29,7 +29,7 @@ const ModalEventEmitter = import type EmitterSubscription from '../vendor/emitter/EmitterSubscription'; import type {ViewProps} from '../Components/View/ViewPropTypes'; import type {SyntheticEvent} from '../Types/CoreEventTypes'; - +import type {DirectEventHandler} from '../Types/CodegenTypes'; /** * The Modal component is a simple way to present content above an enclosing view. * @@ -42,11 +42,9 @@ import type {SyntheticEvent} from '../Types/CoreEventTypes'; // destroyed before the callback is fired. let uniqueModalIdentifier = 0; -export type OrientationChangeEvent = SyntheticEvent< - $ReadOnly<{| - orientation: 'portrait' | 'landscape', - |}>, ->; +type OrientationChangeEvent = $ReadOnly<{| + orientation: 'portrait' | 'landscape', +|}>; export type Props = $ReadOnly<{| ...ViewProps, @@ -101,7 +99,7 @@ export type Props = $ReadOnly<{| * * See https://facebook.github.io/react-native/docs/modal.html#onrequestclose */ - onRequestClose?: ?(event?: SyntheticEvent) => mixed, + onRequestClose?: ?DirectEventHandler, /** * The `onShow` prop allows passing a function that will be called once the @@ -109,7 +107,7 @@ export type Props = $ReadOnly<{| * * See https://facebook.github.io/react-native/docs/modal.html#onshow */ - onShow?: ?(event?: SyntheticEvent) => mixed, + onShow?: ?DirectEventHandler, /** * The `onDismiss` prop allows passing a function that will be called once @@ -142,7 +140,7 @@ export type Props = $ReadOnly<{| * * See https://facebook.github.io/react-native/docs/modal.html#onorientationchange */ - onOrientationChange?: ?(event: OrientationChangeEvent) => mixed, + onOrientationChange?: ?DirectEventHandler, |}>; class Modal extends React.Component { diff --git a/Libraries/Types/CodegenTypes.js b/Libraries/Types/CodegenTypes.js index 0ef355ddbd6..2b41832a61a 100644 --- a/Libraries/Types/CodegenTypes.js +++ b/Libraries/Types/CodegenTypes.js @@ -18,11 +18,11 @@ import type {SyntheticEvent} from './CoreEventTypes'; export type BubblingEventHandler< T, PaperName: string | empty = empty, // eslint-disable-line no-unused-vars -> = (event: SyntheticEvent) => mixed; +> = (event: SyntheticEvent) => void | Promise; export type DirectEventHandler< T, PaperName: string | empty = empty, // eslint-disable-line no-unused-vars -> = (event: SyntheticEvent) => mixed; +> = (event: SyntheticEvent) => void | Promise; // Prop types export type Float = number;