Skip to content

Commit

Permalink
Flow ViewPropTypes (facebook#22504)
Browse files Browse the repository at this point in the history
Summary:
Related to facebook#22100

Enhance ViewPropTypes flow types.
- I had some troubles with a TODO left for `onResponderGrant` hence the return type.
- I wasn't able to properly type `nativeBackgroundAndroid` and `nativeForegroundAndroid` at the moment.
Pull Request resolved: facebook#22504

Reviewed By: cpojer

Differential Revision: D13334024

Pulled By: TheSavior

fbshipit-source-id: cada236e0d716ae78cb663172e5315cf11c6406a
  • Loading branch information
exced authored and facebook-github-bot committed Dec 5, 2018
1 parent c3b3eb7 commit 9facd81
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
51 changes: 27 additions & 24 deletions Libraries/Components/View/ViewPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

'use strict';

import type {Layout, LayoutEvent} from 'CoreEventTypes';
import type {PressEvent, Layout, LayoutEvent} from 'CoreEventTypes';
import type {EdgeInsetsProp} from 'EdgeInsetsPropType';
import type React from 'React';
import type {ViewStyleProp} from 'StyleSheet';
Expand All @@ -32,15 +32,15 @@ type DirectEventProps = $ReadOnly<{|
*
* @platform ios
*/
onAccessibilityAction?: ?Function,
onAccessibilityAction?: ?(string) => void,

/**
* When `accessible` is true, the system will try to invoke this function
* when the user performs accessibility tap gesture.
*
* See http://facebook.github.io/react-native/docs/view.html#onaccessibilitytap
*/
onAccessibilityTap?: ?Function,
onAccessibilityTap?: ?() => void,

/**
* Invoked on mount and layout changes with:
Expand All @@ -61,18 +61,18 @@ type DirectEventProps = $ReadOnly<{|
*
* See http://facebook.github.io/react-native/docs/view.html#onmagictap
*/
onMagicTap?: ?Function,
onMagicTap?: ?() => void,
|}>;

type TouchEventProps = $ReadOnly<{|
onTouchCancel?: ?Function,
onTouchCancelCapture?: ?Function,
onTouchEnd?: ?Function,
onTouchEndCapture?: ?Function,
onTouchMove?: ?Function,
onTouchMoveCapture?: ?Function,
onTouchStart?: ?Function,
onTouchStartCapture?: ?Function,
onTouchCancel?: ?(e: PressEvent) => void,
onTouchCancelCapture?: ?(e: PressEvent) => void,
onTouchEnd?: ?(e: PressEvent) => void,
onTouchEndCapture?: ?(e: PressEvent) => void,
onTouchMove?: ?(e: PressEvent) => void,
onTouchMoveCapture?: ?(e: PressEvent) => void,
onTouchStart?: ?(e: PressEvent) => void,
onTouchStartCapture?: ?(e: PressEvent) => void,
|}>;

/**
Expand All @@ -90,7 +90,7 @@ type GestureResponderEventProps = $ReadOnly<{|
*
* See http://facebook.github.io/react-native/docs/view.html#onmoveshouldsetresponder
*/
onMoveShouldSetResponder?: ?Function,
onMoveShouldSetResponder?: ?(e: PressEvent) => boolean,

/**
* If a parent `View` wants to prevent a child `View` from becoming responder
Expand All @@ -101,7 +101,7 @@ type GestureResponderEventProps = $ReadOnly<{|
*
* See http://facebook.github.io/react-native/docs/view.html#onMoveShouldsetrespondercapture
*/
onMoveShouldSetResponderCapture?: ?Function,
onMoveShouldSetResponderCapture?: ?(e: PressEvent) => boolean,

/**
* The View is now responding for touch events. This is the time to highlight
Expand All @@ -110,9 +110,12 @@ type GestureResponderEventProps = $ReadOnly<{|
* `View.props.onResponderGrant: (event) => {}`, where `event` is a synthetic
* touch event as described above.
*
* PanResponder includes a note `// TODO: t7467124 investigate if this can be removed` that
* should help fixing this return type.
*
* See http://facebook.github.io/react-native/docs/view.html#onrespondergrant
*/
onResponderGrant?: ?Function,
onResponderGrant?: ?(e: PressEvent) => void | boolean,

/**
* The user is moving their finger.
Expand All @@ -122,7 +125,7 @@ type GestureResponderEventProps = $ReadOnly<{|
*
* See http://facebook.github.io/react-native/docs/view.html#onrespondermove
*/
onResponderMove?: ?Function,
onResponderMove?: ?(e: PressEvent) => void,

/**
* Another responder is already active and will not release it to that `View`
Expand All @@ -133,7 +136,7 @@ type GestureResponderEventProps = $ReadOnly<{|
*
* See http://facebook.github.io/react-native/docs/view.html#onresponderreject
*/
onResponderReject?: ?Function,
onResponderReject?: ?(e: PressEvent) => void,

/**
* Fired at the end of the touch.
Expand All @@ -143,10 +146,10 @@ type GestureResponderEventProps = $ReadOnly<{|
*
* See http://facebook.github.io/react-native/docs/view.html#onresponderrelease
*/
onResponderRelease?: ?Function,
onResponderRelease?: ?(e: PressEvent) => void,

onResponderStart?: ?Function,
onResponderEnd?: ?Function,
onResponderStart?: ?(e: PressEvent) => void,
onResponderEnd?: ?(e: PressEvent) => void,

/**
* The responder has been taken from the `View`. Might be taken by other
Expand All @@ -159,7 +162,7 @@ type GestureResponderEventProps = $ReadOnly<{|
*
* See http://facebook.github.io/react-native/docs/view.html#onresponderterminate
*/
onResponderTerminate?: ?Function,
onResponderTerminate?: ?(e: PressEvent) => void,

/**
* Some other `View` wants to become responder and is asking this `View` to
Expand All @@ -170,7 +173,7 @@ type GestureResponderEventProps = $ReadOnly<{|
*
* See http://facebook.github.io/react-native/docs/view.html#onresponderterminationrequest
*/
onResponderTerminationRequest?: ?Function,
onResponderTerminationRequest?: ?(e: PressEvent) => boolean,

/**
* Does this view want to become responder on the start of a touch?
Expand All @@ -180,7 +183,7 @@ type GestureResponderEventProps = $ReadOnly<{|
*
* See http://facebook.github.io/react-native/docs/view.html#onstartshouldsetresponder
*/
onStartShouldSetResponder?: ?Function,
onStartShouldSetResponder?: ?(e: PressEvent) => boolean,

/**
* If a parent `View` wants to prevent a child `View` from becoming responder
Expand All @@ -191,7 +194,7 @@ type GestureResponderEventProps = $ReadOnly<{|
*
* See http://facebook.github.io/react-native/docs/view.html#onstartshouldsetrespondercapture
*/
onStartShouldSetResponderCapture?: ?Function,
onStartShouldSetResponderCapture?: ?(e: PressEvent) => boolean,
|}>;

type AndroidViewProps = $ReadOnly<{|
Expand Down
9 changes: 3 additions & 6 deletions Libraries/Inspector/InspectorOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ const StyleSheet = require('StyleSheet');
const UIManager = require('UIManager');
const View = require('View');

import type {PressEvent} from 'CoreEventTypes';
import type {ViewStyleProp} from 'StyleSheet';

type EventLike = {
nativeEvent: Object,
};

type Inspected = $ReadOnly<{|
frame?: Object,
style?: ViewStyleProp,
Expand All @@ -35,7 +32,7 @@ type Props = $ReadOnly<{|
|}>;

class InspectorOverlay extends React.Component<Props> {
findViewForTouchEvent = (e: EventLike) => {
findViewForTouchEvent = (e: PressEvent) => {
const {locationX, locationY} = e.nativeEvent.touches[0];
UIManager.findSubviewIn(
this.props.inspectedViewTag,
Expand All @@ -50,7 +47,7 @@ class InspectorOverlay extends React.Component<Props> {
);
};

shouldSetResponser = (e: EventLike): boolean => {
shouldSetResponser = (e: PressEvent): boolean => {
this.findViewForTouchEvent(e);
return true;
};
Expand Down

0 comments on commit 9facd81

Please sign in to comment.