mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
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:
parent
ee923bfd94
commit
750f2e5bef
@ -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_
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user