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.
This commit is contained in:
gaaclarke 2019-09-27 15:10:28 -07:00 committed by GitHub
parent ee923bfd94
commit 750f2e5bef
2 changed files with 16 additions and 7 deletions

View File

@ -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<UITouch*>*)touches withEvent:(UIEvent*)event;
@end
#endif // FLUTTER_FLUTTERDARTPROJECT_H_

View File

@ -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<UITouch*>*)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<UITouch*>*)touches withEvent:(UIEvent*)event {
[super touchesBegan:touches withEvent:event];
[[self class] handleStatusBarTouches:touches withEvent:event];
}
#pragma GCC diagnostic push