mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Support status bar taps in FlutterAppDelegate (#3387)
Provide a default status bar tap handler for FlutterAppDelegate. By default, taps are passed to the key window's rootViewController if it's a FlutterViewController. Apps with custom app delegates can customize this behaviour to send the tap to the FlutterViewController(s) they prefer by overriding touchesBegan:withEvent.
This commit is contained in:
parent
c1524787df
commit
c354127d4d
@ -9,10 +9,18 @@
|
||||
|
||||
#include "FlutterMacros.h"
|
||||
|
||||
// Empty implementation of UIApplicationDelegate, for simple apps
|
||||
// that don't need to customize the application delegate.
|
||||
/**
|
||||
* UIApplicationDelegate subclass for simple apps that want default behavior.
|
||||
*
|
||||
* This class provides the following behaviors:
|
||||
* * Status bar touches are forwarded to the key window's root view
|
||||
* FlutterViewController, in order to trigger scroll to top.
|
||||
*
|
||||
* App delegates for Flutter applications are *not* required to inherit from
|
||||
* this class. Developers of custom app delegate classes should copy and paste
|
||||
* code as necessary from FlutterAppDelegate.mm.
|
||||
*/
|
||||
FLUTTER_EXPORT
|
||||
__attribute__((deprecated("subclass UIResponder<UIApplicationDelegate>")))
|
||||
@interface FlutterAppDelegate : UIResponder<UIApplicationDelegate>
|
||||
|
||||
@property(strong, nonatomic) UIWindow* window;
|
||||
|
||||
@ -3,7 +3,28 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "flutter/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h"
|
||||
#include "flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h"
|
||||
|
||||
@implementation FlutterAppDelegate
|
||||
|
||||
// Returns the key window's rootViewController, if it's a FlutterViewController.
|
||||
// Otherwise, returns nil.
|
||||
- (FlutterViewController*)rootFlutterViewController {
|
||||
UIViewController *viewController =
|
||||
[UIApplication sharedApplication].keyWindow.rootViewController;
|
||||
if ([viewController isKindOfClass:[FlutterViewController class]]) {
|
||||
return (FlutterViewController*)viewController;
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (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];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user