@totalpave/cordova-plugin-insets 0.1.8 → 0.1.9
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/package.json +1 -1
- package/plugin.xml +1 -1
- package/src/www/Insets.ts +30 -13
- package/src/www/api.ts +1 -0
- package/www/Insets.d.ts +23 -8
- package/www/api.d.ts +1 -1
- package/www/insets.js +21 -17
- package/www/insets.js.map +1 -1
package/package.json
CHANGED
package/plugin.xml
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" id="@totalpave/cordova-plugin-insets" version="0.1.
|
|
2
|
+
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" id="@totalpave/cordova-plugin-insets" version="0.1.9">
|
|
3
3
|
<name>cordova-plugin-insets</name>
|
|
4
4
|
<description>Cordova Android Plugin to receive native information regarding the unsafe area insets</description>
|
|
5
5
|
<author>Total Pave Inc.</author>
|
package/src/www/Insets.ts
CHANGED
|
@@ -14,6 +14,20 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
+
export interface IInsetsAPI {
|
|
18
|
+
addListener: (callback: IInsetCallbackFunc) => void;
|
|
19
|
+
removeListener: (callback: IInsetCallbackFunc) => void;
|
|
20
|
+
getInsets: () => IInsets;
|
|
21
|
+
}
|
|
22
|
+
declare global {
|
|
23
|
+
interface ITotalpave {
|
|
24
|
+
Insets: IInsetsAPI;
|
|
25
|
+
}
|
|
26
|
+
interface Window {
|
|
27
|
+
totalpave: ITotalpave;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
17
31
|
export const SERVICE_NAME: string = "Insets";
|
|
18
32
|
|
|
19
33
|
export interface IInsets {
|
|
@@ -25,10 +39,10 @@ export interface IInsets {
|
|
|
25
39
|
|
|
26
40
|
export type IInsetCallbackFunc = (inset: IInsets) => void;
|
|
27
41
|
|
|
28
|
-
|
|
29
|
-
private
|
|
30
|
-
private
|
|
31
|
-
private
|
|
42
|
+
class InsetsAPI implements IInsetsAPI {
|
|
43
|
+
private initPromise: Promise<void>;
|
|
44
|
+
private listeners: Array<Function> = [];
|
|
45
|
+
private insets: IInsets = {
|
|
32
46
|
top: 0,
|
|
33
47
|
right: 0,
|
|
34
48
|
bottom: 0,
|
|
@@ -41,7 +55,7 @@ export class Insets {
|
|
|
41
55
|
* This function is called automatically on deviceready.
|
|
42
56
|
* @internal
|
|
43
57
|
*/
|
|
44
|
-
public
|
|
58
|
+
public __init(): Promise<void> {
|
|
45
59
|
if (this.initPromise) {
|
|
46
60
|
return this.initPromise;
|
|
47
61
|
}
|
|
@@ -56,15 +70,16 @@ export class Insets {
|
|
|
56
70
|
// We don't use the cordova callback functions as they will be called multiple times over the lifespan of an app.
|
|
57
71
|
let func = () => {
|
|
58
72
|
resolve();
|
|
59
|
-
|
|
73
|
+
this.removeListener(func);
|
|
60
74
|
}
|
|
61
|
-
|
|
75
|
+
this.addListener(func);
|
|
62
76
|
|
|
63
77
|
// Setup cordova callback.
|
|
78
|
+
let that = this;
|
|
64
79
|
cordova.exec(
|
|
65
80
|
(insets: IInsets) => {
|
|
66
|
-
|
|
67
|
-
for (let i = 0, listeners =
|
|
81
|
+
that.insets = insets;
|
|
82
|
+
for (let i = 0, listeners = that.listeners.slice(), length = listeners.length; i < length; ++i) {
|
|
68
83
|
listeners[i](insets);
|
|
69
84
|
}
|
|
70
85
|
},
|
|
@@ -76,11 +91,11 @@ export class Insets {
|
|
|
76
91
|
});
|
|
77
92
|
}
|
|
78
93
|
|
|
79
|
-
public
|
|
94
|
+
public addListener(callback: IInsetCallbackFunc) {
|
|
80
95
|
this.listeners.push(callback);
|
|
81
96
|
}
|
|
82
97
|
|
|
83
|
-
public
|
|
98
|
+
public removeListener(callback: IInsetCallbackFunc) {
|
|
84
99
|
let index = this.listeners.indexOf(callback);
|
|
85
100
|
if (index === -1) {
|
|
86
101
|
return;
|
|
@@ -91,11 +106,13 @@ export class Insets {
|
|
|
91
106
|
/**
|
|
92
107
|
* @returns Last emitted insets.
|
|
93
108
|
*/
|
|
94
|
-
public
|
|
95
|
-
return
|
|
109
|
+
public getInsets(): IInsets {
|
|
110
|
+
return this.insets;
|
|
96
111
|
}
|
|
97
112
|
};
|
|
98
113
|
|
|
114
|
+
export const Insets = new InsetsAPI();
|
|
115
|
+
|
|
99
116
|
document.addEventListener('deviceready', function() {
|
|
100
117
|
Insets.__init();
|
|
101
118
|
});
|
package/src/www/api.ts
CHANGED
package/www/Insets.d.ts
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
export interface IInsetsAPI {
|
|
2
|
+
addListener: (callback: IInsetCallbackFunc) => void;
|
|
3
|
+
removeListener: (callback: IInsetCallbackFunc) => void;
|
|
4
|
+
getInsets: () => IInsets;
|
|
5
|
+
}
|
|
6
|
+
declare global {
|
|
7
|
+
interface ITotalpave {
|
|
8
|
+
Insets: IInsetsAPI;
|
|
9
|
+
}
|
|
10
|
+
interface Window {
|
|
11
|
+
totalpave: ITotalpave;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
1
14
|
export declare const SERVICE_NAME: string;
|
|
2
15
|
export interface IInsets {
|
|
3
16
|
top: number;
|
|
@@ -6,21 +19,23 @@ export interface IInsets {
|
|
|
6
19
|
left: number;
|
|
7
20
|
}
|
|
8
21
|
export type IInsetCallbackFunc = (inset: IInsets) => void;
|
|
9
|
-
|
|
10
|
-
private
|
|
11
|
-
private
|
|
12
|
-
private
|
|
22
|
+
declare class InsetsAPI implements IInsetsAPI {
|
|
23
|
+
private initPromise;
|
|
24
|
+
private listeners;
|
|
25
|
+
private insets;
|
|
13
26
|
/**
|
|
14
27
|
* Initializes javascript side of the plugin.
|
|
15
28
|
*
|
|
16
29
|
* This function is called automatically on deviceready.
|
|
17
30
|
* @internal
|
|
18
31
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
32
|
+
__init(): Promise<void>;
|
|
33
|
+
addListener(callback: IInsetCallbackFunc): void;
|
|
34
|
+
removeListener(callback: IInsetCallbackFunc): void;
|
|
22
35
|
/**
|
|
23
36
|
* @returns Last emitted insets.
|
|
24
37
|
*/
|
|
25
|
-
|
|
38
|
+
getInsets(): IInsets;
|
|
26
39
|
}
|
|
40
|
+
export declare const Insets: InsetsAPI;
|
|
41
|
+
export {};
|
package/www/api.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { Insets, IInsets, IInsetCallbackFunc } from './Insets';
|
|
1
|
+
export { Insets, IInsetsAPI, IInsets, IInsetCallbackFunc } from './Insets';
|
package/www/insets.js
CHANGED
|
@@ -16,14 +16,23 @@
|
|
|
16
16
|
limitations under the License.
|
|
17
17
|
*/
|
|
18
18
|
const SERVICE_NAME = "Insets";
|
|
19
|
-
class
|
|
19
|
+
class InsetsAPI {
|
|
20
|
+
constructor() {
|
|
21
|
+
this.listeners = [];
|
|
22
|
+
this.insets = {
|
|
23
|
+
top: 0,
|
|
24
|
+
right: 0,
|
|
25
|
+
bottom: 0,
|
|
26
|
+
left: 0
|
|
27
|
+
};
|
|
28
|
+
}
|
|
20
29
|
/**
|
|
21
30
|
* Initializes javascript side of the plugin.
|
|
22
31
|
*
|
|
23
32
|
* This function is called automatically on deviceready.
|
|
24
33
|
* @internal
|
|
25
34
|
*/
|
|
26
|
-
|
|
35
|
+
__init() {
|
|
27
36
|
if (this.initPromise) {
|
|
28
37
|
return this.initPromise;
|
|
29
38
|
}
|
|
@@ -37,22 +46,23 @@ class Insets {
|
|
|
37
46
|
// We don't use the cordova callback functions as they will be called multiple times over the lifespan of an app.
|
|
38
47
|
let func = () => {
|
|
39
48
|
resolve();
|
|
40
|
-
|
|
49
|
+
this.removeListener(func);
|
|
41
50
|
};
|
|
42
|
-
|
|
51
|
+
this.addListener(func);
|
|
43
52
|
// Setup cordova callback.
|
|
53
|
+
let that = this;
|
|
44
54
|
cordova.exec((insets) => {
|
|
45
|
-
|
|
46
|
-
for (let i = 0, listeners =
|
|
55
|
+
that.insets = insets;
|
|
56
|
+
for (let i = 0, listeners = that.listeners.slice(), length = listeners.length; i < length; ++i) {
|
|
47
57
|
listeners[i](insets);
|
|
48
58
|
}
|
|
49
59
|
}, reject, SERVICE_NAME, "setListener", []);
|
|
50
60
|
});
|
|
51
61
|
}
|
|
52
|
-
|
|
62
|
+
addListener(callback) {
|
|
53
63
|
this.listeners.push(callback);
|
|
54
64
|
}
|
|
55
|
-
|
|
65
|
+
removeListener(callback) {
|
|
56
66
|
let index = this.listeners.indexOf(callback);
|
|
57
67
|
if (index === -1) {
|
|
58
68
|
return;
|
|
@@ -62,17 +72,11 @@ class Insets {
|
|
|
62
72
|
/**
|
|
63
73
|
* @returns Last emitted insets.
|
|
64
74
|
*/
|
|
65
|
-
|
|
66
|
-
return
|
|
75
|
+
getInsets() {
|
|
76
|
+
return this.insets;
|
|
67
77
|
}
|
|
68
78
|
}
|
|
69
|
-
Insets
|
|
70
|
-
Insets.insets = {
|
|
71
|
-
top: 0,
|
|
72
|
-
right: 0,
|
|
73
|
-
bottom: 0,
|
|
74
|
-
left: 0
|
|
75
|
-
};
|
|
79
|
+
const Insets = new InsetsAPI();
|
|
76
80
|
document.addEventListener('deviceready', function () {
|
|
77
81
|
Insets.__init();
|
|
78
82
|
});
|
package/www/insets.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"insets.js","sources":["../src/www/Insets.ts"],"sourcesContent":["/*\n Copyright 2022 Total Pave Inc.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*/\n\nexport const SERVICE_NAME: string = \"Insets\";\n\nexport interface IInsets {\n top: number;\n right: number;\n bottom: number;\n left: number;\n}\n\nexport type IInsetCallbackFunc = (inset: IInsets) => void;\n\
|
|
1
|
+
{"version":3,"file":"insets.js","sources":["../src/www/Insets.ts"],"sourcesContent":["/*\n Copyright 2022 Total Pave Inc.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*/\n\nexport interface IInsetsAPI {\n addListener: (callback: IInsetCallbackFunc) => void;\n removeListener: (callback: IInsetCallbackFunc) => void;\n getInsets: () => IInsets;\n}\ndeclare global {\n interface ITotalpave {\n Insets: IInsetsAPI;\n }\n interface Window {\n totalpave: ITotalpave;\n }\n}\n\nexport const SERVICE_NAME: string = \"Insets\";\n\nexport interface IInsets {\n top: number;\n right: number;\n bottom: number;\n left: number;\n}\n\nexport type IInsetCallbackFunc = (inset: IInsets) => void;\n\nclass InsetsAPI implements IInsetsAPI {\n private initPromise: Promise<void>;\n private listeners: Array<Function> = [];\n private insets: IInsets = {\n top: 0,\n right: 0,\n bottom: 0,\n left: 0\n };\n\n /**\n * Initializes javascript side of the plugin.\n * \n * This function is called automatically on deviceready.\n * @internal\n */\n public __init(): Promise<void> {\n if (this.initPromise) {\n return this.initPromise;\n }\n this.initPromise = new Promise<void>((resolve, reject) => {\n // no-op on iOS, still installs to iOS so apps don't need to do platform checks.\n if (cordova.platformId === 'ios') {\n resolve();\n return;\n }\n\n // Setup promise resolving mechanism.\n // We don't use the cordova callback functions as they will be called multiple times over the lifespan of an app.\n let func = () => {\n resolve();\n this.removeListener(func);\n }\n this.addListener(func);\n\n // Setup cordova callback.\n let that = this;\n cordova.exec(\n (insets: IInsets) => {\n that.insets = insets;\n for (let i = 0, listeners = that.listeners.slice(), length = listeners.length; i < length; ++i) {\n listeners[i](insets);\n }\n },\n reject,\n SERVICE_NAME,\n \"setListener\",\n []\n );\n });\n }\n\n public addListener(callback: IInsetCallbackFunc) {\n this.listeners.push(callback);\n }\n\n public removeListener(callback: IInsetCallbackFunc) {\n let index = this.listeners.indexOf(callback);\n if (index === -1) {\n return;\n }\n this.listeners.splice(index, 1);\n }\n\n /**\n * @returns Last emitted insets.\n */ \n public getInsets(): IInsets {\n return this.insets;\n }\n};\n\nexport const Insets = new InsetsAPI();\n\ndocument.addEventListener('deviceready', function() {\n Insets.__init();\n});\n"],"names":[],"mappings":";;AAAA;;;;;;;;;;;;;;AAcE;AAgBK,MAAM,YAAY,GAAW,QAAQ,CAAC;AAW7C,MAAM,SAAS,CAAA;AAAf,IAAA,WAAA,GAAA;QAEY,IAAS,CAAA,SAAA,GAAoB,EAAE,CAAC;AAChC,QAAA,IAAA,CAAA,MAAM,GAAY;AACtB,YAAA,GAAG,EAAE,CAAC;AACN,YAAA,KAAK,EAAE,CAAC;AACR,YAAA,MAAM,EAAE,CAAC;AACT,YAAA,IAAI,EAAE,CAAC;SACV,CAAC;KA8DL;AA5DG;;;;;AAKG;IACI,MAAM,GAAA;QACT,IAAI,IAAI,CAAC,WAAW,EAAE;YAClB,OAAO,IAAI,CAAC,WAAW,CAAC;AAC3B,SAAA;QACD,IAAI,CAAC,WAAW,GAAG,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,KAAI;;AAErD,YAAA,IAAI,OAAO,CAAC,UAAU,KAAK,KAAK,EAAE;AAC9B,gBAAA,OAAO,EAAE,CAAC;gBACV,OAAO;AACV,aAAA;;;YAID,IAAI,IAAI,GAAG,MAAK;AACZ,gBAAA,OAAO,EAAE,CAAC;AACV,gBAAA,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;AAC9B,aAAC,CAAA;AACD,YAAA,IAAI,CAAC,WAAW,CAAC,IA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