Skip to content

Commit

Permalink
Merge pull request #5308 from spicyj/rep
Browse files Browse the repository at this point in the history
Import ResponderEventPlugin changes from RN
  • Loading branch information
sophiebits committed Dec 22, 2015
2 parents 89a0ef4 + bb11639 commit bae0f19
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
22 changes: 14 additions & 8 deletions src/renderers/shared/event/eventPlugins/ResponderEventPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@ var trackedTouchCount = 0;
*/
var previousActiveTouches = 0;

var changeResponder = function(nextResponderInst) {
var changeResponder = function(nextResponderInst, blockNativeResponder) {
var oldResponderInst = responderInst;
responderInst = nextResponderInst;
if (ResponderEventPlugin.GlobalResponderHandler !== null) {
ResponderEventPlugin.GlobalResponderHandler.onChange(
oldResponderInst,
nextResponderInst
nextResponderInst,
blockNativeResponder
);
}
};
Expand Down Expand Up @@ -370,6 +371,7 @@ function setResponderAndExtractTransfer(
grantEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;

EventPropagators.accumulateDirectDispatches(grantEvent);
var blockNativeResponder = executeDirectDispatch(grantEvent) === true;
if (responderInst) {

var terminationRequestEvent = ResponderSyntheticEvent.getPooled(
Expand All @@ -396,7 +398,7 @@ function setResponderAndExtractTransfer(
terminateEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
EventPropagators.accumulateDirectDispatches(terminateEvent);
extracted = accumulate(extracted, [grantEvent, terminateEvent]);
changeResponder(wantsResponderInst);
changeResponder(wantsResponderInst, blockNativeResponder);
} else {
var rejectEvent = ResponderSyntheticEvent.getPooled(
eventTypes.responderReject,
Expand All @@ -410,7 +412,7 @@ function setResponderAndExtractTransfer(
}
} else {
extracted = accumulate(extracted, grantEvent);
changeResponder(wantsResponderInst);
changeResponder(wantsResponderInst, blockNativeResponder);
}
return extracted;
}
Expand All @@ -423,9 +425,13 @@ function setResponderAndExtractTransfer(
* @param {string} topLevelType Record from `EventConstants`.
* @return {boolean} True if a transfer of responder could possibly occur.
*/
function canTriggerTransfer(topLevelType, targetInst) {
return !!targetInst && (
topLevelType === EventConstants.topLevelTypes.topScroll ||
function canTriggerTransfer(topLevelType, topLevelInst, nativeEvent) {
return topLevelInst && (
// 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 === EventConstants.topLevelTypes.topScroll &&
!nativeEvent.responderIgnoreScroll) ||
(trackedTouchCount > 0 &&
topLevelType === EventConstants.topLevelTypes.topSelectionChange) ||
isStartish(topLevelType) ||
Expand Down Expand Up @@ -492,7 +498,7 @@ var ResponderEventPlugin = {

ResponderTouchHistoryStore.recordTouchTrack(topLevelType, nativeEvent, nativeEventTarget);

var extracted = canTriggerTransfer(topLevelType, targetInst) ?
var extracted = canTriggerTransfer(topLevelType, targetInst, nativeEvent) ?
setResponderAndExtractTransfer(
topLevelType,
targetInst,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -730,8 +730,8 @@ describe('ResponderEventPlugin', function() {

// Parent is responder, and responder is transferred by a second touch start
config.startShouldSetResponder.captured.grandParent = {order: 0, returnVal: true};
config.responderTerminationRequest.parent = {order: 1, returnVal: true};
config.responderGrant.grandParent = {order: 2};
config.responderGrant.grandParent = {order: 1};
config.responderTerminationRequest.parent = {order: 2, returnVal: true};
config.responderTerminate.parent = {order: 3};
config.responderStart.grandParent = {order: 4};
run(config, three, startConfig(three.child, [three.child, three.child], [1]));
Expand Down Expand Up @@ -899,10 +899,11 @@ describe('ResponderEventPlugin', function() {
config.moveShouldSetResponder.captured.grandParent = {order: 0, returnVal: false};
config.moveShouldSetResponder.captured.parent = {order: 1, returnVal: false};
config.moveShouldSetResponder.bubbled.parent = {order: 2, returnVal: true};
config.responderTerminationRequest.child = {order: 3, returnVal: false};
config.responderReject.parent = {order: 4};
config.responderGrant.parent = {order: 3};
config.responderTerminationRequest.child = {order: 4, returnVal: false};
config.responderReject.parent = {order: 5};
// The start/move should occur on the original responder if new one is rejected
config.responderMove.child = {order: 5};
config.responderMove.child = {order: 6};

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

touchConfig =
startConfig(three.child, [three.child, three.child], [1]);
Expand Down Expand Up @@ -946,8 +948,9 @@ describe('ResponderEventPlugin', function() {
config.scrollShouldSetResponder.captured.grandParent = {order: 0, returnVal: false};
config.scrollShouldSetResponder.captured.parent = {order: 1, returnVal: false};
config.scrollShouldSetResponder.bubbled.parent = {order: 2, returnVal: true};
config.responderTerminationRequest.child = {order: 3, returnVal: false};
config.responderReject.parent = {order: 4};
config.responderGrant.parent = {order: 3};
config.responderTerminationRequest.child = {order: 4, returnVal: false};
config.responderReject.parent = {order: 5};

run(config, three, {
topLevelType: topLevelTypes.topScroll,
Expand All @@ -962,8 +965,8 @@ describe('ResponderEventPlugin', function() {
config.scrollShouldSetResponder.captured.grandParent = {order: 0, returnVal: false};
config.scrollShouldSetResponder.captured.parent = {order: 1, returnVal: false};
config.scrollShouldSetResponder.bubbled.parent = {order: 2, returnVal: true};
config.responderTerminationRequest.child = {order: 3, returnVal: true};
config.responderGrant.parent = {order: 4};
config.responderGrant.parent = {order: 3};
config.responderTerminationRequest.child = {order: 4, returnVal: true};
config.responderTerminate.child = {order: 5};

run(config, three, {
Expand Down

0 comments on commit bae0f19

Please sign in to comment.