-
Notifications
You must be signed in to change notification settings - Fork 47.3k
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
Use browser event names for top-level event types in React DOM #12629
Changes from 43 commits
d02d86a
45713ce
5f11da0
58a24ba
390fb51
3dcbf4d
1fb5cd8
96ce3cd
737626a
a03d896
d58cd30
e1b9166
f07a64f
da64f27
16c39e5
4a7114e
2a87568
0d864ca
586708e
12c9ac3
9d684fc
c27ab85
4043f87
f029940
0ace5a1
653492c
7e8b34f
2d21c09
d1c390b
ec0b881
352dfbf
ac6e3e2
4a7bf07
3ebd359
6095b0f
bb057bc
6800d01
4d76b15
af02875
c1f6b38
0cb8fad
df7f91d
15c2723
4b2ca6b
e19f37b
0c6982d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,21 +30,6 @@ export const injection = { | |
}, | ||
}; | ||
|
||
export function isEndish(topLevelType) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those methods have been used by the responder plugin and a dependency of the responder and were thus added in the |
||
return ( | ||
topLevelType === 'topMouseUp' || | ||
topLevelType === 'topTouchEnd' || | ||
topLevelType === 'topTouchCancel' | ||
); | ||
} | ||
|
||
export function isMoveish(topLevelType) { | ||
return topLevelType === 'topMouseMove' || topLevelType === 'topTouchMove'; | ||
} | ||
export function isStartish(topLevelType) { | ||
return topLevelType === 'topMouseDown' || topLevelType === 'topTouchStart'; | ||
} | ||
|
||
let validateEventDispatches; | ||
if (__DEV__) { | ||
validateEventDispatches = function(event) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,9 +8,6 @@ | |
import {getLowestCommonAncestor, isAncestor} from 'shared/ReactTreeTraversal'; | ||
|
||
import { | ||
isStartish, | ||
isMoveish, | ||
isEndish, | ||
executeDirectDispatch, | ||
hasDispatches, | ||
executeDispatchesInOrderStopAtTrue, | ||
|
@@ -24,6 +21,17 @@ import { | |
import ResponderSyntheticEvent from './ResponderSyntheticEvent'; | ||
import ResponderTouchHistoryStore from './ResponderTouchHistoryStore'; | ||
import accumulate from './accumulate'; | ||
import { | ||
TOP_SCROLL, | ||
TOP_SELECTION_CHANGE, | ||
TOP_TOUCH_CANCEL, | ||
isStartish, | ||
isMoveish, | ||
isEndish, | ||
startDependencies, | ||
moveDependencies, | ||
endDependencies, | ||
} from './ResponderTopLevelEventTypes'; | ||
|
||
/** | ||
* Instance of element that should respond to touch/move types of interactions, | ||
|
@@ -37,11 +45,6 @@ let responderInst = null; | |
*/ | ||
let trackedTouchCount = 0; | ||
|
||
/** | ||
* Last reported number of active touches. | ||
*/ | ||
let previousActiveTouches = 0; | ||
|
||
const changeResponder = function(nextResponderInst, blockHostResponder) { | ||
const oldResponderInst = responderInst; | ||
responderInst = nextResponderInst; | ||
|
@@ -64,6 +67,7 @@ const eventTypes = { | |
bubbled: 'onStartShouldSetResponder', | ||
captured: 'onStartShouldSetResponderCapture', | ||
}, | ||
dependencies: startDependencies, | ||
}, | ||
|
||
/** | ||
|
@@ -80,6 +84,7 @@ const eventTypes = { | |
bubbled: 'onScrollShouldSetResponder', | ||
captured: 'onScrollShouldSetResponderCapture', | ||
}, | ||
dependencies: [TOP_SCROLL], | ||
}, | ||
|
||
/** | ||
|
@@ -94,6 +99,7 @@ const eventTypes = { | |
bubbled: 'onSelectionChangeShouldSetResponder', | ||
captured: 'onSelectionChangeShouldSetResponderCapture', | ||
}, | ||
dependencies: [TOP_SELECTION_CHANGE], | ||
}, | ||
|
||
/** | ||
|
@@ -105,21 +111,44 @@ const eventTypes = { | |
bubbled: 'onMoveShouldSetResponder', | ||
captured: 'onMoveShouldSetResponderCapture', | ||
}, | ||
dependencies: moveDependencies, | ||
}, | ||
|
||
/** | ||
* Direct responder events dispatched directly to responder. Do not bubble. | ||
*/ | ||
responderStart: {registrationName: 'onResponderStart'}, | ||
responderMove: {registrationName: 'onResponderMove'}, | ||
responderEnd: {registrationName: 'onResponderEnd'}, | ||
responderRelease: {registrationName: 'onResponderRelease'}, | ||
responderStart: { | ||
registrationName: 'onResponderStart', | ||
dependencies: startDependencies, | ||
}, | ||
responderMove: { | ||
registrationName: 'onResponderMove', | ||
dependencies: moveDependencies, | ||
}, | ||
responderEnd: { | ||
registrationName: 'onResponderEnd', | ||
dependencies: endDependencies, | ||
}, | ||
responderRelease: { | ||
registrationName: 'onResponderRelease', | ||
dependencies: [], | ||
}, | ||
responderTerminationRequest: { | ||
registrationName: 'onResponderTerminationRequest', | ||
dependencies: [], | ||
}, | ||
responderGrant: { | ||
registrationName: 'onResponderGrant', | ||
dependencies: [], | ||
}, | ||
responderReject: { | ||
registrationName: 'onResponderReject', | ||
dependencies: [], | ||
}, | ||
responderTerminate: { | ||
registrationName: 'onResponderTerminate', | ||
dependencies: [], | ||
}, | ||
responderGrant: {registrationName: 'onResponderGrant'}, | ||
responderReject: {registrationName: 'onResponderReject'}, | ||
responderTerminate: {registrationName: 'onResponderTerminate'}, | ||
}; | ||
|
||
/** | ||
|
@@ -322,7 +351,7 @@ function setResponderAndExtractTransfer( | |
? eventTypes.startShouldSetResponder | ||
: isMoveish(topLevelType) | ||
? eventTypes.moveShouldSetResponder | ||
: topLevelType === 'topSelectionChange' | ||
: topLevelType === TOP_SELECTION_CHANGE | ||
? eventTypes.selectionChangeShouldSetResponder | ||
: eventTypes.scrollShouldSetResponder; | ||
|
||
|
@@ -427,8 +456,8 @@ function canTriggerTransfer(topLevelType, topLevelInst, nativeEvent) { | |
// responderIgnoreScroll: We are trying to migrate away from specifically | ||
// tracking native scroll events here and responderIgnoreScroll indicates we | ||
// will send topTouchCancel to handle canceling touch events instead | ||
((topLevelType === 'topScroll' && !nativeEvent.responderIgnoreScroll) || | ||
(trackedTouchCount > 0 && topLevelType === 'topSelectionChange') || | ||
((topLevelType === TOP_SCROLL && !nativeEvent.responderIgnoreScroll) || | ||
(trackedTouchCount > 0 && topLevelType === TOP_SELECTION_CHANGE) || | ||
isStartish(topLevelType) || | ||
isMoveish(topLevelType)) | ||
); | ||
|
@@ -534,7 +563,7 @@ const ResponderEventPlugin = { | |
} | ||
|
||
const isResponderTerminate = | ||
responderInst && topLevelType === 'topTouchCancel'; | ||
responderInst && topLevelType === TOP_TOUCH_CANCEL; | ||
const isResponderRelease = | ||
responderInst && | ||
!isResponderTerminate && | ||
|
@@ -556,41 +585,20 @@ const ResponderEventPlugin = { | |
changeResponder(null); | ||
} | ||
|
||
const numberActiveTouches = | ||
ResponderTouchHistoryStore.touchHistory.numberActiveTouches; | ||
if ( | ||
ResponderEventPlugin.GlobalInteractionHandler && | ||
numberActiveTouches !== previousActiveTouches | ||
) { | ||
ResponderEventPlugin.GlobalInteractionHandler.onChange( | ||
numberActiveTouches, | ||
); | ||
} | ||
previousActiveTouches = numberActiveTouches; | ||
|
||
return extracted; | ||
}, | ||
|
||
GlobalResponderHandler: null, | ||
GlobalInteractionHandler: null, | ||
|
||
injection: { | ||
/** | ||
* @param {{onChange: (ReactID, ReactID) => void} GlobalResponderHandler | ||
* Object that handles any change in responder. Use this to inject | ||
* integration with an existing touch handling system etc. | ||
*/ | ||
injectGlobalResponderHandler: function(GlobalResponderHandler) { | ||
injectGlobalResponderHandler(GlobalResponderHandler) { | ||
ResponderEventPlugin.GlobalResponderHandler = GlobalResponderHandler; | ||
}, | ||
|
||
/** | ||
* @param {{onChange: (numberActiveTouches) => void} GlobalInteractionHandler | ||
* Object that handles any change in the number of active touches. | ||
*/ | ||
injectGlobalInteractionHandler: function(GlobalInteractionHandler) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was unused so I removed it. |
||
ResponderEventPlugin.GlobalInteractionHandler = GlobalInteractionHandler; | ||
}, | ||
}, | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* Copyright (c) 2013-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
export const TOP_TOUCH_START = 'topTouchStart'; | ||
export const TOP_TOUCH_MOVE = 'topTouchMove'; | ||
export const TOP_TOUCH_END = 'topTouchEnd'; | ||
export const TOP_TOUCH_CANCEL = 'topTouchCancel'; | ||
export const TOP_SCROLL = 'topScroll'; | ||
export const TOP_SELECTION_CHANGE = 'topSelectionChange'; | ||
|
||
export function isStartish(topLevelType: mixed): boolean { | ||
return topLevelType === TOP_TOUCH_START; | ||
} | ||
|
||
export function isMoveish(topLevelType: mixed): boolean { | ||
return topLevelType === TOP_TOUCH_MOVE; | ||
} | ||
|
||
export function isEndish(topLevelType: mixed): boolean { | ||
return topLevelType === TOP_TOUCH_END || topLevelType === TOP_TOUCH_CANCEL; | ||
} | ||
|
||
export const startDependencies = [TOP_TOUCH_START]; | ||
export const moveDependencies = [TOP_TOUCH_MOVE]; | ||
export const endDependencies = [TOP_TOUCH_CANCEL, TOP_TOUCH_END]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Copyright (c) 2013-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
import type {DOMTopLevelEventType} from 'react-dom/src/events/DOMTopLevelEventTypes'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By importing the type from the Defining the opaque type in |
||
|
||
type RNTopLevelEventType = | ||
| 'topMouseDown' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a comment clarifying these are RN types? Or even declare them separately as |
||
| 'topMouseMove' | ||
| 'topMouseUp' | ||
| 'topScroll' | ||
| 'topSelectionChange' | ||
| 'topTouchCancel' | ||
| 'topTouchEnd' | ||
| 'topTouchMove' | ||
| 'topTouchStart'; | ||
|
||
export type TopLevelType = DOMTopLevelEventType | RNTopLevelEventType; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Copyright (c) 2013-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
// Note: ideally these would be imported from DOMTopLevelEventTypes, | ||
// but our build system currently doesn't let us do that from a fork. | ||
|
||
export const TOP_TOUCH_START = 'touchstart'; | ||
export const TOP_TOUCH_MOVE = 'touchmove'; | ||
export const TOP_TOUCH_END = 'touchend'; | ||
export const TOP_TOUCH_CANCEL = 'touchcancel'; | ||
export const TOP_SCROLL = 'scroll'; | ||
export const TOP_SELECTION_CHANGE = 'selectionchange'; | ||
export const TOP_MOUSE_DOWN = 'mousedown'; | ||
export const TOP_MOUSE_MOVE = 'mousemove'; | ||
export const TOP_MOUSE_UP = 'mouseup'; | ||
|
||
export function isStartish(topLevelType: mixed): boolean { | ||
return topLevelType === TOP_TOUCH_START || topLevelType === TOP_MOUSE_DOWN; | ||
} | ||
|
||
export function isMoveish(topLevelType: mixed): boolean { | ||
return topLevelType === TOP_TOUCH_MOVE || topLevelType === TOP_MOUSE_MOVE; | ||
} | ||
|
||
export function isEndish(topLevelType: mixed): boolean { | ||
return ( | ||
topLevelType === TOP_TOUCH_END || | ||
topLevelType === TOP_TOUCH_CANCEL || | ||
topLevelType === TOP_MOUSE_UP | ||
); | ||
} | ||
|
||
export const startDependencies = [TOP_TOUCH_START, TOP_MOUSE_DOWN]; | ||
export const moveDependencies = [TOP_TOUCH_MOVE, TOP_MOUSE_MOVE]; | ||
export const endDependencies = [TOP_TOUCH_CANCEL, TOP_TOUCH_END, TOP_MOUSE_UP]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've upgraded
babylon
and allbabel-*
packages. This was required to get proper support foropaque
types across the toolchain. All upgrades where minor version only.