Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[platform_views] Fix duplicated touch event pass down to flutter view from platform view. #8026

Merged
merged 4 commits into from
Mar 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,21 @@ - (void)blockGesture {
_delayingRecognizer.get().state = UIGestureRecognizerStateEnded;
}

// We want the intercepting view to consume the touches and not pass the touches up to the parent
// view. Make the touch event method not call super will not pass the touches up to the parent view.
// Hence we overide the touch event methods and do nothing.
- (void)touchesBegan:(NSSet<UITouch*>*)touches withEvent:(UIEvent*)event {
}

- (void)touchesMoved:(NSSet<UITouch*>*)touches withEvent:(UIEvent*)event {
}

- (void)touchesCancelled:(NSSet<UITouch*>*)touches withEvent:(UIEvent*)event {
}

- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event {
}

@end

@implementation DelayingGestureRecognizer {
Expand Down Expand Up @@ -395,19 +410,24 @@ @implementation ForwardingGestureRecognizer {
// So this is safe as when FlutterView is deallocated the reference to ForwardingGestureRecognizer
// will go away.
UIView* _flutterView;
// Counting the pointers that has started in one touch sequence.
NSInteger _currentTouchPointersCount;
}

- (instancetype)initWithTarget:(id)target flutterView:(UIView*)flutterView {
self = [super initWithTarget:target action:nil];
if (self) {
self.delegate = self;
_flutterView = flutterView;
_currentTouchPointersCount = 0;
}
return self;
}

- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
[_flutterView touchesBegan:touches withEvent:event];
_currentTouchPointersCount += touches.count;
[_flutterView touchesBegan:touches withEvent:event];
}

- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {
Expand All @@ -416,11 +436,19 @@ - (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {

- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event {
[_flutterView touchesEnded:touches withEvent:event];
self.state = UIGestureRecognizerStateFailed;
_currentTouchPointersCount -= touches.count;
// Touches in one touch sequence are sent to the touchesEnded method separately if different
// fingers stop touching the screen at different time. So one touchesEnded method triggering does
// not necessarially mean the touch sequence has ended. We Only set the state to
// UIGestureRecognizerStateFailed when all the touches in the current touch sequence is ended.
if (_currentTouchPointersCount == 0) {
self.state = UIGestureRecognizerStateFailed;
}
}

- (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event {
[_flutterView touchesCancelled:touches withEvent:event];
_currentTouchPointersCount = 0;
self.state = UIGestureRecognizerStateFailed;
}

Expand Down