Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 51e50e8

Browse files
authored
[CP] Fix not being able to hide iOS status bar via setEnabledSystemUIMode (#48403)
Original PR: #48271 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent 5a11866 commit 51e50e8

File tree

2 files changed

+91
-2
lines changed

2 files changed

+91
-2
lines changed

shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@
4343
using namespace flutter;
4444

4545
static void SetStatusBarHiddenForSharedApplication(BOOL hidden) {
46-
#if APPLICATION_EXTENSION_API_ONLY
46+
#if not APPLICATION_EXTENSION_API_ONLY
4747
[UIApplication sharedApplication].statusBarHidden = hidden;
4848
#else
4949
FML_LOG(WARNING) << "Application based status bar styling is not available in app extension.";
5050
#endif
5151
}
5252

5353
static void SetStatusBarStyleForSharedApplication(UIStatusBarStyle style) {
54-
#if APPLICATION_EXTENSION_API_ONLY
54+
#if not APPLICATION_EXTENSION_API_ONLY
5555
// Note: -[UIApplication setStatusBarStyle] is deprecated in iOS9
5656
// in favor of delegating to the view controller.
5757
[[UIApplication sharedApplication] setStatusBarStyle:style];

shell/platform/darwin/ios/framework/Source/FlutterPlatformPluginTest.mm

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,4 +405,93 @@ - (void)testViewControllerBasedStatusBarHiddenUpdate {
405405
[bundleMock stopMocking];
406406
}
407407

408+
- (void)testStatusBarHiddenUpdate {
409+
id bundleMock = OCMPartialMock([NSBundle mainBundle]);
410+
OCMStub([bundleMock objectForInfoDictionaryKey:@"UIViewControllerBasedStatusBarAppearance"])
411+
.andReturn(@NO);
412+
id mockApplication = OCMClassMock([UIApplication class]);
413+
OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
414+
415+
// Enabling system UI overlays to update status bar.
416+
FlutterEngine* engine = [[[FlutterEngine alloc] initWithName:@"test" project:nil] autorelease];
417+
[engine runWithEntrypoint:nil];
418+
FlutterViewController* flutterViewController =
419+
[[[FlutterViewController alloc] initWithEngine:engine nibName:nil bundle:nil] autorelease];
420+
std::unique_ptr<fml::WeakPtrFactory<FlutterEngine>> _weakFactory =
421+
std::make_unique<fml::WeakPtrFactory<FlutterEngine>>(engine);
422+
423+
// Update to hidden.
424+
FlutterPlatformPlugin* plugin = [engine platformPlugin];
425+
426+
XCTestExpectation* enableSystemUIOverlaysCalled =
427+
[self expectationWithDescription:@"setEnabledSystemUIOverlays"];
428+
FlutterResult resultSet = ^(id result) {
429+
[enableSystemUIOverlaysCalled fulfill];
430+
};
431+
FlutterMethodCall* methodCallSet =
432+
[FlutterMethodCall methodCallWithMethodName:@"SystemChrome.setEnabledSystemUIOverlays"
433+
arguments:@[ @"SystemUiOverlay.bottom" ]];
434+
[plugin handleMethodCall:methodCallSet result:resultSet];
435+
[self waitForExpectationsWithTimeout:1 handler:nil];
436+
#if not APPLICATION_EXTENSION_API_ONLY
437+
OCMVerify([mockApplication setStatusBarHidden:YES]);
438+
#endif
439+
440+
// Update to shown.
441+
XCTestExpectation* enableSystemUIOverlaysCalled2 =
442+
[self expectationWithDescription:@"setEnabledSystemUIOverlays"];
443+
FlutterResult resultSet2 = ^(id result) {
444+
[enableSystemUIOverlaysCalled2 fulfill];
445+
};
446+
FlutterMethodCall* methodCallSet2 =
447+
[FlutterMethodCall methodCallWithMethodName:@"SystemChrome.setEnabledSystemUIOverlays"
448+
arguments:@[ @"SystemUiOverlay.top" ]];
449+
[plugin handleMethodCall:methodCallSet2 result:resultSet2];
450+
[self waitForExpectationsWithTimeout:1 handler:nil];
451+
#if not APPLICATION_EXTENSION_API_ONLY
452+
OCMVerify([mockApplication setStatusBarHidden:NO]);
453+
#endif
454+
455+
[flutterViewController deregisterNotifications];
456+
[mockApplication stopMocking];
457+
[bundleMock stopMocking];
458+
}
459+
460+
- (void)testStatusBarStyle {
461+
id bundleMock = OCMPartialMock([NSBundle mainBundle]);
462+
OCMStub([bundleMock objectForInfoDictionaryKey:@"UIViewControllerBasedStatusBarAppearance"])
463+
.andReturn(@NO);
464+
id mockApplication = OCMClassMock([UIApplication class]);
465+
OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
466+
467+
FlutterEngine* engine = [[[FlutterEngine alloc] initWithName:@"test" project:nil] autorelease];
468+
[engine runWithEntrypoint:nil];
469+
FlutterViewController* flutterViewController =
470+
[[[FlutterViewController alloc] initWithEngine:engine nibName:nil bundle:nil] autorelease];
471+
std::unique_ptr<fml::WeakPtrFactory<FlutterEngine>> _weakFactory =
472+
std::make_unique<fml::WeakPtrFactory<FlutterEngine>>(engine);
473+
XCTAssertFalse(flutterViewController.prefersStatusBarHidden);
474+
475+
FlutterPlatformPlugin* plugin = [engine platformPlugin];
476+
477+
XCTestExpectation* enableSystemUIModeCalled =
478+
[self expectationWithDescription:@"setSystemUIOverlayStyle"];
479+
FlutterResult resultSet = ^(id result) {
480+
[enableSystemUIModeCalled fulfill];
481+
};
482+
FlutterMethodCall* methodCallSet =
483+
[FlutterMethodCall methodCallWithMethodName:@"SystemChrome.setSystemUIOverlayStyle"
484+
arguments:@{@"statusBarBrightness" : @"Brightness.dark"}];
485+
[plugin handleMethodCall:methodCallSet result:resultSet];
486+
[self waitForExpectationsWithTimeout:1 handler:nil];
487+
488+
#if not APPLICATION_EXTENSION_API_ONLY
489+
OCMVerify([mockApplication setStatusBarStyle:UIStatusBarStyleLightContent]);
490+
#endif
491+
492+
[flutterViewController deregisterNotifications];
493+
[mockApplication stopMocking];
494+
[bundleMock stopMocking];
495+
}
496+
408497
@end

0 commit comments

Comments
 (0)