From 8c73572fc881ef446fc321e8a5d4f67fc75d948b Mon Sep 17 00:00:00 2001 From: LinXunFeng Date: Mon, 20 Nov 2023 23:32:10 +0800 Subject: [PATCH 1/3] fix: flutter#138604 --- .../darwin/ios/framework/Source/FlutterPlatformPlugin.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm index c1d7eaea3296e..fff481ac5cf02 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm @@ -41,7 +41,7 @@ using namespace flutter; static void SetStatusBarHiddenForSharedApplication(BOOL hidden) { -#if APPLICATION_EXTENSION_API_ONLY +#if not APPLICATION_EXTENSION_API_ONLY [UIApplication sharedApplication].statusBarHidden = hidden; #else FML_LOG(WARNING) << "Application based status bar styling is not available in app extension."; @@ -49,7 +49,7 @@ static void SetStatusBarHiddenForSharedApplication(BOOL hidden) { } static void SetStatusBarStyleForSharedApplication(UIStatusBarStyle style) { -#if APPLICATION_EXTENSION_API_ONLY +#if not APPLICATION_EXTENSION_API_ONLY // Note: -[UIApplication setStatusBarStyle] is deprecated in iOS9 // in favor of delegating to the view controller. [[UIApplication sharedApplication] setStatusBarStyle:style]; From 1605afc4a234f1bdcf74ff7143ce586fedc9dad7 Mon Sep 17 00:00:00 2001 From: LinXunFeng Date: Tue, 21 Nov 2023 23:21:02 +0800 Subject: [PATCH 2/3] add: test --- .../Source/FlutterPlatformPluginTest.mm | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm index 894e1f30cd5e1..491a059b34dbf 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm @@ -370,4 +370,96 @@ - (void)testViewControllerBasedStatusBarHiddenUpdate { [bundleMock stopMocking]; } +- (void)testStatusBarHiddenUpdate { + id bundleMock = OCMPartialMock([NSBundle mainBundle]); + OCMStub([bundleMock objectForInfoDictionaryKey:@"UIViewControllerBasedStatusBarAppearance"]) + .andReturn(@NO); + id mockApplication = OCMClassMock([UIApplication class]); + OCMStub([mockApplication sharedApplication]).andReturn(mockApplication); + + // Enabling system UI overlays to update status bar. + FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test" project:nil]; + [engine runWithEntrypoint:nil]; + FlutterViewController* flutterViewController = + [[FlutterViewController alloc] initWithEngine:engine nibName:nil bundle:nil]; + std::unique_ptr> _weakFactory = + std::make_unique>(engine); + + // Update to hidden. + FlutterPlatformPlugin* plugin = [engine platformPlugin]; + + XCTestExpectation* enableSystemUIOverlaysCalled = + [self expectationWithDescription:@"setEnabledSystemUIOverlays"]; + FlutterResult resultSet = ^(id result) { + [enableSystemUIOverlaysCalled fulfill]; + }; + FlutterMethodCall* methodCallSet = + [FlutterMethodCall methodCallWithMethodName:@"SystemChrome.setEnabledSystemUIOverlays" + arguments:@[ @"SystemUiOverlay.bottom" ]]; + [plugin handleMethodCall:methodCallSet result:resultSet]; + [self waitForExpectationsWithTimeout:1 handler:nil]; +#if not APPLICATION_EXTENSION_API_ONLY + OCMVerify([mockApplication setStatusBarHidden:YES]); +#endif + + // Update to shown. + XCTestExpectation* enableSystemUIOverlaysCalled2 = + [self expectationWithDescription:@"setEnabledSystemUIOverlays"]; + FlutterResult resultSet2 = ^(id result) { + [enableSystemUIOverlaysCalled2 fulfill]; + }; + FlutterMethodCall* methodCallSet2 = + [FlutterMethodCall methodCallWithMethodName:@"SystemChrome.setEnabledSystemUIOverlays" + arguments:@[ @"SystemUiOverlay.top" ]]; + [plugin handleMethodCall:methodCallSet2 result:resultSet2]; + [self waitForExpectationsWithTimeout:1 handler:nil]; +#if not APPLICATION_EXTENSION_API_ONLY + OCMVerify([mockApplication setStatusBarHidden:NO]); +#endif + + [flutterViewController deregisterNotifications]; + [mockApplication stopMocking]; + [bundleMock stopMocking]; +} + +- (void)testStatusBarStyle { + id bundleMock = OCMPartialMock([NSBundle mainBundle]); + OCMStub([bundleMock objectForInfoDictionaryKey:@"UIViewControllerBasedStatusBarAppearance"]) + .andReturn(@NO); + id mockApplication = OCMClassMock([UIApplication class]); + OCMStub([mockApplication sharedApplication]).andReturn(mockApplication); + + FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test" project:nil]; + [engine runWithEntrypoint:nil]; + FlutterViewController* flutterViewController = + [[FlutterViewController alloc] initWithEngine:engine nibName:nil bundle:nil]; + std::unique_ptr> _weakFactory = + std::make_unique>(engine); + XCTAssertFalse(flutterViewController.prefersStatusBarHidden); + + FlutterPlatformPlugin* plugin = [engine platformPlugin]; + + XCTestExpectation* enableSystemUIModeCalled = + [self expectationWithDescription:@"setSystemUIOverlayStyle"]; + FlutterResult resultSet = ^(id result) { + [enableSystemUIModeCalled fulfill]; + }; + FlutterMethodCall* methodCallSet = + [FlutterMethodCall methodCallWithMethodName:@"SystemChrome.setSystemUIOverlayStyle" + arguments:@{ + @"statusBarBrightness": @"Brightness.dark" + }]; + [plugin handleMethodCall:methodCallSet result:resultSet]; + [self waitForExpectationsWithTimeout:1 handler:nil]; + +#if not APPLICATION_EXTENSION_API_ONLY + OCMVerify([mockApplication setStatusBarStyle:UIStatusBarStyleLightContent]); +#endif + + [flutterViewController deregisterNotifications]; + [mockApplication stopMocking]; + [bundleMock stopMocking]; +} + + @end From a8fafb9648a072bc57072ff083dc299bf6c9b668 Mon Sep 17 00:00:00 2001 From: LinXunFeng Date: Tue, 21 Nov 2023 23:32:40 +0800 Subject: [PATCH 3/3] formatting --- .../Source/FlutterPlatformPluginTest.mm | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm index 491a059b34dbf..5ce553ca29e02 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm @@ -373,7 +373,7 @@ - (void)testViewControllerBasedStatusBarHiddenUpdate { - (void)testStatusBarHiddenUpdate { id bundleMock = OCMPartialMock([NSBundle mainBundle]); OCMStub([bundleMock objectForInfoDictionaryKey:@"UIViewControllerBasedStatusBarAppearance"]) - .andReturn(@NO); + .andReturn(@NO); id mockApplication = OCMClassMock([UIApplication class]); OCMStub([mockApplication sharedApplication]).andReturn(mockApplication); @@ -381,21 +381,21 @@ - (void)testStatusBarHiddenUpdate { FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test" project:nil]; [engine runWithEntrypoint:nil]; FlutterViewController* flutterViewController = - [[FlutterViewController alloc] initWithEngine:engine nibName:nil bundle:nil]; + [[FlutterViewController alloc] initWithEngine:engine nibName:nil bundle:nil]; std::unique_ptr> _weakFactory = - std::make_unique>(engine); + std::make_unique>(engine); // Update to hidden. FlutterPlatformPlugin* plugin = [engine platformPlugin]; XCTestExpectation* enableSystemUIOverlaysCalled = - [self expectationWithDescription:@"setEnabledSystemUIOverlays"]; + [self expectationWithDescription:@"setEnabledSystemUIOverlays"]; FlutterResult resultSet = ^(id result) { [enableSystemUIOverlaysCalled fulfill]; }; FlutterMethodCall* methodCallSet = - [FlutterMethodCall methodCallWithMethodName:@"SystemChrome.setEnabledSystemUIOverlays" - arguments:@[ @"SystemUiOverlay.bottom" ]]; + [FlutterMethodCall methodCallWithMethodName:@"SystemChrome.setEnabledSystemUIOverlays" + arguments:@[ @"SystemUiOverlay.bottom" ]]; [plugin handleMethodCall:methodCallSet result:resultSet]; [self waitForExpectationsWithTimeout:1 handler:nil]; #if not APPLICATION_EXTENSION_API_ONLY @@ -409,8 +409,8 @@ - (void)testStatusBarHiddenUpdate { [enableSystemUIOverlaysCalled2 fulfill]; }; FlutterMethodCall* methodCallSet2 = - [FlutterMethodCall methodCallWithMethodName:@"SystemChrome.setEnabledSystemUIOverlays" - arguments:@[ @"SystemUiOverlay.top" ]]; + [FlutterMethodCall methodCallWithMethodName:@"SystemChrome.setEnabledSystemUIOverlays" + arguments:@[ @"SystemUiOverlay.top" ]]; [plugin handleMethodCall:methodCallSet2 result:resultSet2]; [self waitForExpectationsWithTimeout:1 handler:nil]; #if not APPLICATION_EXTENSION_API_ONLY @@ -425,7 +425,7 @@ - (void)testStatusBarHiddenUpdate { - (void)testStatusBarStyle { id bundleMock = OCMPartialMock([NSBundle mainBundle]); OCMStub([bundleMock objectForInfoDictionaryKey:@"UIViewControllerBasedStatusBarAppearance"]) - .andReturn(@NO); + .andReturn(@NO); id mockApplication = OCMClassMock([UIApplication class]); OCMStub([mockApplication sharedApplication]).andReturn(mockApplication); @@ -446,9 +446,7 @@ - (void)testStatusBarStyle { }; FlutterMethodCall* methodCallSet = [FlutterMethodCall methodCallWithMethodName:@"SystemChrome.setSystemUIOverlayStyle" - arguments:@{ - @"statusBarBrightness": @"Brightness.dark" - }]; + arguments:@{@"statusBarBrightness" : @"Brightness.dark"}]; [plugin handleMethodCall:methodCallSet result:resultSet]; [self waitForExpectationsWithTimeout:1 handler:nil]; @@ -461,5 +459,4 @@ - (void)testStatusBarStyle { [bundleMock stopMocking]; } - @end