@hiloenergie/capacitor-plugin-safe-area 0.0.10 → 0.0.12-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HiloenergieCapacitorPluginSafeArea.podspec +17 -17
- package/README.md +225 -225
- package/android/build.gradle +58 -58
- package/android/src/main/AndroidManifest.xml +2 -2
- package/android/src/main/java/com/getcapacitor/community/plugins/safearea/SafeAreaPlugin.java +158 -158
- package/android/src/main/java/com/getcapacitor/community/plugins/safearea/SafeAreaView.java +48 -48
- package/dist/docs.json +3 -3
- package/dist/esm/controller.js +1 -1
- package/dist/esm/controller.js.map +1 -1
- package/dist/esm/definitions.d.ts +1 -1
- package/dist/plugin.cjs.js +1 -1
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +1 -1
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/SafeAreaPlugin.swift +25 -71
- package/package.json +7 -7
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
require 'json'
|
|
2
|
-
|
|
3
|
-
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
|
-
|
|
5
|
-
Pod::Spec.new do |s|
|
|
6
|
-
s.name = 'HiloenergieCapacitorPluginSafeArea'
|
|
7
|
-
s.version = package['version']
|
|
8
|
-
s.summary = package['description']
|
|
9
|
-
s.license = package['license']
|
|
10
|
-
s.homepage = package['repository']['url']
|
|
11
|
-
s.author = package['author']
|
|
12
|
-
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
|
|
13
|
-
s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
|
|
14
|
-
s.ios.deployment_target = '14.0'
|
|
15
|
-
s.dependency 'Capacitor'
|
|
16
|
-
s.swift_version = '5.1'
|
|
17
|
-
end
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'HiloenergieCapacitorPluginSafeArea'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.license = package['license']
|
|
10
|
+
s.homepage = package['repository']['url']
|
|
11
|
+
s.author = package['author']
|
|
12
|
+
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
|
|
13
|
+
s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
|
|
14
|
+
s.ios.deployment_target = '14.0'
|
|
15
|
+
s.dependency 'Capacitor'
|
|
16
|
+
s.swift_version = '5.1'
|
|
17
|
+
end
|
package/README.md
CHANGED
|
@@ -1,225 +1,225 @@
|
|
|
1
|
-
<p align="center"><br><img src="https://user-images.githubusercontent.com/236501/85893648-1c92e880-b7a8-11ea-926d-95355b8175c7.png" width="128" height="128" /></p>
|
|
2
|
-
<h3 align="center">Safe Area</h3>
|
|
3
|
-
<p align="center"><strong><code>@capacitor-community/safe-area</code></strong></p>
|
|
4
|
-
<p align="center">
|
|
5
|
-
A plugin to expose the safe area insets from the native iOS/Android device to your web project.
|
|
6
|
-
</p>
|
|
7
|
-
|
|
8
|
-
<p align="center">
|
|
9
|
-
<img src="https://img.shields.io/maintenance/yes/2020?style=flat-square" />
|
|
10
|
-
<a href="https://github.com/capacitor-community/safe-area/actions?query=workflow%3A%22CI%22"><img src="https://img.shields.io/github/workflow/status/capacitor-community/safe-area/CI?style=flat-square" /></a>
|
|
11
|
-
<a href="https://www.npmjs.com/package/@capacitor-community/safe-area"><img src="https://img.shields.io/npm/l/@capacitor-community/safe-area?style=flat-square" /></a>
|
|
12
|
-
<br>
|
|
13
|
-
<a href="https://www.npmjs.com/package/@capacitor-community/safe-area"><img src="https://img.shields.io/npm/dw/@capacitor-community/safe-area?style=flat-square" /></a>
|
|
14
|
-
<a href="https://www.npmjs.com/package/@capacitor-community/safe-area"><img src="https://img.shields.io/npm/v/@capacitor-community/safe-area?style=flat-square" /></a>
|
|
15
|
-
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
16
|
-
<a href="#contributors-"><img src="https://img.shields.io/badge/all%20contributors-0-orange?style=flat-square" /></a>
|
|
17
|
-
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
18
|
-
</p>
|
|
19
|
-
|
|
20
|
-
## Maintainers
|
|
21
|
-
|
|
22
|
-
***This is a fork of [@capacitor-community/safe-area](https://github.com/capacitor-community/safe-area). Please make sure to sync up with the public package through pull requests so that we can eventually switch back to the
|
|
23
|
-
official plugin.***
|
|
24
|
-
|
|
25
|
-
| Maintainer | GitHub | Social |
|
|
26
|
-
| -----------| -------| -------|
|
|
27
|
-
| Kevin Pacheco | [PolymorphiK](https://github.com/PolymorphiK) | [@k_pacheco10](https://twitter.com/k_pacheco10) |
|
|
28
|
-
|
|
29
|
-
## Installation
|
|
30
|
-
|
|
31
|
-
Soon(TM)
|
|
32
|
-
|
|
33
|
-
## Configuration
|
|
34
|
-
|
|
35
|
-
For Android, register plugin in your main activity.
|
|
36
|
-
|
|
37
|
-
```java
|
|
38
|
-
import com.getcapacitor.community.safearea.SafeAreaPlugin;
|
|
39
|
-
|
|
40
|
-
public class MainActivity extends BridgeActivity {
|
|
41
|
-
@Override
|
|
42
|
-
public void onCreate(Bundle savedInstanceState) {
|
|
43
|
-
super.onCreate(savedInstanceState);
|
|
44
|
-
|
|
45
|
-
this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
|
|
46
|
-
add(SafeAreaPlugin.class);
|
|
47
|
-
}});
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
```
|
|
51
|
-
Here is a bonus tip, to get full screen mode use this in your main activity. Requires Android **28+**
|
|
52
|
-
|
|
53
|
-
```java
|
|
54
|
-
@Override
|
|
55
|
-
public void onResume() {
|
|
56
|
-
super.onResume();
|
|
57
|
-
|
|
58
|
-
// Requires API 28+
|
|
59
|
-
this.getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
|
|
60
|
-
|
|
61
|
-
View decorView = this.getWindow().getDecorView();
|
|
62
|
-
|
|
63
|
-
decorView.setSystemUiVisibility(
|
|
64
|
-
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
|
65
|
-
// Set the content to appear under the system bars so that the
|
|
66
|
-
// content doesn't resize when the system bars hide and show.
|
|
67
|
-
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
|
68
|
-
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
|
69
|
-
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
|
70
|
-
// Hide the nav bar and status bar
|
|
71
|
-
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
|
72
|
-
| View.SYSTEM_UI_FLAG_FULLSCREEN);
|
|
73
|
-
}
|
|
74
|
-
```
|
|
75
|
-
To change the Android build version, change the **minSdkVersion** to at least 28 in the **variables.gradle** file. <br />
|
|
76
|
-
For more information please see Android's [immersive](https://developer.android.com/training/system-ui/immersive), and [short edges](https://developer.android.com/reference/android/view/WindowManager.LayoutParams#LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES) documentation.
|
|
77
|
-
|
|
78
|
-
## Usage
|
|
79
|
-
Register the plugin via the entry file of your project.
|
|
80
|
-
|
|
81
|
-
```javascript
|
|
82
|
-
// Register Capacitor Plugin...
|
|
83
|
-
import '@capacitor-community/safe-area';
|
|
84
|
-
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
It is **strongly** recomended that you use the **SafeAreaController** as it makes it super easy to use the plugin :)
|
|
88
|
-
|
|
89
|
-
```javascript
|
|
90
|
-
import { SafeAreaController } from '@capacitor-community/safe-area';
|
|
91
|
-
|
|
92
|
-
// Initialize the controller.
|
|
93
|
-
SafeAreaController.load();
|
|
94
|
-
|
|
95
|
-
// Gets the insets object
|
|
96
|
-
// Shape
|
|
97
|
-
/*
|
|
98
|
-
{
|
|
99
|
-
top: number,
|
|
100
|
-
bottom: number,
|
|
101
|
-
right: number,
|
|
102
|
-
left: number,
|
|
103
|
-
}
|
|
104
|
-
*/
|
|
105
|
-
SafeAreaController.getInsets();
|
|
106
|
-
|
|
107
|
-
// Use this to listen for changes in the insets.
|
|
108
|
-
// i.e. when the device is rotated
|
|
109
|
-
SafeAreaController.addListener((insets) => {
|
|
110
|
-
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
// Use this to force the plugin to invoke the event
|
|
114
|
-
// Example, after you add a listener perhaps you invoke refresh
|
|
115
|
-
// to get the most up-to-date inset values.
|
|
116
|
-
SafeAreaController.refresh();
|
|
117
|
-
|
|
118
|
-
// Uninitialize the controller when you don't need it anymore.
|
|
119
|
-
SafeAreaController.unload();
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
Once the **SafeAreaController** has been loaded, it will inject CSS variables for you to use in your style sheets.
|
|
123
|
-
|
|
124
|
-
```css
|
|
125
|
-
/* styling for every case Web, iOS, and/or Android */
|
|
126
|
-
.myContainer {
|
|
127
|
-
paddingTop: max(1.5rem, val(--safe-area-inset-top));
|
|
128
|
-
paddingLeft: max(1.5rem, val(--safe-area-inset-left));
|
|
129
|
-
paddingRight: max(1.5rem, val(--safe-area-inset-right));
|
|
130
|
-
paddingBottom: val(--safe-area-inset-bottom);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/* If you need Android specific stying */
|
|
134
|
-
.myContainerForAndroidOnly {
|
|
135
|
-
paddingTop: max(1.5rem, val(--android-safe-area-inset-top));
|
|
136
|
-
paddingLeft: max(1.5rem, val(--android-safe-area-inset-left));
|
|
137
|
-
paddingRight: max(1.5rem, val(--android-safe-area-inset-right));
|
|
138
|
-
paddingBottom: val(--android-safe-area-inset-bottom);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/* If you need iOS specific styling */
|
|
142
|
-
.myContainerForIOSOnly {
|
|
143
|
-
paddingTop: max(1.5rem, val(--ios-safe-area-inset-top));
|
|
144
|
-
paddingLeft: max(1.5rem, val(--ios-safe-area-inset-left));
|
|
145
|
-
paddingRight: max(1.5rem, val(--ios-safe-area-inset-right));
|
|
146
|
-
paddingBottom: val(--ios-safe-area-inset-bottom);
|
|
147
|
-
}
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
This can also be used with the styles attribute in something like React.js for example.
|
|
151
|
-
```jsx
|
|
152
|
-
// This div will grow to cover the area of the cutout
|
|
153
|
-
// this would be at the very top.
|
|
154
|
-
<div
|
|
155
|
-
style={{
|
|
156
|
-
height: "var(--safe-area-inset-top)",
|
|
157
|
-
backgroundColor: "#12005e"
|
|
158
|
-
}}>
|
|
159
|
-
</div>
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
<details>
|
|
163
|
-
<summary>React - SafeAreaInsetsProvider</summary>
|
|
164
|
-
|
|
165
|
-
Here is a component that can be used by React.js developers. This handles everything for you via the SafeAreaController. There is a hook you can use as well called **useSafeAreaInsetsState** which will return a JSON object with top, bottom, right, and left number properties.
|
|
166
|
-
|
|
167
|
-
```javascript
|
|
168
|
-
import * as React from 'react';
|
|
169
|
-
import { SafeAreaController } from '@capacitor-community/safe-area';
|
|
170
|
-
|
|
171
|
-
const StateContext = React.createContext();
|
|
172
|
-
|
|
173
|
-
export const useSafeAreaInsetsState = () => {
|
|
174
|
-
const context = React.useContext(StateContext);
|
|
175
|
-
|
|
176
|
-
if(context === undefined)
|
|
177
|
-
throw new Error("Cannot use 'useSafeAreaInsetsState' outside of a SafeAreaInsetsProvider!");
|
|
178
|
-
|
|
179
|
-
return context;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
const SafeAreaInsetsProvider = ({children}) => {
|
|
183
|
-
const [state, setState] = React.useState({
|
|
184
|
-
top: 0,
|
|
185
|
-
bottom: 0,
|
|
186
|
-
right: 0,
|
|
187
|
-
left: 0
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
React.useState(() => {
|
|
191
|
-
SafeAreaController.addListener((insets) => {
|
|
192
|
-
setState(insets);
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
SafeAreaController.load();
|
|
196
|
-
|
|
197
|
-
return () => {
|
|
198
|
-
SafeAreaController.removeAllListeners();
|
|
199
|
-
SafeAreaController.unload();
|
|
200
|
-
}
|
|
201
|
-
}, []);
|
|
202
|
-
|
|
203
|
-
return (
|
|
204
|
-
<StateContext.Provider value={state}>
|
|
205
|
-
{children}
|
|
206
|
-
</StateContext.Provider>
|
|
207
|
-
)
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
export default SafeAreaInsetsProvider;
|
|
211
|
-
```
|
|
212
|
-
|
|
213
|
-
You can then use this provider ideally in the **index** file of your project.
|
|
214
|
-
|
|
215
|
-
```javascript
|
|
216
|
-
ReactDOM.render(
|
|
217
|
-
<React.StrictMode>
|
|
218
|
-
<SafeAreaInsetsProvider>
|
|
219
|
-
<App />
|
|
220
|
-
</SafeAreaInsetsProvider>
|
|
221
|
-
</React.StrictMode>,
|
|
222
|
-
document.getElementById('root')
|
|
223
|
-
);
|
|
224
|
-
```
|
|
225
|
-
</details>
|
|
1
|
+
<p align="center"><br><img src="https://user-images.githubusercontent.com/236501/85893648-1c92e880-b7a8-11ea-926d-95355b8175c7.png" width="128" height="128" /></p>
|
|
2
|
+
<h3 align="center">Safe Area</h3>
|
|
3
|
+
<p align="center"><strong><code>@capacitor-community/safe-area</code></strong></p>
|
|
4
|
+
<p align="center">
|
|
5
|
+
A plugin to expose the safe area insets from the native iOS/Android device to your web project.
|
|
6
|
+
</p>
|
|
7
|
+
|
|
8
|
+
<p align="center">
|
|
9
|
+
<img src="https://img.shields.io/maintenance/yes/2020?style=flat-square" />
|
|
10
|
+
<a href="https://github.com/capacitor-community/safe-area/actions?query=workflow%3A%22CI%22"><img src="https://img.shields.io/github/workflow/status/capacitor-community/safe-area/CI?style=flat-square" /></a>
|
|
11
|
+
<a href="https://www.npmjs.com/package/@capacitor-community/safe-area"><img src="https://img.shields.io/npm/l/@capacitor-community/safe-area?style=flat-square" /></a>
|
|
12
|
+
<br>
|
|
13
|
+
<a href="https://www.npmjs.com/package/@capacitor-community/safe-area"><img src="https://img.shields.io/npm/dw/@capacitor-community/safe-area?style=flat-square" /></a>
|
|
14
|
+
<a href="https://www.npmjs.com/package/@capacitor-community/safe-area"><img src="https://img.shields.io/npm/v/@capacitor-community/safe-area?style=flat-square" /></a>
|
|
15
|
+
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
16
|
+
<a href="#contributors-"><img src="https://img.shields.io/badge/all%20contributors-0-orange?style=flat-square" /></a>
|
|
17
|
+
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
18
|
+
</p>
|
|
19
|
+
|
|
20
|
+
## Maintainers
|
|
21
|
+
|
|
22
|
+
***This is a fork of [@capacitor-community/safe-area](https://github.com/capacitor-community/safe-area). Please make sure to sync up with the public package through pull requests so that we can eventually switch back to the
|
|
23
|
+
official plugin.***
|
|
24
|
+
|
|
25
|
+
| Maintainer | GitHub | Social |
|
|
26
|
+
| -----------| -------| -------|
|
|
27
|
+
| Kevin Pacheco | [PolymorphiK](https://github.com/PolymorphiK) | [@k_pacheco10](https://twitter.com/k_pacheco10) |
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
Soon(TM)
|
|
32
|
+
|
|
33
|
+
## Configuration
|
|
34
|
+
|
|
35
|
+
For Android, register plugin in your main activity.
|
|
36
|
+
|
|
37
|
+
```java
|
|
38
|
+
import com.getcapacitor.community.safearea.SafeAreaPlugin;
|
|
39
|
+
|
|
40
|
+
public class MainActivity extends BridgeActivity {
|
|
41
|
+
@Override
|
|
42
|
+
public void onCreate(Bundle savedInstanceState) {
|
|
43
|
+
super.onCreate(savedInstanceState);
|
|
44
|
+
|
|
45
|
+
this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
|
|
46
|
+
add(SafeAreaPlugin.class);
|
|
47
|
+
}});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
Here is a bonus tip, to get full screen mode use this in your main activity. Requires Android **28+**
|
|
52
|
+
|
|
53
|
+
```java
|
|
54
|
+
@Override
|
|
55
|
+
public void onResume() {
|
|
56
|
+
super.onResume();
|
|
57
|
+
|
|
58
|
+
// Requires API 28+
|
|
59
|
+
this.getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
|
|
60
|
+
|
|
61
|
+
View decorView = this.getWindow().getDecorView();
|
|
62
|
+
|
|
63
|
+
decorView.setSystemUiVisibility(
|
|
64
|
+
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
|
65
|
+
// Set the content to appear under the system bars so that the
|
|
66
|
+
// content doesn't resize when the system bars hide and show.
|
|
67
|
+
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
|
68
|
+
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
|
69
|
+
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
|
70
|
+
// Hide the nav bar and status bar
|
|
71
|
+
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
|
72
|
+
| View.SYSTEM_UI_FLAG_FULLSCREEN);
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
To change the Android build version, change the **minSdkVersion** to at least 28 in the **variables.gradle** file. <br />
|
|
76
|
+
For more information please see Android's [immersive](https://developer.android.com/training/system-ui/immersive), and [short edges](https://developer.android.com/reference/android/view/WindowManager.LayoutParams#LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES) documentation.
|
|
77
|
+
|
|
78
|
+
## Usage
|
|
79
|
+
Register the plugin via the entry file of your project.
|
|
80
|
+
|
|
81
|
+
```javascript
|
|
82
|
+
// Register Capacitor Plugin...
|
|
83
|
+
import '@capacitor-community/safe-area';
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
It is **strongly** recomended that you use the **SafeAreaController** as it makes it super easy to use the plugin :)
|
|
88
|
+
|
|
89
|
+
```javascript
|
|
90
|
+
import { SafeAreaController } from '@capacitor-community/safe-area';
|
|
91
|
+
|
|
92
|
+
// Initialize the controller.
|
|
93
|
+
SafeAreaController.load();
|
|
94
|
+
|
|
95
|
+
// Gets the insets object
|
|
96
|
+
// Shape
|
|
97
|
+
/*
|
|
98
|
+
{
|
|
99
|
+
top: number,
|
|
100
|
+
bottom: number,
|
|
101
|
+
right: number,
|
|
102
|
+
left: number,
|
|
103
|
+
}
|
|
104
|
+
*/
|
|
105
|
+
SafeAreaController.getInsets();
|
|
106
|
+
|
|
107
|
+
// Use this to listen for changes in the insets.
|
|
108
|
+
// i.e. when the device is rotated
|
|
109
|
+
SafeAreaController.addListener((insets) => {
|
|
110
|
+
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// Use this to force the plugin to invoke the event
|
|
114
|
+
// Example, after you add a listener perhaps you invoke refresh
|
|
115
|
+
// to get the most up-to-date inset values.
|
|
116
|
+
SafeAreaController.refresh();
|
|
117
|
+
|
|
118
|
+
// Uninitialize the controller when you don't need it anymore.
|
|
119
|
+
SafeAreaController.unload();
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Once the **SafeAreaController** has been loaded, it will inject CSS variables for you to use in your style sheets.
|
|
123
|
+
|
|
124
|
+
```css
|
|
125
|
+
/* styling for every case Web, iOS, and/or Android */
|
|
126
|
+
.myContainer {
|
|
127
|
+
paddingTop: max(1.5rem, val(--safe-area-inset-top));
|
|
128
|
+
paddingLeft: max(1.5rem, val(--safe-area-inset-left));
|
|
129
|
+
paddingRight: max(1.5rem, val(--safe-area-inset-right));
|
|
130
|
+
paddingBottom: val(--safe-area-inset-bottom);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/* If you need Android specific stying */
|
|
134
|
+
.myContainerForAndroidOnly {
|
|
135
|
+
paddingTop: max(1.5rem, val(--android-safe-area-inset-top));
|
|
136
|
+
paddingLeft: max(1.5rem, val(--android-safe-area-inset-left));
|
|
137
|
+
paddingRight: max(1.5rem, val(--android-safe-area-inset-right));
|
|
138
|
+
paddingBottom: val(--android-safe-area-inset-bottom);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/* If you need iOS specific styling */
|
|
142
|
+
.myContainerForIOSOnly {
|
|
143
|
+
paddingTop: max(1.5rem, val(--ios-safe-area-inset-top));
|
|
144
|
+
paddingLeft: max(1.5rem, val(--ios-safe-area-inset-left));
|
|
145
|
+
paddingRight: max(1.5rem, val(--ios-safe-area-inset-right));
|
|
146
|
+
paddingBottom: val(--ios-safe-area-inset-bottom);
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
This can also be used with the styles attribute in something like React.js for example.
|
|
151
|
+
```jsx
|
|
152
|
+
// This div will grow to cover the area of the cutout
|
|
153
|
+
// this would be at the very top.
|
|
154
|
+
<div
|
|
155
|
+
style={{
|
|
156
|
+
height: "var(--safe-area-inset-top)",
|
|
157
|
+
backgroundColor: "#12005e"
|
|
158
|
+
}}>
|
|
159
|
+
</div>
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
<details>
|
|
163
|
+
<summary>React - SafeAreaInsetsProvider</summary>
|
|
164
|
+
|
|
165
|
+
Here is a component that can be used by React.js developers. This handles everything for you via the SafeAreaController. There is a hook you can use as well called **useSafeAreaInsetsState** which will return a JSON object with top, bottom, right, and left number properties.
|
|
166
|
+
|
|
167
|
+
```javascript
|
|
168
|
+
import * as React from 'react';
|
|
169
|
+
import { SafeAreaController } from '@capacitor-community/safe-area';
|
|
170
|
+
|
|
171
|
+
const StateContext = React.createContext();
|
|
172
|
+
|
|
173
|
+
export const useSafeAreaInsetsState = () => {
|
|
174
|
+
const context = React.useContext(StateContext);
|
|
175
|
+
|
|
176
|
+
if(context === undefined)
|
|
177
|
+
throw new Error("Cannot use 'useSafeAreaInsetsState' outside of a SafeAreaInsetsProvider!");
|
|
178
|
+
|
|
179
|
+
return context;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const SafeAreaInsetsProvider = ({children}) => {
|
|
183
|
+
const [state, setState] = React.useState({
|
|
184
|
+
top: 0,
|
|
185
|
+
bottom: 0,
|
|
186
|
+
right: 0,
|
|
187
|
+
left: 0
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
React.useState(() => {
|
|
191
|
+
SafeAreaController.addListener((insets) => {
|
|
192
|
+
setState(insets);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
SafeAreaController.load();
|
|
196
|
+
|
|
197
|
+
return () => {
|
|
198
|
+
SafeAreaController.removeAllListeners();
|
|
199
|
+
SafeAreaController.unload();
|
|
200
|
+
}
|
|
201
|
+
}, []);
|
|
202
|
+
|
|
203
|
+
return (
|
|
204
|
+
<StateContext.Provider value={state}>
|
|
205
|
+
{children}
|
|
206
|
+
</StateContext.Provider>
|
|
207
|
+
)
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
export default SafeAreaInsetsProvider;
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
You can then use this provider ideally in the **index** file of your project.
|
|
214
|
+
|
|
215
|
+
```javascript
|
|
216
|
+
ReactDOM.render(
|
|
217
|
+
<React.StrictMode>
|
|
218
|
+
<SafeAreaInsetsProvider>
|
|
219
|
+
<App />
|
|
220
|
+
</SafeAreaInsetsProvider>
|
|
221
|
+
</React.StrictMode>,
|
|
222
|
+
document.getElementById('root')
|
|
223
|
+
);
|
|
224
|
+
```
|
|
225
|
+
</details>
|
package/android/build.gradle
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
ext {
|
|
2
|
-
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
-
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.
|
|
4
|
-
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.
|
|
5
|
-
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
buildscript {
|
|
9
|
-
repositories {
|
|
10
|
-
google()
|
|
11
|
-
mavenCentral()
|
|
12
|
-
}
|
|
13
|
-
dependencies {
|
|
14
|
-
classpath 'com.android.tools.build:gradle:8.
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
apply plugin: 'com.android.library'
|
|
19
|
-
|
|
20
|
-
android {
|
|
21
|
-
namespace "com.getcapacitor.community.plugins.safearea"
|
|
22
|
-
|
|
23
|
-
defaultConfig {
|
|
24
|
-
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
|
|
25
|
-
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion :
|
|
26
|
-
versionCode 1
|
|
27
|
-
versionName "1.0"
|
|
28
|
-
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
29
|
-
}
|
|
30
|
-
buildTypes {
|
|
31
|
-
release {
|
|
32
|
-
minifyEnabled false
|
|
33
|
-
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
lintOptions {
|
|
37
|
-
abortOnError false
|
|
38
|
-
}
|
|
39
|
-
compileOptions {
|
|
40
|
-
sourceCompatibility JavaVersion.
|
|
41
|
-
targetCompatibility JavaVersion.
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
repositories {
|
|
46
|
-
google()
|
|
47
|
-
mavenCentral()
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
dependencies {
|
|
52
|
-
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
53
|
-
implementation project(':capacitor-android')
|
|
54
|
-
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
55
|
-
testImplementation "junit:junit:$junitVersion"
|
|
56
|
-
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
57
|
-
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
58
|
-
}
|
|
1
|
+
ext {
|
|
2
|
+
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.6.1'
|
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.5'
|
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.5.1'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
buildscript {
|
|
9
|
+
repositories {
|
|
10
|
+
google()
|
|
11
|
+
mavenCentral()
|
|
12
|
+
}
|
|
13
|
+
dependencies {
|
|
14
|
+
classpath 'com.android.tools.build:gradle:8.2.1'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
apply plugin: 'com.android.library'
|
|
19
|
+
|
|
20
|
+
android {
|
|
21
|
+
namespace "com.getcapacitor.community.plugins.safearea"
|
|
22
|
+
compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 34
|
|
23
|
+
defaultConfig {
|
|
24
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
|
|
25
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 34
|
|
26
|
+
versionCode 1
|
|
27
|
+
versionName "1.0"
|
|
28
|
+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
29
|
+
}
|
|
30
|
+
buildTypes {
|
|
31
|
+
release {
|
|
32
|
+
minifyEnabled false
|
|
33
|
+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
lintOptions {
|
|
37
|
+
abortOnError false
|
|
38
|
+
}
|
|
39
|
+
compileOptions {
|
|
40
|
+
sourceCompatibility JavaVersion.VERSION_17
|
|
41
|
+
targetCompatibility JavaVersion.VERSION_17
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
repositories {
|
|
46
|
+
google()
|
|
47
|
+
mavenCentral()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
dependencies {
|
|
52
|
+
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
53
|
+
implementation project(':capacitor-android')
|
|
54
|
+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
55
|
+
testImplementation "junit:junit:$junitVersion"
|
|
56
|
+
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
57
|
+
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
58
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
2
|
-
</manifest>
|
|
1
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
2
|
+
</manifest>
|