Skip to content

Commit

Permalink
fixed coalescing key generation for RCTTouchEvent
Browse files Browse the repository at this point in the history
Summary:Turns our using the same coalescing key until a person removes all fingers off screen is not ideal.
It doesn't work in a case where the first finger starts moving on screen and then a second finger joins it later (almost any pinch gesture),
since we would try to coalesce move events from the start when only one finger was touching screen with events where two fingers were moving on screen.
That doesn't work and results in a crash.

I've changed the logic for generating the coalescing key in order to prevent this.
We no longer have a single key for a single gesture, but we change the key each time amount of fingers increases ("touchStart") or decreases ("touchEnd").

Reviewed By: javache

Differential Revision: D3138275

fb-gh-sync-id: c32230ba401819fe3a70d1752b286d849520be89
fbshipit-source-id: c32230ba401819fe3a70d1752b286d849520be89
  • Loading branch information
majak authored and Facebook Github Bot 4 committed Apr 5, 2016
1 parent a10c1b5 commit 8efc098
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion React/Base/RCTTouchHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ - (void)handleGestureUpdate:(__unused UIGestureRecognizer *)gesture
{
// If gesture just recognized, send all touches to JS as if they just began.
if (self.state == UIGestureRecognizerStateBegan) {
_coalescingKey++;
[self _updateAndDispatchTouches:_nativeTouches.set eventName:@"topTouchStart" originatingTime:0];

// We store this flag separately from `state` because after a gesture is
Expand All @@ -253,6 +252,7 @@ - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
[super touchesBegan:touches withEvent:event];

_coalescingKey++;
// "start" has to record new touches before extracting the event.
// "end"/"cancel" needs to remove the touch *after* extracting the event.
[self _recordNewTouches:touches];
Expand All @@ -278,6 +278,7 @@ - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
[super touchesEnded:touches withEvent:event];

_coalescingKey++;
if (_dispatchedInitialTouches) {
[self _updateAndDispatchTouches:touches eventName:@"touchEnd" originatingTime:event.timestamp];

Expand Down

0 comments on commit 8efc098

Please sign in to comment.