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

dpogue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-ios.git


The following commit(s) were added to refs/heads/master by this push:
     new c1d4cafa feat(statusbar): change dark/light appearance according to 
background color (#1689)
c1d4cafa is described below

commit c1d4cafa88362c5fa9f8e8a0177489799c6bcb8f
Author: Manuel Beck <[email protected]>
AuthorDate: Wed Aug 26 12:30:11 2026 +0200

    feat(statusbar): change dark/light appearance according to background color 
(#1689)
    
    * 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
    
    * since iOS 18.5+ the system handles the appearance automatically
    
    - Since iOS 18.5 the system automatically changes the appearance of the 
status bar based on the underlying color.
---
 CordovaLib/Classes/Public/CDVViewController.m | 22 ++++++++++++++++++++++
 tests/CordovaLibTests/CDVStatusBarTests.m     | 25 +++++++++++++++++++++++++
 2 files changed, 47 insertions(+)

diff --git a/CordovaLib/Classes/Public/CDVViewController.m 
b/CordovaLib/Classes/Public/CDVViewController.m
index 2b459b92..17695756 100644
--- a/CordovaLib/Classes/Public/CDVViewController.m
+++ b/CordovaLib/Classes/Public/CDVViewController.m
@@ -209,6 +209,7 @@ static UIColor *defaultBackgroundColor(void) {
     }
 
     [self.statusBarBackground 
setBackgroundColor:self.statusBarBackgroundColor];
+    [self setNeedsStatusBarAppearanceUpdate];
 }
 
 - (void)setStatusBarWebViewColor:(UIColor *)color
@@ -216,6 +217,7 @@ static UIColor *defaultBackgroundColor(void) {
     _statusBarWebViewColor = color;
 
     [self.statusBarBackground 
setBackgroundColor:self.statusBarBackgroundColor];
+    [self setNeedsStatusBarAppearanceUpdate];
 }
 
 // Only for testing
@@ -908,6 +910,26 @@ static UIColor *defaultBackgroundColor(void) {
 #endif
 }
 
+- (UIStatusBarStyle)preferredStatusBarStyle
+{
+    // Since iOS 18.5, the system automatically determines the status bar 
style based on the background color of the status bar
+    // so let the system handle it
+    if (@available(iOS 18.5, *)) {
+        return [super 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..880967c8 100644
--- a/tests/CordovaLibTests/CDVStatusBarTests.m
+++ b/tests/CordovaLibTests/CDVStatusBarTests.m
@@ -162,4 +162,29 @@ 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];
+    
+    // Since iOS 18.5, the system automatically determines the status bar 
style based on the background color of the status bar
+    // Check this
+    if (@available(iOS 18.5, *)) {
+        XCTAssertEqual(self.viewController.preferredStatusBarStyle, 
[UIViewController new].preferredStatusBarStyle);
+        return;
+    }
+
+    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: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to