@totalpave/cordova-plugin-insets 0.4.1 → 0.4.2

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/docs.md CHANGED
@@ -18,6 +18,7 @@ This document describes the public API available to library consumers.
18
18
  - [3.3 - addListener](#33---addlistener)
19
19
  - [3.4 - removeListener](#34---removelistener)
20
20
  - [3.5 - getInset](#35---getinset)
21
+ - [4.0 - Sample Code](#40---sample-code)
21
22
 
22
23
  ## 1.0 - General Notes
23
24
  The namespace of this plugin is `window.totalpave.Inset`. It will become available after the `deviceready` event. Throughout this document, I'll refer to the `totalpave.Inset` object as `Inset`.
@@ -168,3 +169,44 @@ Returns the last known [IInset](#21---iinset) object.
168
169
  ```typescript
169
170
  getInset(): IInset;
170
171
  ```
172
+
173
+ ## 4.0 - Sample Code
174
+
175
+ The plugin concerns itself with reporting safe area values. How the app consumes them is entirely up to the app. A very basic example that goes straight to the point would look something like this:
176
+
177
+ ```js
178
+ let insetProvider = await window.totalpave.Inset.create();
179
+ insetProvider.addListener((insets) => {
180
+ let bottomOffset = insets.bottom;
181
+
182
+ let myDiv = document.getElementById('myDiv').style.marginBottom = bottomOffset + 'px';
183
+ });
184
+ ```
185
+
186
+ However, styling a lot of UI directly in the JS isn't very ideal, so a better method is to read the inset reports and set CSS variables which is then accessible from your CSS:
187
+
188
+ ```js
189
+ let insetProvider = await window.totalpave.Inset.create();
190
+ insetProvider.addListener((insets) => {
191
+ let r = document.querySelector(':root');
192
+
193
+ r.style.setProperty('--my-inset-top', `${insets.top}px`);
194
+ r.style.setProperty('--my-inset-bottom', `${insets.bottom}px`);
195
+ r.style.setProperty('--my-inset-left', `${insets.left}px`);
196
+ r.style.setProperty('--my-inset-right', `${insets.right}px`);
197
+ });
198
+ ```
199
+
200
+ This sets variables that can be referenced from CSS:
201
+
202
+ ```css
203
+ #myDiv {
204
+ margin-bottom: var(--my-inset-bottom, env(safe-area-inset-bottom));
205
+ }
206
+ ```
207
+
208
+ Of course you can use `var(--my-inset-bottom)` anywhere you see fit in CSS, inside padding directives, or top/left/right/botton directives, etc...
209
+
210
+ If `--my-inset-bottom` is not set, it falls back to the webview environment variable `env(safe-area-inset-bottom)`, useful if you're sharing web code between cordova and other web environments like a standard website.
211
+
212
+ If you use a CSS preprocessor like Less, Stylus or Sass. It may be smart to create a macro to abstract the usages of the custom variable. There may be a time where this plugin becomes completely unnecessary.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@totalpave/cordova-plugin-insets",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "Cordova Android Plugin to receive native information regarding the unsafe area insets.",
5
5
  "main": "www/insets.js",
6
6
  "types": "www/api.d.ts",
@@ -26,16 +26,16 @@
26
26
  },
27
27
  "homepage": "https://github.com/totalpaveinc/cordova-plugin-insets#readme",
28
28
  "devDependencies": {
29
- "@rollup/plugin-commonjs": "28.0.6",
29
+ "@rollup/plugin-commonjs": "29.0.0",
30
30
  "@rollup/plugin-node-resolve": "16.0.1",
31
31
  "@types/cordova": "11.0.3",
32
32
  "@types/node": "24.3.1",
33
- "ejs": "3.1.10",
34
- "rollup": "4.50.1",
33
+ "ejs": "4.0.1",
34
+ "rollup": "4.57.1",
35
35
  "rollup-plugin-progress": "1.1.2",
36
36
  "rollup-plugin-typescript2": "0.36.0",
37
37
  "ts-node": "10.9.2",
38
- "typescript": "5.9.2"
38
+ "typescript": "5.9.3"
39
39
  },
40
40
  "engines": {
41
41
  "cordovaDependencies": {
package/plugin.xml CHANGED
@@ -2,7 +2,7 @@
2
2
  <plugin
3
3
  xmlns="http://apache.org/cordova/ns/plugins/1.0"
4
4
  id="@totalpave/cordova-plugin-insets"
5
- version="0.4.1"
5
+ version="0.4.2"
6
6
  >
7
7
  <name>cordova-plugin-insets</name>
8
8
  <description>Cordova Android Plugin to receive native information regarding the unsafe area insets</description>
@@ -19,6 +19,7 @@
19
19
  <config-file target="res/xml/config.xml" parent="/*">
20
20
  <feature name="Inset">
21
21
  <param name="android-package" value="com.totalpave.cordova.inset.Inset" />
22
+ <param name="onload" value="true" />
22
23
  </feature>
23
24
  </config-file>
24
25
  <source-file src="src/android/com/totalpave/cordova/inset/Inset.java" target-dir="src/com/totalpave/cordova/inset" />
@@ -28,6 +29,7 @@
28
29
  <config-file target="config.xml" parent="/*">
29
30
  <feature name="Inset">
30
31
  <param name="ios-package" value="TPIInset" />
32
+ <param name="onload" value="true" />
31
33
  </feature>
32
34
  </config-file>
33
35
 
package/plugin.xml.ejs CHANGED
@@ -19,6 +19,7 @@
19
19
  <config-file target="res/xml/config.xml" parent="/*">
20
20
  <feature name="Inset">
21
21
  <param name="android-package" value="com.totalpave.cordova.inset.Inset" />
22
+ <param name="onload" value="true" />
22
23
  </feature>
23
24
  </config-file>
24
25
  <source-file src="src/android/com/totalpave/cordova/inset/Inset.java" target-dir="src/com/totalpave/cordova/inset" />
@@ -28,6 +29,7 @@
28
29
  <config-file target="config.xml" parent="/*">
29
30
  <feature name="Inset">
30
31
  <param name="ios-package" value="TPIInset" />
32
+ <param name="onload" value="true" />
31
33
  </feature>
32
34
  </config-file>
33
35