@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@totalpave/cordova-plugin-insets",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
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",
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.8">
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
- export class Insets {
29
- private static initPromise: Promise<void>;
30
- private static listeners: Array<Function> = [];
31
- private static insets: IInsets = {
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 static __init(): Promise<void> {
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
- Insets.removeListener(func);
73
+ this.removeListener(func);
60
74
  }
61
- Insets.addListener(func);
75
+ this.addListener(func);
62
76
 
63
77
  // Setup cordova callback.
78
+ let that = this;
64
79
  cordova.exec(
65
80
  (insets: IInsets) => {
66
- Insets.insets = insets;
67
- for (let i = 0, listeners = Insets.listeners.slice(), length = listeners.length; i < length; ++i) {
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 static addListener(callback: IInsetCallbackFunc) {
94
+ public addListener(callback: IInsetCallbackFunc) {
80
95
  this.listeners.push(callback);
81
96
  }
82
97
 
83
- public static removeListener(callback: IInsetCallbackFunc) {
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 static getInsets(): IInsets {
95
- return Insets.insets;
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
@@ -2,6 +2,7 @@
2
2
  // Core API
3
3
  export {
4
4
  Insets,
5
+ IInsetsAPI,
5
6
  IInsets,
6
7
  IInsetCallbackFunc
7
8
  } from './Insets';
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
- export declare class Insets {
10
- private static initPromise;
11
- private static listeners;
12
- private static insets;
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
- static __init(): Promise<void>;
20
- static addListener(callback: IInsetCallbackFunc): void;
21
- static removeListener(callback: IInsetCallbackFunc): void;
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
- static getInsets(): IInsets;
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 Insets {
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
- static __init() {
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
- Insets.removeListener(func);
49
+ this.removeListener(func);
41
50
  };
42
- Insets.addListener(func);
51
+ this.addListener(func);
43
52
  // Setup cordova callback.
53
+ let that = this;
44
54
  cordova.exec((insets) => {
45
- Insets.insets = insets;
46
- for (let i = 0, listeners = Insets.listeners.slice(), length = listeners.length; i < length; ++i) {
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
- static addListener(callback) {
62
+ addListener(callback) {
53
63
  this.listeners.push(callback);
54
64
  }
55
- static removeListener(callback) {
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
- static getInsets() {
66
- return Insets.insets;
75
+ getInsets() {
76
+ return this.insets;
67
77
  }
68
78
  }
69
- Insets.listeners = [];
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\nexport class Insets {\n private static initPromise: Promise<void>;\n private static listeners: Array<Function> = [];\n private static 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 static __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 Insets.removeListener(func);\n }\n Insets.addListener(func);\n\n // Setup cordova callback.\n cordova.exec(\n (insets: IInsets) => {\n Insets.insets = insets;\n for (let i = 0, listeners = Insets.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 static addListener(callback: IInsetCallbackFunc) {\n this.listeners.push(callback);\n }\n\n public static 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 static getInsets(): IInsets {\n return Insets.insets;\n }\n};\n\ndocument.addEventListener('deviceready', function() {\n Insets.__init();\n});\n"],"names":[],"mappings":";;AAAA;;;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AC,QAAQ,CAAC,CAAC;AAC7C,QAAA,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE;YACd,OAAO;AACV,SAAA;QACD,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;KACnC;AAED;;AAEG;AACI,IAAA,OAAO,SAAS,GAAA;QACnB,OAAO,MAAM,CAAC,MAAM,CAAC;KACxB;;AAlEc,MAAS,CAAA,SAAA,GAAoB,EAAE,CAAC;AAChC,MAAA,CAAA,MAAM,GAAY;AAC7B,IAAA,GAAG,EAAE,CAAC;AACN,IAAA,KAAK,EAAE,CAAC;AACR,IAAA,MAAM,EAAE,CAAC;AACT,IAAA,IAAI,EAAE,CAAC;CACV,CAAC;AA+DN,QAAQ,CAAC,gBAAgB,CAAC,aAAa,EAAE,YAAA;IACrC,MAAM,CAAC,MAAM,EAAE,CAAC;AACpB,CAAC,CAAC;;;;"}
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,M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