diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h b/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h index 8684a22ea7733..9c534a6fc80e0 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. + * + * 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/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm b/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm index 998211ed779a0..38a16143cf430 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,13 @@ - (FlutterViewController*)rootFlutterViewController { 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