This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
PlatformViewsController always make sure the touch events are finished #22406
Merged
+212
−6
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
87ba06a
Let touch events go through
dd80223
format
183fc62
Merge branch 'master' into gesture
c1529b3
review
d6433a3
only update flutter view controller if the touchBegan starts a new se…
48472f4
add comments
366196d
review
b096e04
review
fc7d934
format
b349a69
review
9ee26e3
remove platformviewstest reference in xcode
6f067c2
Merge branch 'master' into gesture
f93bc21
rebase test code
bca3d18
fix the previous rebase
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -871,6 +871,11 @@ @implementation ForwardingGestureRecognizer { | |
| fml::WeakPtr<flutter::FlutterPlatformViewsController> _platformViewsController; | ||
| // Counting the pointers that has started in one touch sequence. | ||
| NSInteger _currentTouchPointersCount; | ||
| // We can't dispatch events to the framework without this back pointer. | ||
| // This gesture recognizer retains the `FlutterViewController` until the | ||
| // end of a gesture sequence, that is all the touches in touchesBegan are concluded | ||
| // with |touchesCancelled| or |touchesEnded|. | ||
| fml::scoped_nsobject<UIViewController> _flutterViewController; | ||
| } | ||
|
|
||
| - (instancetype)initWithTarget:(id)target | ||
|
|
@@ -887,30 +892,41 @@ - (instancetype)initWithTarget:(id)target | |
| } | ||
|
|
||
| - (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event { | ||
| [_platformViewsController->getFlutterViewController() touchesBegan:touches withEvent:event]; | ||
| FML_DCHECK(_currentTouchPointersCount >= 0); | ||
| if (_currentTouchPointersCount == 0) { | ||
| // At the start of each gesture sequence, we reset the `_flutterViewController`, | ||
| // so that all the touch events in the same sequence are forwarded to the same | ||
| // `_flutterViewController`. | ||
| _flutterViewController.reset([_platformViewsController->getFlutterViewController() retain]); | ||
| } | ||
| [_flutterViewController.get() touchesBegan:touches withEvent:event]; | ||
| _currentTouchPointersCount += touches.count; | ||
| } | ||
|
|
||
| - (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event { | ||
| [_platformViewsController->getFlutterViewController() touchesMoved:touches withEvent:event]; | ||
| [_flutterViewController.get() touchesMoved:touches withEvent:event]; | ||
| } | ||
|
|
||
| - (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event { | ||
| [_platformViewsController->getFlutterViewController() touchesEnded:touches withEvent:event]; | ||
| [_flutterViewController.get() touchesEnded:touches withEvent:event]; | ||
| _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; | ||
| _flutterViewController.reset(nil); | ||
| } | ||
| } | ||
|
|
||
| - (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event { | ||
| [_platformViewsController->getFlutterViewController() touchesCancelled:touches withEvent:event]; | ||
| _currentTouchPointersCount = 0; | ||
| self.state = UIGestureRecognizerStateFailed; | ||
| [_flutterViewController.get() touchesCancelled:touches withEvent:event]; | ||
| _currentTouchPointersCount -= touches.count; | ||
| if (_currentTouchPointersCount == 0) { | ||
| self.state = UIGestureRecognizerStateFailed; | ||
| _flutterViewController.reset(nil); | ||
| } | ||
|
Comment on lines
+924
to
+929
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the case where we get Begin-Begin-Cancel-End the state will no longer be Failed like it was previously, is that expected?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Begin-Begin-Cancel-End makes the count to 0 at the last End, so it state would still be failed. |
||
| } | ||
|
|
||
| - (BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the implication of not incrementing this counter if we have no VC?
Should we be setting to zero in the early return above?