Skip to content

Commit

Permalink
Revert "feat(statusbar)!: implement overlay and background color in i…
Browse files Browse the repository at this point in the history
…OS (#2179)"

This reverts commit 88228ac.
  • Loading branch information
IT-MikeS committed Oct 11, 2024
1 parent 8e91a6a commit 9414673
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 547 deletions.
78 changes: 17 additions & 61 deletions status-bar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ The status bar visibility defaults to visible and the style defaults to
`Style.Default`. You can change these defaults by adding
`UIStatusBarHidden` and/or `UIStatusBarStyle` in `Info.plist`.

`setBackgroundColor` and `setOverlaysWebView` are currently not supported on
iOS devices.

## Example

```typescript
Expand All @@ -30,7 +33,7 @@ window.addEventListener('statusTap', function () {
console.log('statusbar tapped');
});

// Display content under transparent status bar
// Display content under transparent status bar (Android only)
StatusBar.setOverlaysWebView({ overlay: true });

const setStatusBarStyleDark = async () => {
Expand All @@ -50,57 +53,6 @@ const showStatusBar = async () => {
};
```

## Configuration

<docgen-config>
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->

These config values are available:

| 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

In `capacitor.config.json`:

```json
{
"plugins": {
"StatusBar": {
"overlaysWebView": false,
"style": "DARK",
"backgroundColor": "#ffffffff"
}
}
}
```

In `capacitor.config.ts`:

```ts
/// <reference types="@capacitor/status-bar" />

import { CapacitorConfig } from '@capacitor/cli';

const config: CapacitorConfig = {
plugins: {
StatusBar: {
overlaysWebView: false,
style: "DARK",
backgroundColor: "#ffffffff",
},
},
};

export default config;
```

</docgen-config>

## API

<docgen-index>
Expand Down Expand Up @@ -144,6 +96,8 @@ setBackgroundColor(options: BackgroundColorOptions) => Promise<void>

Set the background color of the status bar.

This method is only supported on Android.

| Param | Type |
| ------------- | ------------------------------------------------------------------------- |
| **`options`** | <code><a href="#backgroundcoloroptions">BackgroundColorOptions</a></code> |
Expand Down Expand Up @@ -215,6 +169,8 @@ setOverlaysWebView(options: SetOverlaysWebViewOptions) => Promise<void>
Set whether or not the status bar should overlay the webview to allow usage
of the space underneath it.

This method is only supported on Android.

| Param | Type |
| ------------- | ------------------------------------------------------------------------------- |
| **`options`** | <code><a href="#setoverlayswebviewoptions">SetOverlaysWebViewOptions</a></code> |
Expand All @@ -236,9 +192,9 @@ of the space underneath it.

#### BackgroundColorOptions

| Prop | Type | Description | Since |
| ----------- | ------------------- | ------------------------------------------------- | ----- |
| **`color`** | <code>string</code> | A hex color to which the status bar color is set. | 1.0.0 |
| Prop | Type | Description | Since |
| ----------- | ------------------- | ------------------------------------------------------------------------------------------- | ----- |
| **`color`** | <code>string</code> | A hex color to which the status bar color is set. This option is only supported on Android. | 1.0.0 |


#### AnimationOptions
Expand All @@ -250,12 +206,12 @@ of the space underneath it.

#### StatusBarInfo

| Prop | Type | Description | Since |
| -------------- | --------------------------------------- | ----------------------------------------- | ----- |
| **`visible`** | <code>boolean</code> | Whether the status bar is visible or not. | 1.0.0 |
| **`style`** | <code><a href="#style">Style</a></code> | The current status bar style. | 1.0.0 |
| **`color`** | <code>string</code> | The current status bar color. | 1.0.0 |
| **`overlays`** | <code>boolean</code> | Whether the statusbar is overlaid or not. | 1.0.0 |
| Prop | Type | Description | Since |
| -------------- | --------------------------------------- | ----------------------------------------------------------------------------------- | ----- |
| **`visible`** | <code>boolean</code> | Whether the status bar is visible or not. | 1.0.0 |
| **`style`** | <code><a href="#style">Style</a></code> | The current status bar style. | 1.0.0 |
| **`color`** | <code>string</code> | The current status bar color. This option is only supported on Android. | 1.0.0 |
| **`overlays`** | <code>boolean</code> | Whether the statusbar is overlaid or not. This option is only supported on Android. | 1.0.0 |


#### SetOverlaysWebViewOptions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.capacitorjs.plugins.statusbar;

import android.graphics.Color;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
Expand All @@ -17,15 +16,11 @@ public class StatusBar {
private final AppCompatActivity activity;
private final String defaultStyle;

public StatusBar(AppCompatActivity activity, StatusBarConfig config) {
public StatusBar(AppCompatActivity activity) {
// save initial color of the status bar
this.activity = activity;
this.currentStatusBarColor = activity.getWindow().getStatusBarColor();
this.defaultStyle = getStyle();

setBackgroundColor(config.getBackgroundColor());
setStyle(config.getStyle());
setOverlaysWebView(config.isOverlaysWebView());
}

public void setStyle(String style) {
Expand Down Expand Up @@ -98,7 +93,6 @@ public StatusBarInfo getInfo() {
info.setOverlays(getIsOverlaid());
info.setVisible(isVisible);
info.setColor(String.format("#%06X", (0xFFFFFF & window.getStatusBarColor())));
info.setHeight(getStatusBarHeight());
return info;
}

Expand All @@ -111,17 +105,4 @@ private String getStyle() {
}
return style;
}

private int getStatusBarHeight() {
int statusbarHeight = 0;
int resourceId = activity.getApplicationContext().getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
statusbarHeight = (int) activity.getApplicationContext().getResources().getDimension(resourceId);
}

DisplayMetrics metrics = activity.getApplicationContext().getResources().getDisplayMetrics();
float densityDpi = metrics.density;

return (int) (statusbarHeight / densityDpi);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package com.capacitorjs.plugins.statusbar;

import java.io.Serializable;

public class StatusBarInfo implements Serializable {
public class StatusBarInfo {

private boolean overlays;
private boolean visible;
private String style;
private String color;
private int height;

public boolean isOverlays() {
return overlays;
Expand Down Expand Up @@ -41,12 +38,4 @@ public String getColor() {
public void setColor(String color) {
this.color = color;
}

public int getHeight() {
return height;
}

public void setHeight(int height) {
this.height = height;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.capacitorjs.plugins.statusbar;

import com.getcapacitor.JSObject;
import com.getcapacitor.Logger;
import com.getcapacitor.Plugin;
import com.getcapacitor.PluginCall;
import com.getcapacitor.PluginMethod;
Expand All @@ -12,44 +11,11 @@
@CapacitorPlugin(name = "StatusBar")
public class StatusBarPlugin extends Plugin {

public static final String statusBarVisibilityChanged = "statusBarVisibilityChanged";
public static final String statusBarOverlayChanged = "statusBarOverlayChanged";

private StatusBar implementation;

@Override
public void load() {
StatusBarConfig config = getStatusBarConfig();
implementation = new StatusBar(getActivity(), config);
}

private StatusBarConfig getStatusBarConfig() {
StatusBarConfig config = new StatusBarConfig();
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("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:
return "DEFAULT";
}
implementation = new StatusBar(getActivity());
}

@PluginMethod
Expand Down Expand Up @@ -98,8 +64,6 @@ public void hide(final PluginCall call) {
.executeOnMainThread(
() -> {
implementation.hide();
StatusBarInfo info = implementation.getInfo();
notifyListeners(statusBarVisibilityChanged, toJSObject(info));
call.resolve();
}
);
Expand All @@ -112,8 +76,6 @@ public void show(final PluginCall call) {
.executeOnMainThread(
() -> {
implementation.show();
StatusBarInfo info = implementation.getInfo();
notifyListeners(statusBarVisibilityChanged, toJSObject(info));
call.resolve();
}
);
Expand All @@ -122,7 +84,13 @@ public void show(final PluginCall call) {
@PluginMethod
public void getInfo(final PluginCall call) {
StatusBarInfo info = implementation.getInfo();
call.resolve(toJSObject(info));

JSObject data = new JSObject();
data.put("visible", info.isVisible());
data.put("style", info.getStyle());
data.put("color", info.getColor());
data.put("overlays", info.isOverlays());
call.resolve(data);
}

@PluginMethod
Expand All @@ -132,20 +100,8 @@ public void setOverlaysWebView(final PluginCall call) {
.executeOnMainThread(
() -> {
implementation.setOverlaysWebView(overlays);
StatusBarInfo info = implementation.getInfo();
notifyListeners(statusBarOverlayChanged, toJSObject(info));
call.resolve();
}
);
}

private JSObject toJSObject(StatusBarInfo info) {
JSObject data = new JSObject();
data.put("visible", info.isVisible());
data.put("style", info.getStyle());
data.put("color", info.getColor());
data.put("overlays", info.isOverlays());
data.put("height", info.getHeight());
return data;
}
}

This file was deleted.

6 changes: 0 additions & 6 deletions status-bar/ios/Sources/StatusBarPlugin/CAPNotifications.swift

This file was deleted.

Loading

0 comments on commit 9414673

Please sign in to comment.