You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ma...@apache.org on 2026/08/09 08:27:26 UTC

(cordova-ios) 01/01: feat(statusbar): change dark/light appearance according to background color

This is an automated email from the ASF dual-hosted git repository.

GitToTheHub pushed a commit to branch pr-feat-change-appearance-of-statusbar-by-setting-background-color
in repository https://gitbox.apache.org/repos/asf/cordova-ios.git

commit 2a10788e3d0f549e0547bc8c0aae2911da444d25
Author: Manuel Beck <ma...@outlook.de>
AuthorDate: Sun Aug 9 10:27:12 2026 +0200

    feat(statusbar): change dark/light appearance according to background color
    
    - On Android it's possible to change the dark/light appearance of the status bar by setting the background color of it, even it is not applied visually when in edge-to-edge mode. On iOS the system automatically changes the appearance, but only since iOS 18.5. On older iOS versions that's not the case. So this feature should be available for iOS also.
    - Added status bar test `testStatusBarAppearanceFollowsBackgroundColor`
    - Fixes #1688
    
    Generated-By: GPT-5.6 Terra
---
 CordovaLib/Classes/Public/CDVViewController.m | 16 ++++++++++++++++
 tests/CordovaLibTests/CDVStatusBarTests.m     | 18 ++++++++++++++++++
 2 files changed, 34 insertions(+)

diff --git a/CordovaLib/Classes/Public/CDVViewController.m b/CordovaLib/Classes/Public/CDVViewController.m
index b2dc5714..e3a2c590 100644
--- a/CordovaLib/Classes/Public/CDVViewController.m
+++ b/CordovaLib/Classes/Public/CDVViewController.m
@@ -209,6 +209,7 @@ static UIColor *defaultBackgroundColor(void) {
     }
 
     [self.statusBar setBackgroundColor:self.statusBarBackgroundColor];
+    [self setNeedsStatusBarAppearanceUpdate];
 }
 
 - (void)setStatusBarWebViewColor:(UIColor *)color
@@ -216,6 +217,7 @@ static UIColor *defaultBackgroundColor(void) {
     _statusBarWebViewColor = color;
 
     [self.statusBar setBackgroundColor:self.statusBarBackgroundColor];
+    [self setNeedsStatusBarAppearanceUpdate];
 }
 
 // Only for testing
@@ -895,6 +897,20 @@ static UIColor *defaultBackgroundColor(void) {
 #endif
 }
 
+- (UIStatusBarStyle)preferredStatusBarStyle
+{
+    CGFloat red = 0.f;
+    CGFloat green = 0.f;
+    CGFloat blue = 0.f;
+
+    if (![self.statusBarBackgroundColor getRed:&red green:&green blue:&blue alpha:nil]) {
+        return UIStatusBarStyleDefault;
+    }
+
+    CGFloat luminance = 0.299f * red + 0.587f * green + 0.114f * blue;
+    return luminance > 0.5f ? UIStatusBarStyleDarkContent : UIStatusBarStyleLightContent;
+}
+
 - (void)parseSettingsWithParser:(id <NSXMLParserDelegate>)delegate
 {
     [CDVConfigParser parseConfigFile:self.configFilePath withDelegate:delegate];
diff --git a/tests/CordovaLibTests/CDVStatusBarTests.m b/tests/CordovaLibTests/CDVStatusBarTests.m
index 7a48d4c7..cf0827d3 100644
--- a/tests/CordovaLibTests/CDVStatusBarTests.m
+++ b/tests/CordovaLibTests/CDVStatusBarTests.m
@@ -162,4 +162,22 @@ andWaitForCordovaCommandQueueWithWebViewEngine:self.plugin
     XCTAssertEqual(rgba[3], 0.25f);
 }
 
+- (void)testStatusBarAppearanceFollowsBackgroundColor {
+    XCTestExpectation *loadExpectation = [[XCTNSNotificationExpectation alloc] initWithName:CDVTestingDeviceReadyFired];
+    [self.viewController loadStartPage];
+    [self waitForExpectations:@[loadExpectation] timeout:5];
+
+    [self evaluateJavaScript:@"window.statusbar.setBackgroundColor('#ffffff');"
+andWaitForCordovaCommandQueueWithWebViewEngine:self.plugin
+                     timeout:5];
+
+    XCTAssertEqual(self.viewController.preferredStatusBarStyle, UIStatusBarStyleDarkContent);
+
+    [self evaluateJavaScript:@"window.statusbar.setBackgroundColor('#000000');"
+andWaitForCordovaCommandQueueWithWebViewEngine:self.plugin
+                     timeout:5];
+
+    XCTAssertEqual(self.viewController.preferredStatusBarStyle, UIStatusBarStyleLightContent);
+}
+
 @end


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org