Skip to content

Commit

Permalink
Change returning value of DirectEventHandler and BubblingEventHandler…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
osdnk authored and facebook-github-bot committed Jul 10, 2019
1 parent 8e4b2e7 commit fb7b2d3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 29 deletions.
30 changes: 14 additions & 16 deletions Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<{|
/**
Expand Down Expand Up @@ -93,7 +85,7 @@ type Props = $ReadOnly<{|
/**
* Function called whenever there is an interaction with the navigation view.
*/
onDrawerSlide?: ?(event: DrawerSlideEvent) => mixed,
onDrawerSlide?: ?DirectEventHandler<DrawerSlideEvent>,

/**
* Function called when the drawer state has changed. The drawer can be in 3 states:
Expand Down Expand Up @@ -176,7 +168,13 @@ class DrawerLayoutAndroid extends React.Component<Props, State> {
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 = (
Expand Down Expand Up @@ -233,7 +231,7 @@ class DrawerLayoutAndroid extends React.Component<Props, State> {
);
}

_onDrawerSlide = (event: DrawerSlideEvent) => {
_onDrawerSlide = event => {
if (this.props.onDrawerSlide) {
this.props.onDrawerSlide(event);
}
Expand All @@ -254,7 +252,7 @@ class DrawerLayoutAndroid extends React.Component<Props, State> {
}
};

_onDrawerStateChanged = (event: DrawerStateEvent) => {
_onDrawerStateChanged = event => {
if (this.props.onDrawerStateChanged) {
this.props.onDrawerStateChanged(
DRAWER_STATES[event.nativeEvent.drawerState],
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Components/RefreshControl/RefreshControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type SegmentedControlIOSProps = $ReadOnly<{|
/**
* Callback that is called when the user taps a segment
*/
onChange?: ?(event: SyntheticEvent<OnChangeEvent>) => mixed,
onChange?: ?(event: SyntheticEvent<OnChangeEvent>) => void,
/**
* Callback that is called when the user taps a segment;
* passes the segment's value as an argument
Expand Down
16 changes: 7 additions & 9 deletions Libraries/Modal/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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,
Expand Down Expand Up @@ -101,15 +99,15 @@ export type Props = $ReadOnly<{|
*
* See https://facebook.github.io/react-native/docs/modal.html#onrequestclose
*/
onRequestClose?: ?(event?: SyntheticEvent<null>) => mixed,
onRequestClose?: ?DirectEventHandler<null>,

/**
* The `onShow` prop allows passing a function that will be called once the
* modal has been shown.
*
* See https://facebook.github.io/react-native/docs/modal.html#onshow
*/
onShow?: ?(event?: SyntheticEvent<null>) => mixed,
onShow?: ?DirectEventHandler<null>,

/**
* The `onDismiss` prop allows passing a function that will be called once
Expand Down Expand Up @@ -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<OrientationChangeEvent>,
|}>;

class Modal extends React.Component<Props> {
Expand Down
4 changes: 2 additions & 2 deletions Libraries/Types/CodegenTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>) => mixed;
> = (event: SyntheticEvent<T>) => void | Promise<void>;
export type DirectEventHandler<
T,
PaperName: string | empty = empty, // eslint-disable-line no-unused-vars
> = (event: SyntheticEvent<T>) => mixed;
> = (event: SyntheticEvent<T>) => void | Promise<void>;

// Prop types
export type Float = number;
Expand Down

0 comments on commit fb7b2d3

Please sign in to comment.