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
iOS platform view gesture blocking policy. #15940
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
53f0144
draft1
cda277d
remove not working testing code
c251e27
formatting
e9e8e90
renaming and commenting
c6bd198
review fixes
96f28c0
Merge branch 'master' into platform_view_gesture
9cf53c5
add first test
7b06bb3
add test file to xcode target
ef6f470
add tests for accept scenario
839c3f7
update comments
705a105
revert format on platform_view.dart
4df622a
typo
f262ca0
formatting
488f394
review fixes
6f67a00
review fixes
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
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
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 |
|---|---|---|
|
|
@@ -86,8 +86,10 @@ | |
| views_[viewId] = fml::scoped_nsobject<NSObject<FlutterPlatformView>>([embedded_view retain]); | ||
|
|
||
| FlutterTouchInterceptingView* touch_interceptor = [[[FlutterTouchInterceptingView alloc] | ||
| initWithEmbeddedView:embedded_view.view | ||
| flutterViewController:flutter_view_controller_.get()] autorelease]; | ||
| initWithEmbeddedView:embedded_view.view | ||
| flutterViewController:flutter_view_controller_.get() | ||
| gestureRecognizersBlockingPolicy:gesture_recognizers_blocking_policies[viewType]] | ||
| autorelease]; | ||
|
|
||
| touch_interceptors_[viewId] = | ||
| fml::scoped_nsobject<FlutterTouchInterceptingView>([touch_interceptor retain]); | ||
|
|
@@ -149,11 +151,13 @@ | |
|
|
||
| void FlutterPlatformViewsController::RegisterViewFactory( | ||
| NSObject<FlutterPlatformViewFactory>* factory, | ||
| NSString* factoryId) { | ||
| NSString* factoryId, | ||
| FlutterPlatformViewGestureRecognizersBlockingPolicy gestureRecognizerBlockingPolicy) { | ||
| std::string idString([factoryId UTF8String]); | ||
| FML_CHECK(factories_.count(idString) == 0); | ||
| factories_[idString] = | ||
| fml::scoped_nsobject<NSObject<FlutterPlatformViewFactory>>([factory retain]); | ||
| gesture_recognizers_blocking_policies[idString] = gestureRecognizerBlockingPolicy; | ||
| } | ||
|
|
||
| void FlutterPlatformViewsController::SetFrameSize(SkISize frame_size) { | ||
|
|
@@ -513,6 +517,15 @@ | |
| // invoking an acceptGesture method on the platform_views channel). And this is how we allow the | ||
| // Flutter framework to delay or prevent the embedded view from getting a touch sequence. | ||
| @interface DelayingGestureRecognizer : UIGestureRecognizer <UIGestureRecognizerDelegate> | ||
|
|
||
| // Indicates that if the `DelayingGestureRecognizer`'s state should be set to | ||
| // `UIGestureRecognizerStateEnded` during next `touchesEnded` call. | ||
| @property(nonatomic) bool shouldEndInNextTouchesEnded; | ||
|
|
||
| // Indicates that the `DelayingGestureRecognizer`'s `touchesEnded` has been invoked without | ||
| // setting the state to `UIGestureRecognizerStateEnded`. | ||
| @property(nonatomic) bool touchedEndedWithoutBlocking; | ||
|
|
||
| - (instancetype)initWithTarget:(id)target | ||
| action:(SEL)action | ||
| forwardingRecognizer:(UIGestureRecognizer*)forwardingRecognizer; | ||
|
|
@@ -535,9 +548,12 @@ - (instancetype)initWithTarget:(id)target | |
|
|
||
| @implementation FlutterTouchInterceptingView { | ||
| fml::scoped_nsobject<DelayingGestureRecognizer> _delayingRecognizer; | ||
| FlutterPlatformViewGestureRecognizersBlockingPolicy _blockingPolicy; | ||
| } | ||
| - (instancetype)initWithEmbeddedView:(UIView*)embeddedView | ||
| flutterViewController:(UIViewController*)flutterViewController { | ||
| flutterViewController:(UIViewController*)flutterViewController | ||
| gestureRecognizersBlockingPolicy: | ||
|
Contributor
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. is this the auto indentation?
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. Yes, indented by the formatter |
||
| (FlutterPlatformViewGestureRecognizersBlockingPolicy)blockingPolicy { | ||
| self = [super initWithFrame:embeddedView.frame]; | ||
| if (self) { | ||
| self.multipleTouchEnabled = YES; | ||
|
|
@@ -554,6 +570,7 @@ - (instancetype)initWithEmbeddedView:(UIView*)embeddedView | |
| initWithTarget:self | ||
| action:nil | ||
| forwardingRecognizer:forwardingRecognizer]); | ||
| _blockingPolicy = blockingPolicy; | ||
|
|
||
| [self addGestureRecognizer:_delayingRecognizer.get()]; | ||
| [self addGestureRecognizer:forwardingRecognizer]; | ||
|
|
@@ -566,7 +583,27 @@ - (void)releaseGesture { | |
| } | ||
|
|
||
| - (void)blockGesture { | ||
| _delayingRecognizer.get().state = UIGestureRecognizerStateEnded; | ||
| switch (_blockingPolicy) { | ||
| case FlutterPlatformViewGestureRecognizersBlockingPolicyEager: | ||
| // We block all other gesture recognizers immediately in this policy. | ||
| _delayingRecognizer.get().state = UIGestureRecognizerStateEnded; | ||
| break; | ||
| case FlutterPlatformViewGestureRecognizersBlockingPolicyWaitUntilTouchesEnded: | ||
| if (_delayingRecognizer.get().touchedEndedWithoutBlocking) { | ||
| // If touchesEnded of the `DelayingGesureRecognizer` has been already invoked, | ||
| // we want to set the state of the `DelayingGesureRecognizer` to | ||
| // `UIGestureRecognizerStateEnded` as soon as possible. | ||
| _delayingRecognizer.get().state = UIGestureRecognizerStateEnded; | ||
| } else { | ||
| // If touchesEnded of the `DelayingGesureRecognizer` has not been invoked, | ||
| // We will set a flag to notify the `DelayingGesureRecognizer` to set the state to | ||
| // `UIGestureRecognizerStateEnded` when touchesEnded is called. | ||
| _delayingRecognizer.get().shouldEndInNextTouchesEnded = YES; | ||
| } | ||
| break; | ||
| default: | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| // We want the intercepting view to consume the touches and not pass the touches up to the parent | ||
|
|
@@ -596,7 +633,10 @@ - (instancetype)initWithTarget:(id)target | |
| self = [super initWithTarget:target action:action]; | ||
| if (self) { | ||
| self.delaysTouchesBegan = YES; | ||
| self.delaysTouchesEnded = YES; | ||
| self.delegate = self; | ||
| self.shouldEndInNextTouchesEnded = NO; | ||
| self.touchedEndedWithoutBlocking = NO; | ||
| _forwardingRecognizer.reset([forwardingRecognizer retain]); | ||
| } | ||
| return self; | ||
|
|
@@ -614,6 +654,21 @@ - (BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer | |
| return otherGestureRecognizer == self; | ||
| } | ||
|
|
||
| - (void)touchesBegan:(NSSet<UITouch*>*)touches withEvent:(UIEvent*)event { | ||
| self.touchedEndedWithoutBlocking = NO; | ||
| [super touchesBegan:touches withEvent:event]; | ||
| } | ||
|
|
||
| - (void)touchesEnded:(NSSet<UITouch*>*)touches withEvent:(UIEvent*)event { | ||
| if (self.shouldEndInNextTouchesEnded) { | ||
| self.state = UIGestureRecognizerStateEnded; | ||
| self.shouldEndInNextTouchesEnded = NO; | ||
| } else { | ||
| self.touchedEndedWithoutBlocking = YES; | ||
| } | ||
| [super touchesEnded:touches withEvent:event]; | ||
| } | ||
|
|
||
| - (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event { | ||
| self.state = UIGestureRecognizerStateFailed; | ||
| } | ||
|
|
||
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
23 changes: 23 additions & 0 deletions
23
.../scenario_app/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java
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 |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package io.flutter.plugins; | ||
|
|
||
| import io.flutter.plugin.common.PluginRegistry; | ||
|
|
||
| /** | ||
| * Generated file. Do not edit. | ||
| */ | ||
| public final class GeneratedPluginRegistrant { | ||
| public static void registerWith(PluginRegistry registry) { | ||
| if (alreadyRegisteredWith(registry)) { | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| private static boolean alreadyRegisteredWith(PluginRegistry registry) { | ||
| final String key = GeneratedPluginRegistrant.class.getCanonicalName(); | ||
| if (registry.hasPlugin(key)) { | ||
| return true; | ||
| } | ||
| registry.registrarFor(key); | ||
| return false; | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
testing/scenario_app/ios/Runner/GeneratedPluginRegistrant.h
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 |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // | ||
| // Generated file. Do not edit. | ||
| // | ||
|
|
||
| #ifndef GeneratedPluginRegistrant_h | ||
| #define GeneratedPluginRegistrant_h | ||
|
|
||
| #import <Flutter/Flutter.h> | ||
|
|
||
| NS_ASSUME_NONNULL_BEGIN | ||
|
|
||
| @interface GeneratedPluginRegistrant : NSObject | ||
| + (void)registerWithRegistry:(NSObject<FlutterPluginRegistry>*)registry; | ||
| @end | ||
|
|
||
| NS_ASSUME_NONNULL_END | ||
| #endif /* GeneratedPluginRegistrant_h */ |
12 changes: 12 additions & 0 deletions
12
testing/scenario_app/ios/Runner/GeneratedPluginRegistrant.m
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 |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // | ||
| // Generated file. Do not edit. | ||
| // | ||
|
|
||
| #import "GeneratedPluginRegistrant.h" | ||
|
|
||
| @implementation GeneratedPluginRegistrant | ||
|
|
||
| + (void)registerWithRegistry:(NSObject<FlutterPluginRegistry>*)registry { | ||
| } | ||
|
|
||
| @end |
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
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
Oops, something went wrong.
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.
typos: framework, policy, implemented,
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.
done