Skip to content

Commit a4bec91

Browse files
authored
feat: Android Edge-to-Edge styling options (#440)
* feat(android): plugin configs Define and implement plugin configs. * feat(android): plugin configs Remove extra example. * feat(android): plugin configs Generate changeset. * feat(android): plugin configs Run fmt script. * feat(android): plugin configs Move plugin config initialization and add docs to readme.
1 parent b07a02a commit a4bec91

6 files changed

Lines changed: 99 additions & 3 deletions

File tree

.changeset/quick-days-count.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@capawesome/capacitor-android-edge-to-edge-support': minor
3+
---
4+
5+
feat: support styling options with plugin configs

packages/android-edge-to-edge-support/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,49 @@ npm install @capawesome/capacitor-android-edge-to-edge-support
1313
npx cap sync
1414
```
1515

16+
## Configuration
17+
18+
<docgen-config>
19+
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
20+
21+
| Prop | Type | Description | Since |
22+
| --------------------- | ------------------- | ------------------------------------------------------------------------------------------ | ----- |
23+
| **`backgroundColor`** | <code>string</code> | The hexadecimal color to set as the background color of the status bar and navigation bar. | 7.1.0 |
24+
25+
### Examples
26+
27+
In `capacitor.config.json`:
28+
29+
```json
30+
{
31+
"plugins": {
32+
"EdgeToEdge": {
33+
"backgroundColor": "#ffffff"
34+
}
35+
}
36+
}
37+
```
38+
39+
In `capacitor.config.ts`:
40+
41+
```ts
42+
/// <reference types="@capawesome/capacitor-android-edge-to-edge-support" />
43+
44+
import { CapacitorConfig } from '@capacitor/cli';
45+
46+
const config: CapacitorConfig = {
47+
plugins: {
48+
EdgeToEdge: {
49+
backgroundColor: "#ffffff",
50+
},
51+
},
52+
};
53+
54+
export default config;
55+
```
56+
57+
</docgen-config>
58+
1659
## Usage
1760

1861
The plugin **only needs to be installed**. It applies insets to the web view to support edge-to-edge display on Android. The plugin also provides a method to set the background color of the status bar and navigation bar. It's recommended to use this method in combination with the [Status Bar](https://capacitorjs.com/docs/apis/status-bar) plugin.

packages/android-edge-to-edge-support/android/src/main/java/io/capawesome/capacitorjs/plugins/androidedgetoedgesupport/EdgeToEdge.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@
1111

1212
public class EdgeToEdge {
1313

14+
@NonNull
15+
private final EdgeToEdgeConfig config;
16+
1417
@NonNull
1518
private final EdgeToEdgePlugin plugin;
1619

17-
public EdgeToEdge(@NonNull EdgeToEdgePlugin plugin) {
20+
public EdgeToEdge(@NonNull EdgeToEdgePlugin plugin, @NonNull EdgeToEdgeConfig config) {
21+
this.config = config;
1822
this.plugin = plugin;
1923
// Apply insets to disable the edge-to-edge feature
2024
applyInsets();
@@ -39,7 +43,7 @@ private void applyInsets() {
3943
// Get parent view
4044
ViewGroup parent = (ViewGroup) view.getParent();
4145
// Set background color to black
42-
parent.setBackgroundColor(Color.WHITE);
46+
parent.setBackgroundColor(this.config.getBackgroundColor());
4347
// Apply insets to disable the edge-to-edge feature
4448
ViewCompat.setOnApplyWindowInsetsListener(view, (v, windowInsets) -> {
4549
Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package io.capawesome.capacitorjs.plugins.androidedgetoedgesupport;
2+
3+
import android.graphics.Color;
4+
5+
public class EdgeToEdgeConfig {
6+
7+
private int backgroundColor = Color.WHITE;
8+
9+
public int getBackgroundColor() {
10+
return this.backgroundColor;
11+
}
12+
13+
public void setBackgroundColor(int backgroundColor) {
14+
this.backgroundColor = backgroundColor;
15+
}
16+
}

packages/android-edge-to-edge-support/android/src/main/java/io/capawesome/capacitorjs/plugins/androidedgetoedgesupport/EdgeToEdgePlugin.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.capawesome.capacitorjs.plugins.androidedgetoedgesupport;
22

3+
import android.graphics.Color;
34
import androidx.annotation.Nullable;
45
import com.getcapacitor.Plugin;
56
import com.getcapacitor.PluginCall;
@@ -17,7 +18,8 @@ public class EdgeToEdgePlugin extends Plugin {
1718

1819
@Override
1920
public void load() {
20-
implementation = new EdgeToEdge(this);
21+
EdgeToEdgeConfig config = getEdgeToEdgeConfig();
22+
implementation = new EdgeToEdge(this, config);
2123
}
2224

2325
@PluginMethod
@@ -30,4 +32,14 @@ public void setBackgroundColor(PluginCall call) {
3032
implementation.setBackgroundColor(color);
3133
call.resolve();
3234
}
35+
36+
private EdgeToEdgeConfig getEdgeToEdgeConfig() {
37+
EdgeToEdgeConfig config = new EdgeToEdgeConfig();
38+
39+
String backgroundColor = getConfig().getString("backgroundColor");
40+
if (backgroundColor != null) {
41+
config.setBackgroundColor(Color.parseColor(backgroundColor));
42+
}
43+
return config;
44+
}
3345
}

packages/android-edge-to-edge-support/src/definitions.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/// <reference types="@capacitor/cli" />
2+
3+
declare module '@capacitor/cli' {
4+
export interface PluginsConfig {
5+
EdgeToEdge?: {
6+
/**
7+
* The hexadecimal color to set as the background color of the status bar and navigation bar.
8+
*
9+
* @since 7.1.0
10+
* @example "#ffffff"
11+
*/
12+
backgroundColor?: string;
13+
};
14+
}
15+
}
16+
117
export interface EdgeToEdgePlugin {
218
/**
319
* Set the background color of the status bar and navigation bar.

0 commit comments

Comments
 (0)