Skip to content

Commit

Permalink
Codemod arvr to use onPointer* instead of onEnter/onExit/onMove
Browse files Browse the repository at this point in the history
Summary: Changelog: [Internal] Improve experimental support for pointer event dispatching support in JS

Reviewed By: mdvacca

Differential Revision: D35216647

fbshipit-source-id: 212f038115e4713097db05847a9638efe0a25bed
  • Loading branch information
javache authored and facebook-github-bot committed Apr 5, 2022
1 parent 9f1fa91 commit 6e5cefe
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
41 changes: 24 additions & 17 deletions Libraries/Components/View/ViewPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {
BlurEvent,
FocusEvent,
MouseEvent,
PointerEvent,
PressEvent,
Layout,
LayoutEvent,
Expand Down Expand Up @@ -84,8 +85,28 @@ type DirectEventProps = $ReadOnly<{|
|}>;

type MouseEventProps = $ReadOnly<{|
onMouseEnter?: (event: MouseEvent) => void,
onMouseLeave?: (event: MouseEvent) => void,
onMouseEnter?: ?(event: MouseEvent) => void,
onMouseLeave?: ?(event: MouseEvent) => void,
|}>;

type PointerEventProps = $ReadOnly<{|
onPointerEnter?: ?(event: PointerEvent) => void,
onPointerLeave?: ?(event: PointerEvent) => void,
onPointerMove?: ?(event: PointerEvent) => void,
onPointerCancel?: ?(e: PointerEvent) => void,
onPointerCancelCapture?: ?(e: PointerEvent) => void,
onPointerDown?: ?(e: PointerEvent) => void,
onPointerDownCapture?: ?(e: PointerEvent) => void,
onPointerUp?: ?(e: PointerEvent) => void,
onPointerUpCapture?: ?(e: PointerEvent) => void,

// FIXME: these events are temporary while we converge pointer event handling
onPointerEnter2?: ?(e: PointerEvent) => void,
onPointerEnter2Capture?: ?(e: PointerEvent) => void,
onPointerLeave2?: ?(e: PointerEvent) => void,
onPointerLeave2Capture?: ?(e: PointerEvent) => void,
onPointerMove2?: ?(e: PointerEvent) => void,
onPointerMove2Capture?: ?(e: PointerEvent) => void,
|}>;

type TouchEventProps = $ReadOnly<{|
Expand All @@ -99,20 +120,6 @@ type TouchEventProps = $ReadOnly<{|
onTouchStartCapture?: ?(e: PressEvent) => void,
|}>;

type PointerEventCallbackProps = $ReadOnly<{|
onPointerCancel?: ?(e: PointerEvent) => void,
onPointerCancelCapture?: ?(e: PointerEvent) => void,
onPointerDown?: ?(e: PointerEvent) => void,
onPointerDownCapture?: ?(e: PointerEvent) => void,
onPointerEnter2?: ?(e: PointerEvent) => void,
onPointerLeave2?: ?(e: PointerEvent) => void,
onPointerEnter2Capture?: ?(e: PointerEvent) => void,
onPointerLeave2Capture?: ?(e: PointerEvent) => void,
onPointerMove2Capture?: ?(e: PointerEvent) => void,
onPointerUp?: ?(e: PointerEvent) => void,
onPointerUpCapture?: ?(e: PointerEvent) => void,
|}>;

/**
* For most touch interactions, you'll simply want to wrap your component in
* `TouchableHighlight` or `TouchableOpacity`. Check out `Touchable.js`,
Expand Down Expand Up @@ -395,8 +402,8 @@ export type ViewProps = $ReadOnly<{|
...DirectEventProps,
...GestureResponderEventProps,
...MouseEventProps,
...PointerEventProps,
...TouchEventProps,
...PointerEventCallbackProps,
...AndroidViewProps,
...IOSViewProps,

Expand Down
9 changes: 9 additions & 0 deletions Libraries/Text/TextProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import type {
LayoutEvent,
PointerEvent,
PressEvent,
TextLayoutEvent,
} from '../Types/CoreEventTypes';
Expand All @@ -31,10 +32,18 @@ export type PressRetentionOffset = $ReadOnly<{|
right: number,
|}>;

type PointerEventProps = $ReadOnly<{|
onPointerEnter?: (event: PointerEvent) => void,
onPointerLeave?: (event: PointerEvent) => void,
onPointerMove?: (event: PointerEvent) => void,
|}>;

/**
* @see https://reactnative.dev/docs/text#reference
*/
export type TextProps = $ReadOnly<{|
...PointerEventProps,

/**
* Indicates whether the view is an accessibility element.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function EventfulView(props: {|
const [tag, setTag] = React.useState('');

const eventLog = eventName => event => {
// $FlowFixMe[prop-missing] Using private property
// $FlowFixMe Using private property
log(`${name} - ${eventName} - target: ${event.target._nativeTag}`);
setLastEvent(eventName);
};
Expand Down

0 comments on commit 6e5cefe

Please sign in to comment.