From 750f2e5befef60bd764d8cfecec63a539cc9121b Mon Sep 17 00:00:00 2001 From: gaaclarke <30870216+gaaclarke@users.noreply.github.com> Date: Fri, 27 Sep 2019 15:10:28 -0700 Subject: [PATCH] Split out the logic to handle status bar touches into its own function (flutter/engine#12587) Split out the logic to handle status bar touches into its own function. This should make add-to-app clients' lives easier. --- .../ios/framework/Headers/FlutterAppDelegate.h | 9 +++++++++ .../ios/framework/Source/FlutterAppDelegate.mm | 14 +++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h b/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h index 8684a22ea77..9c534a6fc80 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h @@ -29,6 +29,15 @@ FLUTTER_EXPORT @property(strong, nonatomic) UIWindow* window; +/** + * Handle StatusBar touches. + * + * Call this from your AppDelegate's `touchesBegan:withEvent:` to have Flutter respond to StatusBar + * touches. For example, to enable scroll-to-top behavior. FlutterAppDelegate already calls it so + * you only need to manually call it if you aren't using a FlutterAppDelegate. + */ ++ (void)handleStatusBarTouches:(NSSet*)touches withEvent:(UIEvent*)event; + @end #endif // FLUTTER_FLUTTERDARTPROJECT_H_ diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm index 998211ed779..38a16143cf4 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm @@ -40,7 +40,7 @@ static NSString* kBackgroundFetchCapatibility = @"fetch"; // Returns the key window's rootViewController, if it's a FlutterViewController. // Otherwise, returns nil. -- (FlutterViewController*)rootFlutterViewController { ++ (FlutterViewController*)rootFlutterViewController { UIViewController* viewController = [UIApplication sharedApplication].keyWindow.rootViewController; if ([viewController isKindOfClass:[FlutterViewController class]]) { return (FlutterViewController*)viewController; @@ -48,13 +48,13 @@ static NSString* kBackgroundFetchCapatibility = @"fetch"; return nil; } -- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event { - [super touchesBegan:touches withEvent:event]; ++ (void)handleStatusBarTouches:(NSSet*)touches withEvent:(UIEvent*)event { + [self.rootFlutterViewController handleStatusBarTouches:event]; +} - // Pass status bar taps to key window Flutter rootViewController. - if (self.rootFlutterViewController != nil) { - [self.rootFlutterViewController handleStatusBarTouches:event]; - } +- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event { + [super touchesBegan:touches withEvent:event]; + [[self class] handleStatusBarTouches:touches withEvent:event]; } #pragma GCC diagnostic push