Import ResponderEventPlugin changes from RN
Ben Alpert committed
Oct 28, 2015 at 12:52 UTC
bb11639e25461a61d65af06308152dd7892cafa2
2 files changed
+29
-20
src/renderers/shared/event/eventPlugins/ResponderEventPlugin.js
+14
-8
@@ -46,13 +46,14 @@ var trackedTouchCount = 0;
46
*/
47
var previousActiveTouches = 0;
48
49
-var changeResponder = function(nextResponderInst) {
49
+var changeResponder = function(nextResponderInst, blockNativeResponder) {
50
var oldResponderInst = responderInst;
51
responderInst = nextResponderInst;
52
if (ResponderEventPlugin.GlobalResponderHandler !== null) {
53
ResponderEventPlugin.GlobalResponderHandler.onChange(
54
oldResponderInst,
55
- nextResponderInst
55
+ nextResponderInst,
56
+ blockNativeResponder
57
);
58
}
59
};
@@ -370,6 +371,7 @@ function setResponderAndExtractTransfer(
371
grantEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
372
373
EventPropagators.accumulateDirectDispatches(grantEvent);
374
+ var blockNativeResponder = executeDirectDispatch(grantEvent) === true;
375
if (responderInst) {
376
377
var terminationRequestEvent = ResponderSyntheticEvent.getPooled(
@@ -396,7 +398,7 @@ function setResponderAndExtractTransfer(
398
terminateEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
399
EventPropagators.accumulateDirectDispatches(terminateEvent);
400
extracted = accumulate(extracted, [grantEvent, terminateEvent]);
399
- changeResponder(wantsResponderInst);
401
+ changeResponder(wantsResponderInst, blockNativeResponder);
402
} else {
403
var rejectEvent = ResponderSyntheticEvent.getPooled(
404
eventTypes.responderReject,
@@ -410,7 +412,7 @@ function setResponderAndExtractTransfer(
412
}
413
} else {
414
extracted = accumulate(extracted, grantEvent);
413
- changeResponder(wantsResponderInst);
415
+ changeResponder(wantsResponderInst, blockNativeResponder);
416
}
417
return extracted;
418
}
@@ -423,9 +425,13 @@ function setResponderAndExtractTransfer(
425
* @param {string} topLevelType Record from `EventConstants`.
426
* @return {boolean} True if a transfer of responder could possibly occur.
427
*/
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) ||
435
(trackedTouchCount > 0 &&
436
topLevelType === EventConstants.topLevelTypes.topSelectionChange) ||
437
isStartish(topLevelType) ||
@@ -492,7 +498,7 @@ var ResponderEventPlugin = {
498
499
ResponderTouchHistoryStore.recordTouchTrack(topLevelType, nativeEvent, nativeEventTarget);
500
495
- var extracted = canTriggerTransfer(topLevelType, targetInst) ?
501
+ var extracted = canTriggerTransfer(topLevelType, targetInst, nativeEvent) ?
502
setResponderAndExtractTransfer(
503
topLevelType,
504
targetInst,
src/renderers/shared/event/eventPlugins/__tests__/ResponderEventPlugin-test.js
+15
-12
@@ -730,8 +730,8 @@ describe('ResponderEventPlugin', function() {
730
731
// Parent is responder, and responder is transferred by a second touch start
732
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};
735
config.responderTerminate.parent = {order: 3};
736
config.responderStart.grandParent = {order: 4};
737
run(config, three, startConfig(three.child, [three.child, three.child], [1]));
@@ -899,10 +899,11 @@ describe('ResponderEventPlugin', function() {
899
config.moveShouldSetResponder.captured.grandParent = {order: 0, returnVal: false};
900
config.moveShouldSetResponder.captured.parent = {order: 1, returnVal: false};
901
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};
905
// 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};
907
908
var touchConfig =
909
moveConfig(three.child, [three.child], [0]);
@@ -913,10 +914,11 @@ describe('ResponderEventPlugin', function() {
914
config.startShouldSetResponder.captured.grandParent = {order: 0, returnVal: false};
915
config.startShouldSetResponder.captured.parent = {order: 1, returnVal: false};
916
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};
920
// 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};
922
923
touchConfig =
924
startConfig(three.child, [three.child, three.child], [1]);
@@ -946,8 +948,9 @@ describe('ResponderEventPlugin', function() {
948
config.scrollShouldSetResponder.captured.grandParent = {order: 0, returnVal: false};
949
config.scrollShouldSetResponder.captured.parent = {order: 1, returnVal: false};
950
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};
954
955
run(config, three, {
956
topLevelType: topLevelTypes.topScroll,
@@ -962,8 +965,8 @@ describe('ResponderEventPlugin', function() {
965
config.scrollShouldSetResponder.captured.grandParent = {order: 0, returnVal: false};
966
config.scrollShouldSetResponder.captured.parent = {order: 1, returnVal: false};
967
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};
970
config.responderTerminate.child = {order: 5};
971
972
run(config, three, {