Skip to content

Commit 5085a74

Browse files
luissilvaosusernuno
authored andcommitted
feat: add support for the new Dark Content style
1 parent aae0aa6 commit 5085a74

File tree

9 files changed

+89
-17
lines changed

9 files changed

+89
-17
lines changed

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Preferences
5555

5656
<preference name="StatusBarBackgroundColor" value="#000000" />
5757

58-
- __StatusBarStyle__ (status bar style, defaults to lightcontent). Set the status bar style (e.g. text color). Available options: `default`, `lightcontent`. `blacktranslucent` and `blackopaque` are also available, but __deprecated__, will be removed in next major release, use `lightcontent` instead.
58+
- __StatusBarStyle__ (status bar style, defaults to lightcontent). Set the status bar style (e.g. text color). Available options: `default`, `lightcontent` and `darkcontent`. `blacktranslucent` and `blackopaque` are also available, but __deprecated__, will be removed in next major release, use `lightcontent` instead.
5959

6060
<preference name="StatusBarStyle" value="lightcontent" />
6161

@@ -118,6 +118,7 @@ Although in the global scope, it is not available until after the `deviceready`
118118
- StatusBar.overlaysWebView
119119
- StatusBar.styleDefault
120120
- StatusBar.styleLightContent
121+
- StatusBar.styleDarkContent
121122
- StatusBar.styleBlackTranslucent
122123
- StatusBar.styleBlackOpaque
123124
- StatusBar.backgroundColorByName
@@ -164,6 +165,7 @@ StatusBar.styleDefault
164165
=================
165166

166167
Use the default statusbar (dark text, for light backgrounds).
168+
For iOS - dark or light text depending on a device current theme.
167169

168170
StatusBar.styleDefault();
169171

@@ -183,6 +185,21 @@ Use the lightContent statusbar (light text, for dark backgrounds).
183185
StatusBar.styleLightContent();
184186

185187

188+
Supported Platforms
189+
-------------------
190+
191+
- iOS
192+
- Android 6+
193+
- Windows
194+
195+
StatusBar.styleDarkContent
196+
=================
197+
198+
Use the darkContent statusbar (dark text, for light backgrounds).
199+
200+
StatusBar.styleDarkContent();
201+
202+
186203
Supported Platforms
187204
-------------------
188205

src/android/StatusBar.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,16 @@ public void run() {
261261
return true;
262262
}
263263

264+
if ("styleDarkContent".equals(action)) {
265+
this.cordova.getActivity().runOnUiThread(new Runnable() {
266+
@Override
267+
public void run() {
268+
setStatusBarStyle("darkcontent");
269+
}
270+
});
271+
return true;
272+
}
273+
264274
if ("styleBlackTranslucent".equals(action)) {
265275
this.cordova.getActivity().runOnUiThread(new Runnable() {
266276
@Override
@@ -347,7 +357,8 @@ private void setStatusBarStyle(final String style) {
347357
int uiOptions = decorView.getSystemUiVisibility();
348358

349359
String[] darkContentStyles = {
350-
"default",
360+
"default",
361+
"darkcontent"
351362
};
352363

353364
String[] lightContentStyles = {
@@ -366,7 +377,7 @@ private void setStatusBarStyle(final String style) {
366377
return;
367378
}
368379

369-
LOG.e(TAG, "Invalid style, must be either 'default', 'lightcontent' or the deprecated 'blacktranslucent' and 'blackopaque'");
380+
LOG.e(TAG, "Invalid style, must be either 'default', 'lightcontent', 'darkcontent' or the deprecated 'blacktranslucent' and 'blackopaque'");
370381
}
371382
}
372383
}

src/browser/StatusBarProxy.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ function notSupported (win, fail) {
3333

3434
module.exports = {
3535
isVisible: false,
36-
styleBlackTranslucent: notSupported,
37-
styleDefault: notSupported,
38-
styleLightContent: notSupported,
39-
styleBlackOpaque: notSupported,
40-
overlaysWebView: notSupported,
36+
styleBlackTranslucent:notSupported,
37+
styleDefault:notSupported,
38+
styleLightContent:notSupported,
39+
styleDarkContent: notSupported,
40+
styleBlackOpaque:notSupported,
41+
overlaysWebView:notSupported,
4142
styleLightContect: notSupported,
4243
backgroundColorByName: notSupported,
4344
backgroundColorByHexString: notSupported,

src/ios/CDVStatusBar.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
- (void) styleDefault:(CDVInvokedUrlCommand*)command;
3838
- (void) styleLightContent:(CDVInvokedUrlCommand*)command;
39+
- (void) styleDarkContent:(CDVInvokedUrlCommand*)command;
3940
- (void) styleBlackTranslucent:(CDVInvokedUrlCommand*)command;
4041
- (void) styleBlackOpaque:(CDVInvokedUrlCommand*)command;
4142

src/ios/CDVStatusBar.m

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,8 @@ - (void) setStatusBarStyle:(NSString*)statusBarStyle
316316
[self styleDefault:nil];
317317
} else if ([lcStatusBarStyle isEqualToString:@"lightcontent"]) {
318318
[self styleLightContent:nil];
319+
} else if ([lcStatusBarStyle isEqualToString:@"darkcontent"]) {
320+
[self styleDarkContent:nil];
319321
} else if ([lcStatusBarStyle isEqualToString:@"blacktranslucent"]) {
320322
[self styleBlackTranslucent:nil];
321323
} else if ([lcStatusBarStyle isEqualToString:@"blackopaque"]) {
@@ -325,19 +327,23 @@ - (void) setStatusBarStyle:(NSString*)statusBarStyle
325327

326328
- (void) styleDefault:(CDVInvokedUrlCommand*)command
327329
{
328-
if (@available(iOS 13.0, *)) {
329-
// TODO - Replace with UIStatusBarStyleDarkContent once Xcode 10 support is dropped
330-
[self setStyleForStatusBar:3];
331-
} else {
332-
[self setStyleForStatusBar:UIStatusBarStyleDefault];
333-
}
330+
[self setStyleForStatusBar:UIStatusBarStyleDefault];
334331
}
335332

336333
- (void) styleLightContent:(CDVInvokedUrlCommand*)command
337334
{
338335
[self setStyleForStatusBar:UIStatusBarStyleLightContent];
339336
}
340337

338+
- (void) styleDarkContent:(CDVInvokedUrlCommand*)command
339+
{
340+
if (@available(iOS 13.0, *)) {
341+
[self setStyleForStatusBar:UIStatusBarStyleDarkContent];
342+
} else {
343+
[self styleDefault: command];
344+
}
345+
}
346+
341347
- (void) styleBlackTranslucent:(CDVInvokedUrlCommand*)command
342348
{
343349
[self setStyleForStatusBar:UIStatusBarStyleLightContent];

src/windows/StatusBarProxy.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ module.exports = {
8080
}
8181
},
8282

83+
styleDarkContent: function () {
84+
// dark text ( to be used on a light background )
85+
if (isSupported()) {
86+
getViewStatusBar().foregroundColor = { a: 0, r: 0, g: 0, b: 0 };
87+
}
88+
},
89+
8390
styleBlackTranslucent: function () {
8491
// #88000000 ? Apple says to use lightContent instead
8592
return module.exports.styleLightContent();

tests/tests.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ exports.defineAutoTests = function () {
5353
expect(window.StatusBar.styleLightContent).toBeDefined();
5454
expect(typeof window.StatusBar.styleLightContent).toBe('function');
5555

56+
expect(window.StatusBar.styleDarkContent).toBeDefined();
57+
expect(typeof window.StatusBar.styleDarkContent).toBe("function");
58+
5659
expect(window.StatusBar.styleBlackOpaque).toBeDefined();
5760
expect(typeof window.StatusBar.styleBlackOpaque).toBe('function');
5861

@@ -95,6 +98,11 @@ exports.defineManualTests = function (contentEl, createActionButton) {
9598
StatusBar.styleDefault();
9699
}
97100

101+
function doColor4() {
102+
log('set style=darkcontent');
103+
StatusBar.styleDarkContent();
104+
}
105+
98106
var showOverlay = true;
99107
function doOverlay () {
100108
showOverlay = !showOverlay;
@@ -114,6 +122,8 @@ exports.defineManualTests = function (contentEl, createActionButton) {
114122
'</p> <div id="action-color2"></div>' +
115123
'Expected result: Status bar text will be a light (white) color' +
116124
'</p> <div id="action-color3"></div>' +
125+
'Expected result: Status bar text will be a dark (black) color<br>for iOS - a device theme depending (black or white) color' +
126+
'</p> <div id="action-color4"></div>' +
117127
'Expected result: Status bar text will be a dark (black) color' +
118128
'</p> <div id="action-overlays"></div>' +
119129
'Expected result:<br>Overlay true = status bar will lay on top of web view content<br>Overlay false = status bar will be separate from web view and will not cover content' +
@@ -169,11 +179,19 @@ exports.defineManualTests = function (contentEl, createActionButton) {
169179
'action-color3'
170180
);
171181

182+
createActionButton(
183+
'Style=dark',
184+
function () {
185+
doColor4();
186+
},
187+
'action-color4'
188+
);
189+
172190
createActionButton(
173191
'Toggle Overlays',
174192
function () {
175193
doOverlay();
176-
},
194+
},
177195
'action-overlays'
178196
);
179197
};

types/index.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ interface StatusBar {
2626

2727
/**
2828
* Use the default statusbar (dark text, for light backgrounds).
29+
* For iOS - dark or light text depending on a device configuration.
2930
*/
3031
styleDefault(): void;
3132

@@ -34,6 +35,11 @@ interface StatusBar {
3435
*/
3536
styleLightContent(): void;
3637

38+
/**
39+
* Use the darkContent statusbar (dark text, for light backgrounds).
40+
*/
41+
styleDarkContent(): void;
42+
3743
/**
3844
* Use the blackTranslucent statusbar (light text, for dark backgrounds).
3945
*/

www/statusbar.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,20 @@ var StatusBar = {
5353
},
5454

5555
styleDefault: function () {
56-
// dark text ( to be used on a light background )
57-
exec(null, null, 'StatusBar', 'styleDefault', []);
56+
// dark text ( to be used on a light background and on iOS depending on a device configuration )
57+
exec(null, null, "StatusBar", "styleDefault", []);
5858
},
5959

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

65+
styleDarkContent: function () {
66+
// dark text ( to be used on a light background )
67+
exec(null, null, "StatusBar", "styleDarkContent", []);
68+
},
69+
6570
styleBlackTranslucent: function () {
6671
console.warn('styleBlackTranslucent is deprecated and will be removed in next major release, use styleLightContent');
6772
exec(null, null, 'StatusBar', 'styleBlackTranslucent', []);

0 commit comments

Comments
 (0)