Flow ViewPropTypes (#22504)
Summary: Related to #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: https://github.com/facebook/react-native/pull/22504 Reviewed By: cpojer Differential Revision: D13334024 Pulled By: TheSavior fbshipit-source-id: cada236e0d716ae78cb663172e5315cf11c6406a
This commit is contained in:
Родитель
c3b3eb7f73
Коммит
9facd81894
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
import type {Layout, LayoutEvent} from 'CoreEventTypes';
|
import type {PressEvent, Layout, LayoutEvent} from 'CoreEventTypes';
|
||||||
import type {EdgeInsetsProp} from 'EdgeInsetsPropType';
|
import type {EdgeInsetsProp} from 'EdgeInsetsPropType';
|
||||||
import type React from 'React';
|
import type React from 'React';
|
||||||
import type {ViewStyleProp} from 'StyleSheet';
|
import type {ViewStyleProp} from 'StyleSheet';
|
||||||
|
@ -32,7 +32,7 @@ type DirectEventProps = $ReadOnly<{|
|
||||||
*
|
*
|
||||||
* @platform ios
|
* @platform ios
|
||||||
*/
|
*/
|
||||||
onAccessibilityAction?: ?Function,
|
onAccessibilityAction?: ?(string) => void,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When `accessible` is true, the system will try to invoke this function
|
* When `accessible` is true, the system will try to invoke this function
|
||||||
|
@ -40,7 +40,7 @@ type DirectEventProps = $ReadOnly<{|
|
||||||
*
|
*
|
||||||
* See http://facebook.github.io/react-native/docs/view.html#onaccessibilitytap
|
* See http://facebook.github.io/react-native/docs/view.html#onaccessibilitytap
|
||||||
*/
|
*/
|
||||||
onAccessibilityTap?: ?Function,
|
onAccessibilityTap?: ?() => void,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked on mount and layout changes with:
|
* Invoked on mount and layout changes with:
|
||||||
|
@ -61,18 +61,18 @@ type DirectEventProps = $ReadOnly<{|
|
||||||
*
|
*
|
||||||
* See http://facebook.github.io/react-native/docs/view.html#onmagictap
|
* See http://facebook.github.io/react-native/docs/view.html#onmagictap
|
||||||
*/
|
*/
|
||||||
onMagicTap?: ?Function,
|
onMagicTap?: ?() => void,
|
||||||
|}>;
|
|}>;
|
||||||
|
|
||||||
type TouchEventProps = $ReadOnly<{|
|
type TouchEventProps = $ReadOnly<{|
|
||||||
onTouchCancel?: ?Function,
|
onTouchCancel?: ?(e: PressEvent) => void,
|
||||||
onTouchCancelCapture?: ?Function,
|
onTouchCancelCapture?: ?(e: PressEvent) => void,
|
||||||
onTouchEnd?: ?Function,
|
onTouchEnd?: ?(e: PressEvent) => void,
|
||||||
onTouchEndCapture?: ?Function,
|
onTouchEndCapture?: ?(e: PressEvent) => void,
|
||||||
onTouchMove?: ?Function,
|
onTouchMove?: ?(e: PressEvent) => void,
|
||||||
onTouchMoveCapture?: ?Function,
|
onTouchMoveCapture?: ?(e: PressEvent) => void,
|
||||||
onTouchStart?: ?Function,
|
onTouchStart?: ?(e: PressEvent) => void,
|
||||||
onTouchStartCapture?: ?Function,
|
onTouchStartCapture?: ?(e: PressEvent) => void,
|
||||||
|}>;
|
|}>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -90,7 +90,7 @@ type GestureResponderEventProps = $ReadOnly<{|
|
||||||
*
|
*
|
||||||
* See http://facebook.github.io/react-native/docs/view.html#onmoveshouldsetresponder
|
* 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
|
* If a parent `View` wants to prevent a child `View` from becoming responder
|
||||||
|
@ -101,7 +101,7 @@ type GestureResponderEventProps = $ReadOnly<{|
|
||||||
*
|
*
|
||||||
* See http://facebook.github.io/react-native/docs/view.html#onMoveShouldsetrespondercapture
|
* 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
|
* The View is now responding for touch events. This is the time to highlight
|
||||||
|
@ -110,9 +110,12 @@ type GestureResponderEventProps = $ReadOnly<{|
|
||||||
* `View.props.onResponderGrant: (event) => {}`, where `event` is a synthetic
|
* `View.props.onResponderGrant: (event) => {}`, where `event` is a synthetic
|
||||||
* touch event as described above.
|
* 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
|
* See http://facebook.github.io/react-native/docs/view.html#onrespondergrant
|
||||||
*/
|
*/
|
||||||
onResponderGrant?: ?Function,
|
onResponderGrant?: ?(e: PressEvent) => void | boolean,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The user is moving their finger.
|
* The user is moving their finger.
|
||||||
|
@ -122,7 +125,7 @@ type GestureResponderEventProps = $ReadOnly<{|
|
||||||
*
|
*
|
||||||
* See http://facebook.github.io/react-native/docs/view.html#onrespondermove
|
* 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`
|
* Another responder is already active and will not release it to that `View`
|
||||||
|
@ -133,7 +136,7 @@ type GestureResponderEventProps = $ReadOnly<{|
|
||||||
*
|
*
|
||||||
* See http://facebook.github.io/react-native/docs/view.html#onresponderreject
|
* See http://facebook.github.io/react-native/docs/view.html#onresponderreject
|
||||||
*/
|
*/
|
||||||
onResponderReject?: ?Function,
|
onResponderReject?: ?(e: PressEvent) => void,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fired at the end of the touch.
|
* Fired at the end of the touch.
|
||||||
|
@ -143,10 +146,10 @@ type GestureResponderEventProps = $ReadOnly<{|
|
||||||
*
|
*
|
||||||
* See http://facebook.github.io/react-native/docs/view.html#onresponderrelease
|
* See http://facebook.github.io/react-native/docs/view.html#onresponderrelease
|
||||||
*/
|
*/
|
||||||
onResponderRelease?: ?Function,
|
onResponderRelease?: ?(e: PressEvent) => void,
|
||||||
|
|
||||||
onResponderStart?: ?Function,
|
onResponderStart?: ?(e: PressEvent) => void,
|
||||||
onResponderEnd?: ?Function,
|
onResponderEnd?: ?(e: PressEvent) => void,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The responder has been taken from the `View`. Might be taken by other
|
* The responder has been taken from the `View`. Might be taken by other
|
||||||
|
@ -159,7 +162,7 @@ type GestureResponderEventProps = $ReadOnly<{|
|
||||||
*
|
*
|
||||||
* See http://facebook.github.io/react-native/docs/view.html#onresponderterminate
|
* 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
|
* Some other `View` wants to become responder and is asking this `View` to
|
||||||
|
@ -170,7 +173,7 @@ type GestureResponderEventProps = $ReadOnly<{|
|
||||||
*
|
*
|
||||||
* See http://facebook.github.io/react-native/docs/view.html#onresponderterminationrequest
|
* 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?
|
* Does this view want to become responder on the start of a touch?
|
||||||
|
@ -180,7 +183,7 @@ type GestureResponderEventProps = $ReadOnly<{|
|
||||||
*
|
*
|
||||||
* See http://facebook.github.io/react-native/docs/view.html#onstartshouldsetresponder
|
* 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
|
* If a parent `View` wants to prevent a child `View` from becoming responder
|
||||||
|
@ -191,7 +194,7 @@ type GestureResponderEventProps = $ReadOnly<{|
|
||||||
*
|
*
|
||||||
* See http://facebook.github.io/react-native/docs/view.html#onstartshouldsetrespondercapture
|
* See http://facebook.github.io/react-native/docs/view.html#onstartshouldsetrespondercapture
|
||||||
*/
|
*/
|
||||||
onStartShouldSetResponderCapture?: ?Function,
|
onStartShouldSetResponderCapture?: ?(e: PressEvent) => boolean,
|
||||||
|}>;
|
|}>;
|
||||||
|
|
||||||
type AndroidViewProps = $ReadOnly<{|
|
type AndroidViewProps = $ReadOnly<{|
|
||||||
|
|
|
@ -17,12 +17,9 @@ const StyleSheet = require('StyleSheet');
|
||||||
const UIManager = require('UIManager');
|
const UIManager = require('UIManager');
|
||||||
const View = require('View');
|
const View = require('View');
|
||||||
|
|
||||||
|
import type {PressEvent} from 'CoreEventTypes';
|
||||||
import type {ViewStyleProp} from 'StyleSheet';
|
import type {ViewStyleProp} from 'StyleSheet';
|
||||||
|
|
||||||
type EventLike = {
|
|
||||||
nativeEvent: Object,
|
|
||||||
};
|
|
||||||
|
|
||||||
type Inspected = $ReadOnly<{|
|
type Inspected = $ReadOnly<{|
|
||||||
frame?: Object,
|
frame?: Object,
|
||||||
style?: ViewStyleProp,
|
style?: ViewStyleProp,
|
||||||
|
@ -35,7 +32,7 @@ type Props = $ReadOnly<{|
|
||||||
|}>;
|
|}>;
|
||||||
|
|
||||||
class InspectorOverlay extends React.Component<Props> {
|
class InspectorOverlay extends React.Component<Props> {
|
||||||
findViewForTouchEvent = (e: EventLike) => {
|
findViewForTouchEvent = (e: PressEvent) => {
|
||||||
const {locationX, locationY} = e.nativeEvent.touches[0];
|
const {locationX, locationY} = e.nativeEvent.touches[0];
|
||||||
UIManager.findSubviewIn(
|
UIManager.findSubviewIn(
|
||||||
this.props.inspectedViewTag,
|
this.props.inspectedViewTag,
|
||||||
|
@ -50,7 +47,7 @@ class InspectorOverlay extends React.Component<Props> {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
shouldSetResponser = (e: EventLike): boolean => {
|
shouldSetResponser = (e: PressEvent): boolean => {
|
||||||
this.findViewForTouchEvent(e);
|
this.findViewForTouchEvent(e);
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
Загрузка…
Ссылка в новой задаче