[iOS] Fixes system navigator pop not work when App's root vc is TabBarController (flutter/engine#30939)
* [iOS] Fixes system navigator pop not work when App's root vc is TabBarController * Add test * Update review feedback
This commit is contained in:
@@ -241,12 +241,15 @@ using namespace flutter;
|
||||
// in the navigation hierarchy.
|
||||
// It's also possible in an Add2App scenario that the FlutterViewController was presented
|
||||
// outside the context of a UINavigationController, and still wants to be popped.
|
||||
UIViewController* viewController = [UIApplication sharedApplication].keyWindow.rootViewController;
|
||||
if ([viewController isKindOfClass:[UINavigationController class]]) {
|
||||
[((UINavigationController*)viewController) popViewControllerAnimated:isAnimated];
|
||||
|
||||
UIViewController* engineViewController = [_engine.get() viewController];
|
||||
UINavigationController* navigationController = [engineViewController navigationController];
|
||||
if (navigationController) {
|
||||
[navigationController popViewControllerAnimated:isAnimated];
|
||||
} else {
|
||||
auto engineViewController = static_cast<UIViewController*>([_engine.get() viewController]);
|
||||
if (engineViewController != viewController) {
|
||||
UIViewController* rootViewController =
|
||||
[UIApplication sharedApplication].keyWindow.rootViewController;
|
||||
if (engineViewController != rootViewController) {
|
||||
[engineViewController dismissViewControllerAnimated:isAnimated completion:nil];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterBinaryMessenger.h"
|
||||
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
|
||||
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h"
|
||||
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.h"
|
||||
#import "flutter/shell/platform/darwin/ios/platform_view_ios.h"
|
||||
|
||||
@@ -48,4 +49,32 @@
|
||||
XCTAssertEqual(value, true);
|
||||
}
|
||||
|
||||
- (void)testPopSystemNavigator {
|
||||
FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test" project:nil];
|
||||
[engine runWithEntrypoint:nil];
|
||||
FlutterViewController* flutterViewController =
|
||||
[[FlutterViewController alloc] initWithEngine:engine nibName:nil bundle:nil];
|
||||
UINavigationController* navigationController =
|
||||
[[UINavigationController alloc] initWithRootViewController:flutterViewController];
|
||||
UITabBarController* tabBarController = [[UITabBarController alloc] init];
|
||||
tabBarController.viewControllers = @[ navigationController ];
|
||||
std::unique_ptr<fml::WeakPtrFactory<FlutterEngine>> _weakFactory =
|
||||
std::make_unique<fml::WeakPtrFactory<FlutterEngine>>(engine);
|
||||
FlutterPlatformPlugin* plugin =
|
||||
[[FlutterPlatformPlugin alloc] initWithEngine:_weakFactory->GetWeakPtr()];
|
||||
|
||||
id navigationControllerMock = OCMPartialMock(navigationController);
|
||||
OCMStub([navigationControllerMock popViewControllerAnimated:YES]);
|
||||
// Set some string to the pasteboard.
|
||||
__block bool calledSet = false;
|
||||
FlutterResult resultSet = ^(id result) {
|
||||
calledSet = true;
|
||||
};
|
||||
FlutterMethodCall* methodCallSet =
|
||||
[FlutterMethodCall methodCallWithMethodName:@"SystemNavigator.pop" arguments:@(YES)];
|
||||
[plugin handleMethodCall:methodCallSet result:resultSet];
|
||||
XCTAssertEqual(calledSet, true);
|
||||
OCMVerify([navigationControllerMock popViewControllerAnimated:YES]);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user