Skip to content

Commit

Permalink
refactor(statusbar): change config variables name
Browse files Browse the repository at this point in the history
  • Loading branch information
andredestro committed Aug 22, 2024
1 parent 97bc763 commit e02a3b4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
22 changes: 11 additions & 11 deletions status-bar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ const showStatusBar = async () => {

These config values are available:

| Prop | Type | Description | Default | Since |
| ------------------------------ | -------------------- | -------------------------------------------------------------------------------------------------------------------- | -------------------- | ----- |
| **`StatusBarOverlaysWebView`** | <code>boolean</code> | Whether the statusbar is overlaid or not. | <code>true</code> | 1.0.0 |
| **`StatusBarStyle`** | <code>string</code> | <a href="#style">Style</a> of the text of the status bar. | <code>default</code> | 1.0.0 |
| **`StatusBarBackgroundColor`** | <code>string</code> | Color of the background of the statusbar in hex format, #RRGGBB. Doesn't work if `StatusBarOverlaysWebView` is true. | <code>#000000</code> | 1.0.0 |
| Prop | Type | Description | Default | Since |
| --------------------- | -------------------- | ----------------------------------------------------------------------------------------------------------- | -------------------- | ----- |
| **`overlaysWebView`** | <code>boolean</code> | Whether the statusbar is overlaid or not. | <code>true</code> | 1.0.0 |
| **`style`** | <code>string</code> | <a href="#style">Style</a> of the text of the status bar. | <code>default</code> | 1.0.0 |
| **`backgroundColor`** | <code>string</code> | Color of the background of the statusbar in hex format, #RRGGBB. Doesn't work if `overlaysWebView` is true. | <code>#000000</code> | 1.0.0 |

### Examples

Expand All @@ -71,9 +71,9 @@ In `capacitor.config.json`:
{
"plugins": {
"StatusBar": {
"StatusBarOverlaysWebView": false,
"StatusBarStyle": "DARK",
"StatusBarBackgroundColor": "#ffffffff"
"overlaysWebView": false,
"style": "DARK",
"backgroundColor": "#ffffffff"
}
}
}
Expand All @@ -89,9 +89,9 @@ import { CapacitorConfig } from '@capacitor/cli';
const config: CapacitorConfig = {
plugins: {
StatusBar: {
StatusBarOverlaysWebView: false,
StatusBarStyle: "DARK",
StatusBarBackgroundColor: "#ffffffff",
overlaysWebView: false,
style: "DARK",
backgroundColor: "#ffffffff",
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,26 @@ public void load() {

private StatusBarConfig getStatusBarConfig() {
StatusBarConfig config = new StatusBarConfig();
String backgroundColor = getConfig().getString("StatusBarBackgroundColor");
String backgroundColor = getConfig().getString("backgroundColor");
if (backgroundColor != null) {
try {
config.setBackgroundColor(WebColor.parseColor(backgroundColor));
} catch (IllegalArgumentException ex) {
Logger.debug("Background color not applied");
}
}
config.setStyle(styleFromConfig(getConfig().getString("StatusBarStyle", config.getStyle())));
config.setOverlaysWebView(getConfig().getBoolean("StatusBarOverlaysWebView", config.isOverlaysWebView()));
config.setStyle(styleFromConfig(getConfig().getString("style", config.getStyle())));
config.setOverlaysWebView(getConfig().getBoolean("overlaysWebView", config.isOverlaysWebView()));
return config;
}

private String styleFromConfig(String style) {
switch (style.toLowerCase()) {
case "lightcontent":
case "dark":
return "DARK";
case "darkcontent":
case "light":
return "LIGHT";
case "default":
default:
Expand Down
6 changes: 3 additions & 3 deletions status-bar/ios/Sources/StatusBarPlugin/StatusBarPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public class StatusBarPlugin: CAPPlugin, CAPBridgedPlugin {

private func statusBarConfig() -> StatusBarConfig {
var config = StatusBarConfig()
config.overlaysWebView = getConfig().getBoolean("StatusBarOverlaysWebView", config.overlaysWebView)
if let colorConfig = getConfig().getString("StatusBarBackgroundColor"), let color = UIColor.capacitor.color(fromHex: colorConfig)
config.overlaysWebView = getConfig().getBoolean("overlaysWebView", config.overlaysWebView)
if let colorConfig = getConfig().getString("backgroundColor"), let color = UIColor.capacitor.color(fromHex: colorConfig)
{
config.backgroundColor = color
}
if let configStyle = getConfig().getString("StatusBarStyle") {
if let configStyle = getConfig().getString("style") {
config.style = style(fromString: configStyle)
}
return config
Expand Down
8 changes: 4 additions & 4 deletions status-bar/src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ declare module '@capacitor/cli' {
* @default true
* @example false
*/
StatusBarOverlaysWebView?: boolean;
overlaysWebView?: boolean;

/**
* Style of the text of the status bar.
Expand All @@ -22,17 +22,17 @@ declare module '@capacitor/cli' {
* @default default
* @example "DARK"
*/
StatusBarStyle?: string;
style?: string;

/**
* Color of the background of the statusbar in hex format, #RRGGBB.
* Doesn't work if `StatusBarOverlaysWebView` is true.
* Doesn't work if `overlaysWebView` is true.
*
* @since 1.0.0
* @default #000000
* @example "#ffffffff"
*/
StatusBarBackgroundColor?: string;
backgroundColor?: string;
};
}
}
Expand Down

0 comments on commit e02a3b4

Please sign in to comment.