Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[react-events] Tap responder #16628

Merged
merged 2 commits into from
Sep 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions packages/react-dom/src/events/DOMEventResponderSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const eventResponderContext: ReactDOMResponderContext = {
}
}
},
isTargetWithinResponder(target: Element | Document): boolean {
isTargetWithinResponder(target: null | Element | Document): boolean {
validateResponderContext();
if (target != null) {
let fiber = getClosestInstanceFromNode(target);
Expand All @@ -132,7 +132,7 @@ const eventResponderContext: ReactDOMResponderContext = {
}
return false;
},
isTargetWithinResponderScope(target: Element | Document): boolean {
isTargetWithinResponderScope(target: null | Element | Document): boolean {
validateResponderContext();
const componentInstance = ((currentInstance: any): ReactDOMEventResponderInstance);
const responder = componentInstance.responder;
Expand All @@ -155,7 +155,7 @@ const eventResponderContext: ReactDOMResponderContext = {
return false;
},
isTargetWithinNode(
childTarget: Element | Document,
childTarget: null | Element | Document,
parentTarget: Element | Document,
): boolean {
validateResponderContext();
Expand Down Expand Up @@ -387,11 +387,9 @@ function createDOMResponderEvent(
): ReactDOMResponderEvent {
const {buttons, pointerType} = (nativeEvent: any);
let eventPointerType = '';
let pointerId = null;

if (pointerType !== undefined) {
eventPointerType = pointerType;
pointerId = (nativeEvent: any).pointerId;
} else if (nativeEvent.key !== undefined) {
eventPointerType = 'keyboard';
} else if (buttons !== undefined) {
Expand All @@ -404,7 +402,6 @@ function createDOMResponderEvent(
nativeEvent: nativeEvent,
passive,
passiveSupported,
pointerId,
pointerType: eventPointerType,
target: nativeEventTarget,
type: topLevelType,
Expand Down
7 changes: 7 additions & 0 deletions packages/react-events/npm/tap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react-events-tap.production.min.js');
} else {
module.exports = require('./cjs/react-events-tap.development.js');
}
1 change: 1 addition & 0 deletions packages/react-events/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"press.js",
"scroll.js",
"swipe.js",
"tap.js",
"build-info.json",
"cjs/",
"umd/"
Expand Down
16 changes: 11 additions & 5 deletions packages/react-events/src/dom/Press.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ const pressResponderImpl = {
props: PressProps,
state: PressState,
): void {
const {pointerId, pointerType, type} = event;
const {pointerType, type} = event;

if (props.disabled) {
removeRootEventTypes(context, state);
Expand Down Expand Up @@ -584,7 +584,7 @@ const pressResponderImpl = {
state.pointerType = pointerType;
const pressTarget = (state.pressTarget = context.getResponderNode());
if (isPointerEvent) {
state.activePointerId = pointerId;
state.activePointerId = nativeEvent.pointerId;
} else if (isTouchEvent) {
const touchEvent = getTouchFromPressEvent(nativeEvent);
if (touchEvent === null) {
Expand Down Expand Up @@ -652,7 +652,7 @@ const pressResponderImpl = {
props: PressProps,
state: PressState,
): void {
let {pointerId, pointerType, target, type} = event;
let {pointerType, target, type} = event;

const nativeEvent: any = event.nativeEvent;
const isPressed = state.isPressed;
Expand All @@ -672,7 +672,10 @@ const pressResponderImpl = {
if (previousPointerType !== pointerType) {
return;
}
if (type === 'pointermove' && activePointerId !== pointerId) {
if (
type === 'pointermove' &&
activePointerId !== nativeEvent.pointerId
Copy link
Contributor

@trueadm trueadm Sep 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not extract pointerId above? You use it just below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value is only used (and not null) within the the PointerEvent branches.

) {
return;
} else if (type === 'touchmove') {
touchEvent = getTouchById(nativeEvent, activePointerId);
Expand Down Expand Up @@ -733,7 +736,10 @@ const pressResponderImpl = {
const buttons = state.buttons;
let isKeyboardEvent = false;
let touchEvent;
if (type === 'pointerup' && activePointerId !== pointerId) {
if (
type === 'pointerup' &&
activePointerId !== nativeEvent.pointerId
) {
return;
} else if (type === 'touchend') {
touchEvent = getTouchById(nativeEvent, activePointerId);
Expand Down
Loading