Skip to content

Commit bb11639

Browse files
committed
Import ResponderEventPlugin changes from RN
1 parent 67663ba commit bb11639

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

src/renderers/shared/event/eventPlugins/ResponderEventPlugin.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,14 @@ var trackedTouchCount = 0;
4646
*/
4747
var previousActiveTouches = 0;
4848

49-
var changeResponder = function(nextResponderInst) {
49+
var changeResponder = function(nextResponderInst, blockNativeResponder) {
5050
var oldResponderInst = responderInst;
5151
responderInst = nextResponderInst;
5252
if (ResponderEventPlugin.GlobalResponderHandler !== null) {
5353
ResponderEventPlugin.GlobalResponderHandler.onChange(
5454
oldResponderInst,
55-
nextResponderInst
55+
nextResponderInst,
56+
blockNativeResponder
5657
);
5758
}
5859
};
@@ -370,6 +371,7 @@ function setResponderAndExtractTransfer(
370371
grantEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
371372

372373
EventPropagators.accumulateDirectDispatches(grantEvent);
374+
var blockNativeResponder = executeDirectDispatch(grantEvent) === true;
373375
if (responderInst) {
374376

375377
var terminationRequestEvent = ResponderSyntheticEvent.getPooled(
@@ -396,7 +398,7 @@ function setResponderAndExtractTransfer(
396398
terminateEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
397399
EventPropagators.accumulateDirectDispatches(terminateEvent);
398400
extracted = accumulate(extracted, [grantEvent, terminateEvent]);
399-
changeResponder(wantsResponderInst);
401+
changeResponder(wantsResponderInst, blockNativeResponder);
400402
} else {
401403
var rejectEvent = ResponderSyntheticEvent.getPooled(
402404
eventTypes.responderReject,
@@ -410,7 +412,7 @@ function setResponderAndExtractTransfer(
410412
}
411413
} else {
412414
extracted = accumulate(extracted, grantEvent);
413-
changeResponder(wantsResponderInst);
415+
changeResponder(wantsResponderInst, blockNativeResponder);
414416
}
415417
return extracted;
416418
}
@@ -423,9 +425,13 @@ function setResponderAndExtractTransfer(
423425
* @param {string} topLevelType Record from `EventConstants`.
424426
* @return {boolean} True if a transfer of responder could possibly occur.
425427
*/
426-
function canTriggerTransfer(topLevelType, targetInst) {
427-
return !!targetInst && (
428-
topLevelType === EventConstants.topLevelTypes.topScroll ||
428+
function canTriggerTransfer(topLevelType, topLevelInst, nativeEvent) {
429+
return topLevelInst && (
430+
// responderIgnoreScroll: We are trying to migrate away from specifically
431+
// tracking native scroll events here and responderIgnoreScroll indicates we
432+
// will send topTouchCancel to handle canceling touch events instead
433+
(topLevelType === EventConstants.topLevelTypes.topScroll &&
434+
!nativeEvent.responderIgnoreScroll) ||
429435
(trackedTouchCount > 0 &&
430436
topLevelType === EventConstants.topLevelTypes.topSelectionChange) ||
431437
isStartish(topLevelType) ||
@@ -492,7 +498,7 @@ var ResponderEventPlugin = {
492498

493499
ResponderTouchHistoryStore.recordTouchTrack(topLevelType, nativeEvent, nativeEventTarget);
494500

495-
var extracted = canTriggerTransfer(topLevelType, targetInst) ?
501+
var extracted = canTriggerTransfer(topLevelType, targetInst, nativeEvent) ?
496502
setResponderAndExtractTransfer(
497503
topLevelType,
498504
targetInst,

src/renderers/shared/event/eventPlugins/__tests__/ResponderEventPlugin-test.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -730,8 +730,8 @@ describe('ResponderEventPlugin', function() {
730730

731731
// Parent is responder, and responder is transferred by a second touch start
732732
config.startShouldSetResponder.captured.grandParent = {order: 0, returnVal: true};
733-
config.responderTerminationRequest.parent = {order: 1, returnVal: true};
734-
config.responderGrant.grandParent = {order: 2};
733+
config.responderGrant.grandParent = {order: 1};
734+
config.responderTerminationRequest.parent = {order: 2, returnVal: true};
735735
config.responderTerminate.parent = {order: 3};
736736
config.responderStart.grandParent = {order: 4};
737737
run(config, three, startConfig(three.child, [three.child, three.child], [1]));
@@ -899,10 +899,11 @@ describe('ResponderEventPlugin', function() {
899899
config.moveShouldSetResponder.captured.grandParent = {order: 0, returnVal: false};
900900
config.moveShouldSetResponder.captured.parent = {order: 1, returnVal: false};
901901
config.moveShouldSetResponder.bubbled.parent = {order: 2, returnVal: true};
902-
config.responderTerminationRequest.child = {order: 3, returnVal: false};
903-
config.responderReject.parent = {order: 4};
902+
config.responderGrant.parent = {order: 3};
903+
config.responderTerminationRequest.child = {order: 4, returnVal: false};
904+
config.responderReject.parent = {order: 5};
904905
// The start/move should occur on the original responder if new one is rejected
905-
config.responderMove.child = {order: 5};
906+
config.responderMove.child = {order: 6};
906907

907908
var touchConfig =
908909
moveConfig(three.child, [three.child], [0]);
@@ -913,10 +914,11 @@ describe('ResponderEventPlugin', function() {
913914
config.startShouldSetResponder.captured.grandParent = {order: 0, returnVal: false};
914915
config.startShouldSetResponder.captured.parent = {order: 1, returnVal: false};
915916
config.startShouldSetResponder.bubbled.parent = {order: 2, returnVal: true};
916-
config.responderTerminationRequest.child = {order: 3, returnVal: false};
917-
config.responderReject.parent = {order: 4};
917+
config.responderGrant.parent = {order: 3};
918+
config.responderTerminationRequest.child = {order: 4, returnVal: false};
919+
config.responderReject.parent = {order: 5};
918920
// The start/move should occur on the original responder if new one is rejected
919-
config.responderStart.child = {order: 5};
921+
config.responderStart.child = {order: 6};
920922

921923
touchConfig =
922924
startConfig(three.child, [three.child, three.child], [1]);
@@ -946,8 +948,9 @@ describe('ResponderEventPlugin', function() {
946948
config.scrollShouldSetResponder.captured.grandParent = {order: 0, returnVal: false};
947949
config.scrollShouldSetResponder.captured.parent = {order: 1, returnVal: false};
948950
config.scrollShouldSetResponder.bubbled.parent = {order: 2, returnVal: true};
949-
config.responderTerminationRequest.child = {order: 3, returnVal: false};
950-
config.responderReject.parent = {order: 4};
951+
config.responderGrant.parent = {order: 3};
952+
config.responderTerminationRequest.child = {order: 4, returnVal: false};
953+
config.responderReject.parent = {order: 5};
951954

952955
run(config, three, {
953956
topLevelType: topLevelTypes.topScroll,
@@ -962,8 +965,8 @@ describe('ResponderEventPlugin', function() {
962965
config.scrollShouldSetResponder.captured.grandParent = {order: 0, returnVal: false};
963966
config.scrollShouldSetResponder.captured.parent = {order: 1, returnVal: false};
964967
config.scrollShouldSetResponder.bubbled.parent = {order: 2, returnVal: true};
965-
config.responderTerminationRequest.child = {order: 3, returnVal: true};
966-
config.responderGrant.parent = {order: 4};
968+
config.responderGrant.parent = {order: 3};
969+
config.responderTerminationRequest.child = {order: 4, returnVal: true};
967970
config.responderTerminate.child = {order: 5};
968971

969972
run(config, three, {

0 commit comments

Comments
 (0)