From 8f8a95e0c7b4e595751ec25d67b488edd09179b3 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Mon, 4 Mar 2019 12:55:23 -0800 Subject: [PATCH 1/4] fix touch assertion throw issue --- .../framework/Source/FlutterPlatformViews.mm | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm index 3452807bcdeb5..d3146851fe805 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm @@ -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*)touches withEvent:(UIEvent*)event { +} + +- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event { +} + +- (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event { +} + +- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event { +} + @end @implementation DelayingGestureRecognizer { @@ -395,19 +410,23 @@ @implementation ForwardingGestureRecognizer { // So this is safe as when FlutterView is deallocated the reference to ForwardingGestureRecognizer // will go away. UIView* _flutterView; + NSInteger _currentEventTouchCount; } - (instancetype)initWithTarget:(id)target flutterView:(UIView*)flutterView { self = [super initWithTarget:target action:nil]; if (self) { self.delegate = self; - _flutterView = flutterView; + _flutterView = flutterView;ng how many touches have begun for one touch sequence. + _currentEventTouchCount = 0; } return self; } - (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event { [_flutterView touchesBegan:touches withEvent:event]; + _currentEventTouchCount += touches.count; + [_flutterView touchesBegan:touches withEvent:event]; } - (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event { @@ -416,11 +435,19 @@ - (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event { - (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event { [_flutterView touchesEnded:touches withEvent:event]; - self.state = UIGestureRecognizerStateFailed; + _currentEventTouchCount -= 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 (_currentEventTouchCount == 0) { + self.state = UIGestureRecognizerStateFailed; + } } - (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event { [_flutterView touchesCancelled:touches withEvent:event]; + _currentEventTouchCount = 0; self.state = UIGestureRecognizerStateFailed; } From 6a5dfa6dc1323e48134d0781d53b5cae41727487 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Mon, 4 Mar 2019 13:10:40 -0800 Subject: [PATCH 2/4] formatting --- .../darwin/ios/framework/Source/FlutterPlatformViews.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm index d3146851fe805..a594f9bdaea50 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm @@ -417,8 +417,8 @@ - (instancetype)initWithTarget:(id)target flutterView:(UIView*)flutterView { self = [super initWithTarget:target action:nil]; if (self) { self.delegate = self; - _flutterView = flutterView;ng how many touches have begun for one touch sequence. - _currentEventTouchCount = 0; + _flutterView = flutterView; + _currentEventTouchCount = 0; } return self; } From d3afd9ea2690f87169a75f1c6bd0a5c58b046285 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Mon, 4 Mar 2019 13:11:49 -0800 Subject: [PATCH 3/4] add comments for the counter --- .../platform/darwin/ios/framework/Source/FlutterPlatformViews.mm | 1 + 1 file changed, 1 insertion(+) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm index a594f9bdaea50..e878abcffaa3e 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm @@ -410,6 +410,7 @@ @implementation ForwardingGestureRecognizer { // So this is safe as when FlutterView is deallocated the reference to ForwardingGestureRecognizer // will go away. UIView* _flutterView; + // Counting the touches that has started in one touch sequence. NSInteger _currentEventTouchCount; } From 7e47b87cabc0be53582dd45ae5f888592241e835 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Mon, 4 Mar 2019 13:33:57 -0800 Subject: [PATCH 4/4] review fixes --- .../ios/framework/Source/FlutterPlatformViews.mm | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm index e878abcffaa3e..2bd198af6bf12 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm @@ -410,8 +410,8 @@ @implementation ForwardingGestureRecognizer { // So this is safe as when FlutterView is deallocated the reference to ForwardingGestureRecognizer // will go away. UIView* _flutterView; - // Counting the touches that has started in one touch sequence. - NSInteger _currentEventTouchCount; + // Counting the pointers that has started in one touch sequence. + NSInteger _currentTouchPointersCount; } - (instancetype)initWithTarget:(id)target flutterView:(UIView*)flutterView { @@ -419,14 +419,14 @@ - (instancetype)initWithTarget:(id)target flutterView:(UIView*)flutterView { if (self) { self.delegate = self; _flutterView = flutterView; - _currentEventTouchCount = 0; + _currentTouchPointersCount = 0; } return self; } - (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event { [_flutterView touchesBegan:touches withEvent:event]; - _currentEventTouchCount += touches.count; + _currentTouchPointersCount += touches.count; [_flutterView touchesBegan:touches withEvent:event]; } @@ -436,19 +436,19 @@ - (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event { - (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event { [_flutterView touchesEnded:touches withEvent:event]; - _currentEventTouchCount -= touches.count; + _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 (_currentEventTouchCount == 0) { + if (_currentTouchPointersCount == 0) { self.state = UIGestureRecognizerStateFailed; } } - (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event { [_flutterView touchesCancelled:touches withEvent:event]; - _currentEventTouchCount = 0; + _currentTouchPointersCount = 0; self.state = UIGestureRecognizerStateFailed; }