diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.mm index 76d81013dc..8000df2830 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.mm @@ -42,7 +42,7 @@ FLUTTER_ASSERT_ARC pixelFormat:(MTLPixelFormat)pixelFormat { self = [self init]; - if ([self.layer isKindOfClass:NSClassFromString(@"CAMetalLayer")]) { + if ([self.layer isKindOfClass:[CAMetalLayer class]]) { self.layer.allowsGroupOpacity = NO; self.layer.contentsScale = contentsScale; self.layer.rasterizationScale = contentsScale; diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm index 16f5fa59be..d6f52eddf9 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm @@ -2458,7 +2458,7 @@ fml::RefPtr GetDefaultTaskRunner() { // Find ForwardGestureRecognizer UIGestureRecognizer* forwardGectureRecognizer = nil; for (UIGestureRecognizer* gestureRecognizer in touchInteceptorView.gestureRecognizers) { - if ([gestureRecognizer isKindOfClass:NSClassFromString(@"ForwardingGestureRecognizer")]) { + if ([gestureRecognizer isKindOfClass:[ForwardingGestureRecognizer class]]) { forwardGectureRecognizer = gestureRecognizer; break; } @@ -2525,7 +2525,7 @@ fml::RefPtr GetDefaultTaskRunner() { // Find ForwardGestureRecognizer UIGestureRecognizer* forwardGectureRecognizer = nil; for (UIGestureRecognizer* gestureRecognizer in touchInteceptorView.gestureRecognizers) { - if ([gestureRecognizer isKindOfClass:NSClassFromString(@"ForwardingGestureRecognizer")]) { + if ([gestureRecognizer isKindOfClass:[ForwardingGestureRecognizer class]]) { forwardGectureRecognizer = gestureRecognizer; break; } @@ -2649,7 +2649,7 @@ fml::RefPtr GetDefaultTaskRunner() { // Find ForwardGestureRecognizer UIGestureRecognizer* forwardGectureRecognizer = nil; for (UIGestureRecognizer* gestureRecognizer in touchInteceptorView.gestureRecognizers) { - if ([gestureRecognizer isKindOfClass:NSClassFromString(@"ForwardingGestureRecognizer")]) { + if ([gestureRecognizer isKindOfClass:[ForwardingGestureRecognizer class]]) { forwardGectureRecognizer = gestureRecognizer; break; } @@ -2763,7 +2763,7 @@ fml::RefPtr GetDefaultTaskRunner() { // Find ForwardGestureRecognizer UIGestureRecognizer* forwardGectureRecognizer = nil; for (UIGestureRecognizer* gestureRecognizer in touchInteceptorView.gestureRecognizers) { - if ([gestureRecognizer isKindOfClass:NSClassFromString(@"ForwardingGestureRecognizer")]) { + if ([gestureRecognizer isKindOfClass:[ForwardingGestureRecognizer class]]) { forwardGectureRecognizer = gestureRecognizer; break; } @@ -2828,7 +2828,7 @@ fml::RefPtr GetDefaultTaskRunner() { // Find ForwardGestureRecognizer __block UIGestureRecognizer* forwardGestureRecognizer = nil; for (UIGestureRecognizer* gestureRecognizer in touchInteceptorView.gestureRecognizers) { - if ([gestureRecognizer isKindOfClass:NSClassFromString(@"ForwardingGestureRecognizer")]) { + if ([gestureRecognizer isKindOfClass:[ForwardingGestureRecognizer class]]) { forwardGestureRecognizer = gestureRecognizer; break; } @@ -2851,7 +2851,7 @@ fml::RefPtr GetDefaultTaskRunner() { dispatch_async(dispatch_get_main_queue(), ^{ // Re-query forward gesture recognizer since it's recreated. for (UIGestureRecognizer* gestureRecognizer in touchInteceptorView.gestureRecognizers) { - if ([gestureRecognizer isKindOfClass:NSClassFromString(@"ForwardingGestureRecognizer")]) { + if ([gestureRecognizer isKindOfClass:[ForwardingGestureRecognizer class]]) { forwardGestureRecognizer = gestureRecognizer; break; } @@ -2873,7 +2873,7 @@ fml::RefPtr GetDefaultTaskRunner() { dispatch_async(dispatch_get_main_queue(), ^{ // Re-query forward gesture recognizer since it's recreated. for (UIGestureRecognizer* gestureRecognizer in touchInteceptorView.gestureRecognizers) { - if ([gestureRecognizer isKindOfClass:NSClassFromString(@"ForwardingGestureRecognizer")]) { + if ([gestureRecognizer isKindOfClass:[ForwardingGestureRecognizer class]]) { forwardGestureRecognizer = gestureRecognizer; break; } diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h index 7a611d86a4..8267b1ccfe 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h @@ -21,8 +21,6 @@ #import "flutter/shell/platform/darwin/ios/framework/Source/platform_views_controller.h" #import "flutter/shell/platform/darwin/ios/ios_context.h" -@class FlutterTouchInterceptingView; - // A UIView that acts as a clipping mask for the |ChildClippingView|. // // On the [UIView drawRect:] method, this view performs a series of clipping operations and sets the @@ -159,4 +157,44 @@ @property(nonatomic, readonly) BOOL flt_hasFirstResponderInViewHierarchySubtree; @end +// This recognizer delays touch events from being dispatched to the responder chain until it failed +// recognizing a gesture. +// +// We only fail this recognizer when asked to do so by the Flutter framework (which does so by +// 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 FlutterDelayingGestureRecognizer : UIGestureRecognizer + +// Indicates that if the `FlutterDelayingGestureRecognizer`'s state should be set to +// `UIGestureRecognizerStateEnded` during next `touchesEnded` call. +@property(nonatomic) BOOL shouldEndInNextTouchesEnded; + +// Indicates that the `FlutterDelayingGestureRecognizer`'s `touchesEnded` has been invoked without +// setting the state to `UIGestureRecognizerStateEnded`. +@property(nonatomic) BOOL touchedEndedWithoutBlocking; + +@property(nonatomic) UIGestureRecognizer* forwardingRecognizer; + +- (instancetype)initWithTarget:(id)target + action:(SEL)action + forwardingRecognizer:(UIGestureRecognizer*)forwardingRecognizer; +@end + +// While the FlutterDelayingGestureRecognizer is preventing touches from hitting the responder chain +// the touch events are not arriving to the FlutterView (and thus not arriving to the Flutter +// framework). We use this gesture recognizer to dispatch the events directly to the FlutterView +// while during this phase. +// +// If the Flutter framework decides to dispatch events to the embedded view, we fail the +// FlutterDelayingGestureRecognizer which sends the events up the responder chain. But since the +// events are handled by the embedded view they are not delivered to the Flutter framework in this +// phase as well. So during this phase as well the ForwardingGestureRecognizer dispatched the events +// directly to the FlutterView. +@interface ForwardingGestureRecognizer : UIGestureRecognizer +- (instancetype)initWithTarget:(id)target + platformViewsController: + (fml::WeakPtr)platformViewsController; +- (ForwardingGestureRecognizer*)recreateRecognizerWithTarget:(id)target; +@end + #endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERPLATFORMVIEWS_INTERNAL_H_ diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm index bd0edd7683..ce38124365 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm @@ -510,46 +510,6 @@ static BOOL _preparedOnce = NO; } @end -// This recognizer delays touch events from being dispatched to the responder chain until it failed -// recognizing a gesture. -// -// We only fail this recognizer when asked to do so by the Flutter framework (which does so by -// 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 FlutterDelayingGestureRecognizer : UIGestureRecognizer - -// Indicates that if the `FlutterDelayingGestureRecognizer`'s state should be set to -// `UIGestureRecognizerStateEnded` during next `touchesEnded` call. -@property(nonatomic) BOOL shouldEndInNextTouchesEnded; - -// Indicates that the `FlutterDelayingGestureRecognizer`'s `touchesEnded` has been invoked without -// setting the state to `UIGestureRecognizerStateEnded`. -@property(nonatomic) BOOL touchedEndedWithoutBlocking; - -@property(nonatomic) UIGestureRecognizer* forwardingRecognizer; - -- (instancetype)initWithTarget:(id)target - action:(SEL)action - forwardingRecognizer:(UIGestureRecognizer*)forwardingRecognizer; -@end - -// While the FlutterDelayingGestureRecognizer is preventing touches from hitting the responder chain -// the touch events are not arriving to the FlutterView (and thus not arriving to the Flutter -// framework). We use this gesture recognizer to dispatch the events directly to the FlutterView -// while during this phase. -// -// If the Flutter framework decides to dispatch events to the embedded view, we fail the -// FlutterDelayingGestureRecognizer which sends the events up the responder chain. But since the -// events are handled by the embedded view they are not delivered to the Flutter framework in this -// phase as well. So during this phase as well the ForwardingGestureRecognizer dispatched the events -// directly to the FlutterView. -@interface ForwardingGestureRecognizer : UIGestureRecognizer -- (instancetype)initWithTarget:(id)target - platformViewsController: - (fml::WeakPtr)platformViewsController; -- (ForwardingGestureRecognizer*)recreateRecognizerWithTarget:(id)target; -@end - @interface FlutterTouchInterceptingView () @property(nonatomic, weak, readonly) UIView* embeddedView; @property(nonatomic, readonly) FlutterDelayingGestureRecognizer* delayingRecognizer; diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterView.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterView.mm index 1f26954009..cab7a67e15 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterView.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterView.mm @@ -40,7 +40,7 @@ FLUTTER_ASSERT_ARC } - (MTLPixelFormat)pixelFormat { - if ([self.layer isKindOfClass:NSClassFromString(@"CAMetalLayer")]) { + if ([self.layer isKindOfClass:[CAMetalLayer class]]) { // It is a known Apple bug that CAMetalLayer incorrectly reports its supported // SDKs. It is, in fact, available since iOS 8. #pragma clang diagnostic push @@ -93,7 +93,7 @@ static void PrintWideGamutWarningOnce() { } - (void)layoutSubviews { - if ([self.layer isKindOfClass:NSClassFromString(@"CAMetalLayer")]) { + if ([self.layer isKindOfClass:[CAMetalLayer class]]) { // It is a known Apple bug that CAMetalLayer incorrectly reports its supported // SDKs. It is, in fact, available since iOS 8. #pragma clang diagnostic push diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewTest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewTest.mm index e7b26cbe70..08cf885da5 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewTest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewTest.mm @@ -62,7 +62,7 @@ FLUTTER_ASSERT_ARC delegate.isUsingImpeller = NO; FlutterView* view = [[FlutterView alloc] initWithDelegate:delegate opaque:NO enableWideGamut:YES]; [view layoutSubviews]; - XCTAssertTrue([view.layer isKindOfClass:NSClassFromString(@"CAMetalLayer")]); + XCTAssertTrue([view.layer isKindOfClass:[CAMetalLayer class]]); CAMetalLayer* layer = (CAMetalLayer*)view.layer; XCTAssertEqual(layer.pixelFormat, MTLPixelFormatBGRA8Unorm); }