Skip to content

Commit

Permalink
feat: change default style to be UIStatusBarStyleDefault and add dark…
Browse files Browse the repository at this point in the history
… content style
  • Loading branch information
andredestro committed Jul 31, 2024
1 parent 6c1ebbe commit 598439a
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<param name="onload" value="true" />
</feature>
<preference name="StatusBarOverlaysWebView" value="true" />
<preference name="StatusBarStyle" value="lightcontent" />
<preference name="StatusBarStyle" value="default" />
</config-file>

<header-file src="src/ios/CDVStatusBar.h" />
Expand Down
1 change: 1 addition & 0 deletions src/ios/CDVStatusBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
- (void) overlaysWebView:(CDVInvokedUrlCommand*)command;

- (void) styleDefault:(CDVInvokedUrlCommand*)command;
- (void) styleDarkContent:(CDVInvokedUrlCommand*)command;
- (void) styleLightContent:(CDVInvokedUrlCommand*)command;
- (void) styleBlackTranslucent:(CDVInvokedUrlCommand*)command;
- (void) styleBlackOpaque:(CDVInvokedUrlCommand*)command;
Expand Down
14 changes: 8 additions & 6 deletions src/ios/CDVStatusBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ - (void) setStatusBarStyle:(NSString*)statusBarStyle
[self styleDefault:nil];
} else if ([lcStatusBarStyle isEqualToString:@"lightcontent"]) {
[self styleLightContent:nil];
} else if ([lcStatusBarStyle isEqualToString:@"darkcontent"]) {
[self styleDarkContent:nil];
} else if ([lcStatusBarStyle isEqualToString:@"blacktranslucent"]) {
[self styleBlackTranslucent:nil];
} else if ([lcStatusBarStyle isEqualToString:@"blackopaque"]) {
Expand All @@ -325,12 +327,12 @@ - (void) setStatusBarStyle:(NSString*)statusBarStyle

- (void) styleDefault:(CDVInvokedUrlCommand*)command
{
if (@available(iOS 13.0, *)) {
// TODO - Replace with UIStatusBarStyleDarkContent once Xcode 10 support is dropped
[self setStyleForStatusBar:3];
} else {
[self setStyleForStatusBar:UIStatusBarStyleDefault];
}
[self setStyleForStatusBar:UIStatusBarStyleDefault];
}

- (void) styleDarkContent:(CDVInvokedUrlCommand*)command
{
[self setStyleForStatusBar:UIStatusBarStyleDarkContent];
}

- (void) styleLightContent:(CDVInvokedUrlCommand*)command
Expand Down
3 changes: 3 additions & 0 deletions tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ exports.defineAutoTests = function () {
expect(window.StatusBar.styleDefault).toBeDefined();
expect(typeof window.StatusBar.styleDefault).toBe('function');

expect(window.StatusBar.styleDarkContent).toBeDefined();
expect(typeof window.StatusBar.styleDarkContent).toBe('function');

expect(window.StatusBar.styleLightContent).toBeDefined();
expect(typeof window.StatusBar.styleLightContent).toBe('function');

Expand Down
9 changes: 7 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@ interface StatusBar {
overlaysWebView(isOverlay: boolean): void;

/**
* Use the default statusbar (dark text, for light backgrounds).
* Automatically chooses light or dark content based on the user interface style
*/
styleDefault(): void;

/**
* Use the darkContent statusbar (dark text, for light backgrounds).
*/
styleDarkContent(): void;

/**
* Use the lightContent statusbar (light text, for dark backgrounds).
*/
Expand Down Expand Up @@ -78,4 +83,4 @@ interface StatusBar {
isVisible: boolean;
}

declare var StatusBar: StatusBar;
declare var StatusBar: StatusBar;
7 changes: 6 additions & 1 deletion www/statusbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,19 @@ var StatusBar = {
},

styleDefault: function () {
// dark text ( to be used on a light background )
// automatically chooses light or dark content based on the user interface style
exec(null, null, 'StatusBar', 'styleDefault', []);
},

styleLightContent: function () {
// light text ( to be used on a dark background )
exec(null, null, 'StatusBar', 'styleLightContent', []);
},

Check failure on line 64 in www/statusbar.js

View workflow job for this annotation

GitHub Actions / Lint Test

Trailing spaces not allowed

Check failure on line 64 in www/statusbar.js

View workflow job for this annotation

GitHub Actions / Lint Test

Trailing spaces not allowed
styleDarkContent: function () {
// dark text ( to be used on a light background )
exec(null, null, 'StatusBar', 'styleDarkContent', []);
},

styleBlackTranslucent: function () {
console.warn('styleBlackTranslucent is deprecated and will be removed in next major release, use styleLightContent');
Expand Down

0 comments on commit 598439a

Please sign in to comment.