From 549dcad6da1d601705130faed80254bc61e467c0 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Fri, 27 Sep 2019 13:30:35 -0700 Subject: [PATCH 1/3] 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 | 13 ++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h b/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h index 8684a22ea7733..a7f1dd2b2b89b 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h @@ -29,6 +29,15 @@ FLUTTER_EXPORT @property(strong, nonatomic) UIWindow* window; +/** + * Handle StatusBar touches. + * + * If you want your Flutter views to respond to StatusBar touches, like scroll-to-top behavior, you + * need to call this function from your AppDelegate's `touchesBegan:withEvent:`. 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/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm b/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm index 998211ed779a0..7f3ae71d85852 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm @@ -40,7 +40,7 @@ - (BOOL)application:(UIApplication*)application // 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,16 @@ - (FlutterViewController*)rootFlutterViewController { return nil; } ++ (void)handleStatusBarTouches:(NSSet*)touches withEvent:(UIEvent*)event { + if (self.class.rootFlutterViewController != nil) { + [self.class.rootFlutterViewController handleStatusBarTouches:event]; + } +} + - (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event { [super touchesBegan:touches withEvent:event]; - // Pass status bar taps to key window Flutter rootViewController. - if (self.rootFlutterViewController != nil) { - [self.rootFlutterViewController handleStatusBarTouches:event]; - } + [self.class handleStatusBarTouches:touches withEvent:event]; } #pragma GCC diagnostic push From e32642f9a51180974c34c346fa6e2918184a5363 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Fri, 27 Sep 2019 14:27:53 -0700 Subject: [PATCH 2/3] responded to jmagman's feedback --- .../darwin/ios/framework/Headers/FlutterAppDelegate.h | 6 +++--- .../darwin/ios/framework/Source/FlutterAppDelegate.mm | 7 ++----- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h b/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h index a7f1dd2b2b89b..dbde8e3d352c0 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h @@ -32,9 +32,9 @@ FLUTTER_EXPORT /** * Handle StatusBar touches. * - * If you want your Flutter views to respond to StatusBar touches, like scroll-to-top behavior, you - * need to call this function from your AppDelegate's `touchesBegan:withEvent:`. FlutterAppDelegate - * already calls it so you only need to manually call it if you aren't using a FlutterAppDelegate. + * 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; diff --git a/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm b/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm index 7f3ae71d85852..b7121b35d24a5 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm @@ -49,15 +49,12 @@ + (FlutterViewController*)rootFlutterViewController { } + (void)handleStatusBarTouches:(NSSet*)touches withEvent:(UIEvent*)event { - if (self.class.rootFlutterViewController != nil) { - [self.class.rootFlutterViewController handleStatusBarTouches:event]; - } + [self.rootFlutterViewController handleStatusBarTouches:event]; } - (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event { [super touchesBegan:touches withEvent:event]; - - [self.class handleStatusBarTouches:touches withEvent:event]; + [[self class] handleStatusBarTouches:touches withEvent:event]; } #pragma GCC diagnostic push From bd295bcc2bfbde2ef1656f69793c5d4bd36fb6bb Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Fri, 27 Sep 2019 14:35:12 -0700 Subject: [PATCH 3/3] Added missing generics for touchesBegan:withEvent: --- .../darwin/ios/framework/Headers/FlutterAppDelegate.h | 2 +- .../darwin/ios/framework/Source/FlutterAppDelegate.mm | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h b/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h index dbde8e3d352c0..9c534a6fc80e0 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h @@ -36,7 +36,7 @@ FLUTTER_EXPORT * 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; ++ (void)handleStatusBarTouches:(NSSet*)touches withEvent:(UIEvent*)event; @end diff --git a/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm b/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm index b7121b35d24a5..38a16143cf430 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm @@ -48,11 +48,11 @@ + (FlutterViewController*)rootFlutterViewController { return nil; } -+ (void)handleStatusBarTouches:(NSSet*)touches withEvent:(UIEvent*)event { ++ (void)handleStatusBarTouches:(NSSet*)touches withEvent:(UIEvent*)event { [self.rootFlutterViewController handleStatusBarTouches:event]; } -- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event { +- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event { [super touchesBegan:touches withEvent:event]; [[self class] handleStatusBarTouches:touches withEvent:event]; }