Skip to content

Commit 2da536f

Browse files
authored
Revert "iOS platform view gesture blocking policy. (flutter#15940)"
This reverts commit e97dc01.
1 parent 86e8e50 commit 2da536f

File tree

13 files changed

+21
-437
lines changed

13 files changed

+21
-437
lines changed

shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -238,32 +238,6 @@ typedef void (*FlutterPluginRegistrantCallback)(NSObject<FlutterPluginRegistry>*
238238
- (void)detachFromEngineForRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar;
239239
@end
240240

241-
#pragma mark -
242-
/***************************************************************************************************
243-
* How the UIGestureRecognizers of a platform view are blocked.
244-
*
245-
* UIGestureRecognizers of platform views can be blocked based on decisions made by the
246-
* Flutter Framework (e.g. When an interact-able widget is covering the platform view).
247-
*/
248-
typedef enum {
249-
/**
250-
* Flutter blocks all the UIGestureRecognizers on the platform view as soon as it
251-
* decides they should be blocked.
252-
*
253-
* With this policy, only the `touchesBegan` method for all the UIGestureRecognizers is guaranteed
254-
* to be called.
255-
*/
256-
FlutterPlatformViewGestureRecognizersBlockingPolicyEager,
257-
/**
258-
* Flutter blocks the platform view's UIGestureRecognizers from recognizing only after
259-
* touchesEnded was invoked.
260-
*
261-
* This results in the platform view's UIGestureRecognizers seeing the entire touch sequence,
262-
* but never recognizing the gesture (and never invoking actions).
263-
*/
264-
FlutterPlatformViewGestureRecognizersBlockingPolicyWaitUntilTouchesEnded,
265-
} FlutterPlatformViewGestureRecognizersBlockingPolicy;
266-
267241
#pragma mark -
268242
/***************************************************************************************************
269243
*Registration context for a single `FlutterPlugin`, providing a one stop shop
@@ -303,23 +277,6 @@ typedef enum {
303277
- (void)registerViewFactory:(NSObject<FlutterPlatformViewFactory>*)factory
304278
withId:(NSString*)factoryId;
305279

306-
/**
307-
* Registers a `FlutterPlatformViewFactory` for creation of platform views.
308-
*
309-
* Plugins can expose a `UIView` for embedding in Flutter apps by registering a view factory.
310-
*
311-
* @param factory The view factory that will be registered.
312-
* @param factoryId A unique identifier for the factory, the Dart code of the Flutter app can use
313-
* this identifier to request creation of a `UIView` by the registered factory.
314-
* @param gestureBlockingPolicy How UIGestureRecognizers on the platform views are
315-
* blocked.
316-
*
317-
*/
318-
- (void)registerViewFactory:(NSObject<FlutterPlatformViewFactory>*)factory
319-
withId:(NSString*)factoryId
320-
gestureRecognizersBlockingPolicy:
321-
(FlutterPlatformViewGestureRecognizersBlockingPolicy)gestureRecognizersBlockingPolicy;
322-
323280
/**
324281
* Publishes a value for external use of the plugin.
325282
*

shell/platform/darwin/ios/framework/Source/FlutterEngine.mm

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -761,17 +761,7 @@ - (NSString*)lookupKeyForAsset:(NSString*)asset fromPackage:(NSString*)package {
761761

762762
- (void)registerViewFactory:(NSObject<FlutterPlatformViewFactory>*)factory
763763
withId:(NSString*)factoryId {
764-
[self registerViewFactory:factory
765-
withId:factoryId
766-
gestureRecognizersBlockingPolicy:FlutterPlatformViewGestureRecognizersBlockingPolicyEager];
767-
}
768-
769-
- (void)registerViewFactory:(NSObject<FlutterPlatformViewFactory>*)factory
770-
withId:(NSString*)factoryId
771-
gestureRecognizersBlockingPolicy:
772-
(FlutterPlatformViewGestureRecognizersBlockingPolicy)gestureRecognizersBlockingPolicy {
773-
[_flutterEngine platformViewsController] -> RegisterViewFactory(factory, factoryId,
774-
gestureRecognizersBlockingPolicy);
764+
[_flutterEngine platformViewsController] -> RegisterViewFactory(factory, factoryId);
775765
}
776766

777767
@end

shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm

Lines changed: 5 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,8 @@
8686
views_[viewId] = fml::scoped_nsobject<NSObject<FlutterPlatformView>>([embedded_view retain]);
8787

8888
FlutterTouchInterceptingView* touch_interceptor = [[[FlutterTouchInterceptingView alloc]
89-
initWithEmbeddedView:embedded_view.view
90-
flutterViewController:flutter_view_controller_.get()
91-
gestureRecognizersBlockingPolicy:gesture_recognizers_blocking_policies[viewType]]
92-
autorelease];
89+
initWithEmbeddedView:embedded_view.view
90+
flutterViewController:flutter_view_controller_.get()] autorelease];
9391

9492
touch_interceptors_[viewId] =
9593
fml::scoped_nsobject<FlutterTouchInterceptingView>([touch_interceptor retain]);
@@ -151,13 +149,11 @@
151149

152150
void FlutterPlatformViewsController::RegisterViewFactory(
153151
NSObject<FlutterPlatformViewFactory>* factory,
154-
NSString* factoryId,
155-
FlutterPlatformViewGestureRecognizersBlockingPolicy gestureRecognizerBlockingPolicy) {
152+
NSString* factoryId) {
156153
std::string idString([factoryId UTF8String]);
157154
FML_CHECK(factories_.count(idString) == 0);
158155
factories_[idString] =
159156
fml::scoped_nsobject<NSObject<FlutterPlatformViewFactory>>([factory retain]);
160-
gesture_recognizers_blocking_policies[idString] = gestureRecognizerBlockingPolicy;
161157
}
162158

163159
void FlutterPlatformViewsController::SetFrameSize(SkISize frame_size) {
@@ -517,15 +513,6 @@
517513
// invoking an acceptGesture method on the platform_views channel). And this is how we allow the
518514
// Flutter framework to delay or prevent the embedded view from getting a touch sequence.
519515
@interface DelayingGestureRecognizer : UIGestureRecognizer <UIGestureRecognizerDelegate>
520-
521-
// Indicates that if the `DelayingGestureRecognizer`'s state should be set to
522-
// `UIGestureRecognizerStateEnded` during next `touchesEnded` call.
523-
@property(nonatomic) bool shouldEndInNextTouchesEnded;
524-
525-
// Indicates that the `DelayingGestureRecognizer`'s `touchesEnded` has been invoked without
526-
// setting the state to `UIGestureRecognizerStateEnded`.
527-
@property(nonatomic) bool touchedEndedWithoutBlocking;
528-
529516
- (instancetype)initWithTarget:(id)target
530517
action:(SEL)action
531518
forwardingRecognizer:(UIGestureRecognizer*)forwardingRecognizer;
@@ -548,12 +535,9 @@ - (instancetype)initWithTarget:(id)target
548535

549536
@implementation FlutterTouchInterceptingView {
550537
fml::scoped_nsobject<DelayingGestureRecognizer> _delayingRecognizer;
551-
FlutterPlatformViewGestureRecognizersBlockingPolicy _blockingPolicy;
552538
}
553539
- (instancetype)initWithEmbeddedView:(UIView*)embeddedView
554-
flutterViewController:(UIViewController*)flutterViewController
555-
gestureRecognizersBlockingPolicy:
556-
(FlutterPlatformViewGestureRecognizersBlockingPolicy)blockingPolicy {
540+
flutterViewController:(UIViewController*)flutterViewController {
557541
self = [super initWithFrame:embeddedView.frame];
558542
if (self) {
559543
self.multipleTouchEnabled = YES;
@@ -570,7 +554,6 @@ - (instancetype)initWithEmbeddedView:(UIView*)embeddedView
570554
initWithTarget:self
571555
action:nil
572556
forwardingRecognizer:forwardingRecognizer]);
573-
_blockingPolicy = blockingPolicy;
574557

575558
[self addGestureRecognizer:_delayingRecognizer.get()];
576559
[self addGestureRecognizer:forwardingRecognizer];
@@ -583,27 +566,7 @@ - (void)releaseGesture {
583566
}
584567

585568
- (void)blockGesture {
586-
switch (_blockingPolicy) {
587-
case FlutterPlatformViewGestureRecognizersBlockingPolicyEager:
588-
// We block all other gesture recognizers immediately in this policy.
589-
_delayingRecognizer.get().state = UIGestureRecognizerStateEnded;
590-
break;
591-
case FlutterPlatformViewGestureRecognizersBlockingPolicyWaitUntilTouchesEnded:
592-
if (_delayingRecognizer.get().touchedEndedWithoutBlocking) {
593-
// If touchesEnded of the `DelayingGesureRecognizer` has been already invoked,
594-
// we want to set the state of the `DelayingGesureRecognizer` to
595-
// `UIGestureRecognizerStateEnded` as soon as possible.
596-
_delayingRecognizer.get().state = UIGestureRecognizerStateEnded;
597-
} else {
598-
// If touchesEnded of the `DelayingGesureRecognizer` has not been invoked,
599-
// We will set a flag to notify the `DelayingGesureRecognizer` to set the state to
600-
// `UIGestureRecognizerStateEnded` when touchesEnded is called.
601-
_delayingRecognizer.get().shouldEndInNextTouchesEnded = YES;
602-
}
603-
break;
604-
default:
605-
break;
606-
}
569+
_delayingRecognizer.get().state = UIGestureRecognizerStateEnded;
607570
}
608571

609572
// We want the intercepting view to consume the touches and not pass the touches up to the parent
@@ -633,10 +596,7 @@ - (instancetype)initWithTarget:(id)target
633596
self = [super initWithTarget:target action:action];
634597
if (self) {
635598
self.delaysTouchesBegan = YES;
636-
self.delaysTouchesEnded = YES;
637599
self.delegate = self;
638-
self.shouldEndInNextTouchesEnded = NO;
639-
self.touchedEndedWithoutBlocking = NO;
640600
_forwardingRecognizer.reset([forwardingRecognizer retain]);
641601
}
642602
return self;
@@ -654,21 +614,6 @@ - (BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer
654614
return otherGestureRecognizer == self;
655615
}
656616

657-
- (void)touchesBegan:(NSSet<UITouch*>*)touches withEvent:(UIEvent*)event {
658-
self.touchedEndedWithoutBlocking = NO;
659-
[super touchesBegan:touches withEvent:event];
660-
}
661-
662-
- (void)touchesEnded:(NSSet<UITouch*>*)touches withEvent:(UIEvent*)event {
663-
if (self.shouldEndInNextTouchesEnded) {
664-
self.state = UIGestureRecognizerStateEnded;
665-
self.shouldEndInNextTouchesEnded = NO;
666-
} else {
667-
self.touchedEndedWithoutBlocking = YES;
668-
}
669-
[super touchesEnded:touches withEvent:event];
670-
}
671-
672617
- (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event {
673618
self.state = UIGestureRecognizerStateFailed;
674619
}

shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "flutter/shell/platform/darwin/common/framework/Headers/FlutterBinaryMessenger.h"
1212
#include "flutter/shell/platform/darwin/common/framework/Headers/FlutterChannels.h"
1313
#include "flutter/shell/platform/darwin/ios/framework/Headers/FlutterPlatformViews.h"
14-
#include "flutter/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h"
1514

1615
// A UIView that is used as the parent for embedded UIViews.
1716
//
@@ -20,9 +19,7 @@
2019
// 2. Dispatching all events that are hittested to the embedded view to the FlutterView.
2120
@interface FlutterTouchInterceptingView : UIView
2221
- (instancetype)initWithEmbeddedView:(UIView*)embeddedView
23-
flutterViewController:(UIViewController*)flutterViewController
24-
gestureRecognizersBlockingPolicy:
25-
(FlutterPlatformViewGestureRecognizersBlockingPolicy)blockingPolicy;
22+
flutterViewController:(UIViewController*)flutterViewController;
2623

2724
// Stop delaying any active touch sequence (and let it arrive the embedded view).
2825
- (void)releaseGesture;
@@ -83,10 +80,7 @@ class FlutterPlatformViewsController {
8380

8481
void SetFlutterViewController(UIViewController* flutter_view_controller);
8582

86-
void RegisterViewFactory(
87-
NSObject<FlutterPlatformViewFactory>* factory,
88-
NSString* factoryId,
89-
FlutterPlatformViewGestureRecognizersBlockingPolicy gestureRecognizerBlockingPolicy);
83+
void RegisterViewFactory(NSObject<FlutterPlatformViewFactory>* factory, NSString* factoryId);
9084

9185
void SetFrameSize(SkISize frame_size);
9286

@@ -158,10 +152,6 @@ class FlutterPlatformViewsController {
158152
// Only compoiste platform views in this set.
159153
std::unordered_set<int64_t> views_to_recomposite_;
160154

161-
// The FlutterPlatformViewGestureRecognizersBlockingPolicy for each type of platform view.
162-
std::map<std::string, FlutterPlatformViewGestureRecognizersBlockingPolicy>
163-
gesture_recognizers_blocking_policies;
164-
165155
std::map<int64_t, std::unique_ptr<SkPictureRecorder>> picture_recorders_;
166156

167157
void OnCreate(FlutterMethodCall* call, FlutterResult& result);

testing/scenario_app/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java

Lines changed: 0 additions & 23 deletions
This file was deleted.

testing/scenario_app/ios/Runner/GeneratedPluginRegistrant.h

Lines changed: 0 additions & 17 deletions
This file was deleted.

testing/scenario_app/ios/Runner/GeneratedPluginRegistrant.m

Lines changed: 0 additions & 12 deletions
This file was deleted.

testing/scenario_app/ios/Scenarios/Scenarios.xcodeproj/project.pbxproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
6816DBAC2318696600A51400 /* golden_platform_view_opacity_iPhone SE_simulator.png in Resources */ = {isa = PBXBuildFile; fileRef = 6816DBA72318696600A51400 /* golden_platform_view_opacity_iPhone SE_simulator.png */; };
5151
6816DBAD2318696600A51400 /* golden_platform_view_cliprect_iPhone SE_simulator.png in Resources */ = {isa = PBXBuildFile; fileRef = 6816DBA82318696600A51400 /* golden_platform_view_cliprect_iPhone SE_simulator.png */; };
5252
6816DBAE2318696600A51400 /* golden_platform_view_cliprrect_iPhone SE_simulator.png in Resources */ = {isa = PBXBuildFile; fileRef = 6816DBA92318696600A51400 /* golden_platform_view_cliprrect_iPhone SE_simulator.png */; };
53-
68A5B63423EB71D300BDBCDB /* PlatformViewGestureRecognizerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 68A5B63323EB71D300BDBCDB /* PlatformViewGestureRecognizerTests.m */; };
5453
/* End PBXBuildFile section */
5554

5655
/* Begin PBXContainerItemProxy section */
@@ -157,7 +156,6 @@
157156
6816DBA72318696600A51400 /* golden_platform_view_opacity_iPhone SE_simulator.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "golden_platform_view_opacity_iPhone SE_simulator.png"; sourceTree = "<group>"; };
158157
6816DBA82318696600A51400 /* golden_platform_view_cliprect_iPhone SE_simulator.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "golden_platform_view_cliprect_iPhone SE_simulator.png"; sourceTree = "<group>"; };
159158
6816DBA92318696600A51400 /* golden_platform_view_cliprrect_iPhone SE_simulator.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "golden_platform_view_cliprrect_iPhone SE_simulator.png"; sourceTree = "<group>"; };
160-
68A5B63323EB71D300BDBCDB /* PlatformViewGestureRecognizerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PlatformViewGestureRecognizerTests.m; sourceTree = "<group>"; };
161159
/* End PBXFileReference section */
162160

163161
/* Begin PBXFrameworksBuildPhase section */
@@ -271,7 +269,6 @@
271269
6816DBA02317573300A51400 /* GoldenImage.m */,
272270
6816DBA22318358200A51400 /* PlatformViewGoldenTestManager.h */,
273271
6816DBA32318358200A51400 /* PlatformViewGoldenTestManager.m */,
274-
68A5B63323EB71D300BDBCDB /* PlatformViewGestureRecognizerTests.m */,
275272
);
276273
path = ScenariosUITests;
277274
sourceTree = "<group>";
@@ -461,7 +458,6 @@
461458
isa = PBXSourcesBuildPhase;
462459
buildActionMask = 2147483647;
463460
files = (
464-
68A5B63423EB71D300BDBCDB /* PlatformViewGestureRecognizerTests.m in Sources */,
465461
6816DBA12317573300A51400 /* GoldenImage.m in Sources */,
466462
6816DB9E231750ED00A51400 /* GoldenPlatformViewTests.m in Sources */,
467463
6816DBA42318358200A51400 /* PlatformViewGoldenTestManager.m in Sources */,

testing/scenario_app/ios/Scenarios/Scenarios/AppDelegate.m

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ - (BOOL)application:(UIApplication*)application
2525

2626
// This argument is used by the XCUITest for Platform Views so that the app
2727
// under test will create platform views.
28-
// If the test is one of the platform view golden tests,
29-
// the launchArgsMap should match the one in the `PlatformVieGoldenTestManager`.
28+
// The launchArgsMap should match the one in the `PlatformVieGoldenTestManager`.
3029
NSDictionary<NSString*, NSString*>* launchArgsMap = @{
3130
@"--platform-view" : @"platform_view",
3231
@"--platform-view-multiple" : @"platform_view_multiple",
@@ -38,21 +37,18 @@ - (BOOL)application:(UIApplication*)application
3837
@"--platform-view-transform" : @"platform_view_transform",
3938
@"--platform-view-opacity" : @"platform_view_opacity",
4039
@"--platform-view-rotate" : @"platform_view_rotate",
41-
@"--gesture-reject-after-touches-ended" : @"platform_view_gesture_reject_after_touches_ended",
42-
@"--gesture-reject-eager" : @"platform_view_gesture_reject_eager",
43-
@"--gesture-accept" : @"platform_view_gesture_accept",
4440
};
45-
__block NSString* platformViewTestName = nil;
41+
__block NSString* goldenTestName = nil;
4642
[launchArgsMap
4743
enumerateKeysAndObjectsUsingBlock:^(NSString* argument, NSString* testName, BOOL* stop) {
4844
if ([[[NSProcessInfo processInfo] arguments] containsObject:argument]) {
49-
platformViewTestName = testName;
45+
goldenTestName = testName;
5046
*stop = YES;
5147
}
5248
}];
5349

54-
if (platformViewTestName) {
55-
[self readyContextForPlatformViewTests:platformViewTestName];
50+
if (goldenTestName) {
51+
[self readyContextForPlatformViewTests:goldenTestName];
5652
} else if ([[[NSProcessInfo processInfo] arguments] containsObject:@"--screen-before-flutter"]) {
5753
self.window.rootViewController = [[ScreenBeforeFlutter alloc] initWithEngineRunCompletion:nil];
5854
} else {
@@ -80,13 +76,7 @@ - (void)readyContextForPlatformViewTests:(NSString*)scenarioIdentifier {
8076
[[TextPlatformViewFactory alloc] initWithMessenger:flutterViewController.binaryMessenger];
8177
NSObject<FlutterPluginRegistrar>* registrar =
8278
[flutterViewController.engine registrarForPlugin:@"scenarios/TextPlatformViewPlugin"];
83-
[registrar registerViewFactory:textPlatformViewFactory
84-
withId:@"scenarios/textPlatformView"
85-
gestureRecognizersBlockingPolicy:FlutterPlatformViewGestureRecognizersBlockingPolicyEager];
86-
[registrar registerViewFactory:textPlatformViewFactory
87-
withId:@"scenarios/textPlatformView_blockPolicyUntilTouchesEnded"
88-
gestureRecognizersBlockingPolicy:
89-
FlutterPlatformViewGestureRecognizersBlockingPolicyWaitUntilTouchesEnded];
79+
[registrar registerViewFactory:textPlatformViewFactory withId:@"scenarios/textPlatformView"];
9080
self.window.rootViewController = flutterViewController;
9181
}
9282

0 commit comments

Comments
 (0)