@totalpave/cordova-plugin-insets 0.2.0 → 0.3.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/www/insets.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  /*
4
- Copyright 2022 Total Pave Inc.
4
+ Copyright 2022-2024 Total Pave Inc.
5
5
 
6
6
  Licensed under the Apache License, Version 2.0 (the "License");
7
7
  you may not use this file except in compliance with the License.
@@ -15,71 +15,203 @@
15
15
  See the License for the specific language governing permissions and
16
16
  limitations under the License.
17
17
  */
18
- const SERVICE_NAME = "Insets";
19
- class InsetsAPI {
18
+ const SERVICE_NAME = "Inset";
19
+ class Inset {
20
20
  constructor() {
21
- this.listeners = [];
22
- this.insets = {
21
+ this.$id = null;
22
+ this.$listeners = [];
23
+ this.$currentInset = {
23
24
  top: 0,
25
+ left: 0,
24
26
  right: 0,
25
- bottom: 0,
26
- left: 0
27
+ bottom: 0
27
28
  };
28
29
  }
29
30
  /**
30
- * Initializes javascript side of the plugin.
31
+ * Gets the native identifier
32
+ *
33
+ * @returns
34
+ */
35
+ getID() {
36
+ return this.$id;
37
+ }
38
+ /**
39
+ * Gets the last emitted inset information
40
+ *
41
+ * @returns
42
+ */
43
+ getInsets() {
44
+ console.warn('getInsets() is deprecated, use getInset instead()', new Error().stack);
45
+ return this.getInset();
46
+ }
47
+ getInset() {
48
+ return this.$currentInset;
49
+ }
50
+ /**
51
+ * See the static Inset.free method for details
52
+ *
53
+ * This is the equivilant of calling Inset.free(insetInstance)
54
+ *
55
+ * @returns
56
+ */
57
+ async free() {
58
+ return await Inset.free(this);
59
+ }
60
+ /**
61
+ * Adds a listener to this inset configuration.
62
+ *
63
+ * Note that this may fire even if nothing has actually
64
+ * changed.
65
+ *
66
+ * Retain the listener reference to remove it later if
67
+ * necessary.
31
68
  *
32
- * This function is called automatically on deviceready.
33
- * @internal
69
+ * @param listener
34
70
  */
35
- __init() {
36
- if (this.initPromise) {
37
- return this.initPromise;
71
+ addListener(listener) {
72
+ this.$listeners.push(listener);
73
+ listener(this.$currentInset);
74
+ }
75
+ /**
76
+ * Frees the listener reference
77
+ *
78
+ * @param listener
79
+ */
80
+ removeListener(listener) {
81
+ let idx = this.$listeners.indexOf(listener);
82
+ if (idx > -1) {
83
+ this.$listeners.splice(idx, 1);
38
84
  }
39
- this.initPromise = new Promise((resolve, reject) => {
40
- // no-op on iOS, still installs to iOS so apps don't need to do platform checks.
85
+ }
86
+ $onUpdate(insets) {
87
+ this.$currentInset = insets;
88
+ for (let i = 0; i < this.$listeners.length; i++) {
89
+ this.$listeners[i](insets);
90
+ }
91
+ }
92
+ static $generateID() {
93
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
94
+ const r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
95
+ return v.toString(16);
96
+ });
97
+ }
98
+ /**
99
+ * Configures a new Inset instance to listen for inset changes
100
+ * It's valid to have multiple instances, with different configurations
101
+ * Each instance may have 0-to-many listeners attached via addListener
102
+ *
103
+ * If this instance is no longer needed/used, call `free` to free
104
+ * resources.
105
+ *
106
+ * It will be more performant to keep the instance count low. If only one
107
+ * configuration set is needed, then it would be recommended to create a
108
+ * single instance and share it rather than every object having it's own
109
+ * inset listener instance.
110
+ *
111
+ * @param config
112
+ * @returns
113
+ */
114
+ static create(config) {
115
+ return new Promise((resolve, reject) => {
116
+ if (!config) {
117
+ config = {};
118
+ }
41
119
  if (cordova.platformId === 'ios') {
42
- resolve();
120
+ let instance = new Inset();
121
+ instance.$id = Inset.$generateID();
122
+ resolve(instance);
43
123
  return;
44
124
  }
45
- // Setup promise resolving mechanism.
46
- // We don't use the cordova callback functions as they will be called multiple times over the lifespan of an app.
47
- let func = () => {
48
- resolve();
49
- this.removeListener(func);
50
- };
51
- this.addListener(func);
52
- // Setup cordova callback.
53
- let that = this;
54
- cordova.exec((insets) => {
55
- that.insets = insets;
56
- for (let i = 0, listeners = that.listeners.slice(), length = listeners.length; i < length; ++i) {
57
- listeners[i](insets);
125
+ let inset = new Inset();
126
+ cordova.exec((e) => {
127
+ if (Inset.$isInitEvent(e)) {
128
+ inset.$id = e.data;
129
+ resolve(inset);
58
130
  }
59
- }, reject, SERVICE_NAME, "setListener", []);
131
+ else if (Inset.$isUpdateEvent(e)) {
132
+ inset.$onUpdate(e.data);
133
+ }
134
+ }, reject, SERVICE_NAME, "create", [config]);
60
135
  });
61
136
  }
62
- addListener(callback) {
63
- this.listeners.push(callback);
64
- }
65
- removeListener(callback) {
66
- let index = this.listeners.indexOf(callback);
67
- if (index === -1) {
68
- return;
69
- }
70
- this.listeners.splice(index, 1);
71
- }
72
137
  /**
73
- * @returns Last emitted insets.
138
+ * Frees the native resources associated with the given
139
+ * inset.
140
+ *
141
+ * After freeing, the inset is no longer usable and it will
142
+ * not receive anymore inset updates. If you retain any
143
+ * references to inset listeners, they should also be dereferenced
144
+ * to allow for garbage collection.
145
+ *
146
+ * This is the equivilant of calling `await inset.free()`
147
+ *
148
+ * @param inset
149
+ * @returns
74
150
  */
75
- getInsets() {
76
- return this.insets;
151
+ static free(inset) {
152
+ let id = null;
153
+ if (typeof inset === 'string') {
154
+ id = inset;
155
+ }
156
+ else {
157
+ id = inset.getID();
158
+ }
159
+ return new Promise((resolve, reject) => {
160
+ if (cordova.platformId === 'ios') {
161
+ resolve();
162
+ return;
163
+ }
164
+ cordova.exec(() => {
165
+ resolve();
166
+ }, reject, SERVICE_NAME, "delete", [id]);
167
+ });
168
+ }
169
+ static $isInitEvent(e) {
170
+ return e.type === 'init';
171
+ }
172
+ static $isUpdateEvent(e) {
173
+ return e.type === 'update';
77
174
  }
78
175
  }
79
- const Insets = new InsetsAPI();
80
- document.addEventListener('deviceready', function () {
81
- Insets.__init();
82
- });
83
176
 
84
- exports.Insets = Insets;
177
+ /*
178
+ Copyright 2022 Total Pave Inc.
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
191
+ */
192
+ /**
193
+ * An enumeration of Inset Types.
194
+ * These are mapped to android's native WindowInsetsCompat.TYPE
195
+ *
196
+ * See https://developer.android.com/reference/androidx/core/view/WindowInsetsCompat.Type
197
+ * for more information.
198
+ *
199
+ * Note that the native constant values is an implementation detail,
200
+ * therefore the values here isn't a direct mapping, but will be resolved
201
+ * appropriately.
202
+ */
203
+ exports.InsetMask = void 0;
204
+ (function (InsetMask) {
205
+ InsetMask[InsetMask["CAPTION_BAR"] = 1] = "CAPTION_BAR";
206
+ InsetMask[InsetMask["DISPLAY_CUTOUT"] = 2] = "DISPLAY_CUTOUT";
207
+ InsetMask[InsetMask["IME"] = 4] = "IME";
208
+ InsetMask[InsetMask["MANDATORY_SYSTEM_GESTURES"] = 8] = "MANDATORY_SYSTEM_GESTURES";
209
+ InsetMask[InsetMask["NAVIGATION_BARS"] = 16] = "NAVIGATION_BARS";
210
+ InsetMask[InsetMask["STATUS_BARS"] = 32] = "STATUS_BARS";
211
+ InsetMask[InsetMask["SYSTEM_BARS"] = 64] = "SYSTEM_BARS";
212
+ InsetMask[InsetMask["SYSTEM_GESTURES"] = 128] = "SYSTEM_GESTURES";
213
+ InsetMask[InsetMask["TAPPABLE_ELEMENT"] = 256] = "TAPPABLE_ELEMENT";
214
+ })(exports.InsetMask || (exports.InsetMask = {}));
215
+
216
+ exports.Inset = Inset;
85
217
  //# sourceMappingURL=insets.js.map
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 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;AACT,QAAA,IAAI,IAAI,CAAC,WAAW,EAAE;YAClB,OAAO,IAAI,CAAC,WAAW,CAAC;SAC3B;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;;;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,IAAI,CAAC,CAAC;;YAGvB,IAAI,IAAI,GAAG,IAAI,CAAC;AAChB,YAAA,OAAO,CAAC,IAAI,CACR,CAAC,MAAe,KAAI;AAChB,gBAAA,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;gBACrB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,EAAE,MAAM,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,GAAG,MAAM,EAAE,EAAE,CAAC,EAAE;AAC5F,oBAAA,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;iBACxB;aACJ,EACD,MAAM,EACN,YAAY,EACZ,aAAa,EACb,EAAE,CACL,CAAC;AACN,SAAC,CAAC,CAAC;KACN;AAEM,IAAA,WAAW,CAAC,QAA4B,EAAA;AAC3C,QAAA,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;KACjC;AAEM,IAAA,cAAc,CAAC,QAA4B,EAAA;QAC9C,IAAI,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;AAC7C,QAAA,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE;YACd,OAAO;SACV;QACD,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;KACnC;AAED;;AAEG;IACI,SAAS,GAAA;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC;KACtB;AACJ,CAAA;AAEY,MAAA,MAAM,GAAG,IAAI,SAAS,GAAG;AAEtC,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/Inset.ts","../src/www/InsetMask.ts"],"sourcesContent":["/*\n Copyright 2022-2024 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\nimport {IInsetConfiguration} from './IInsetConfiguration';\nimport {IInsetCallbackFunc} from './IInsetCallbackFunc';\nimport {IInset} from './IInset';\n\nexport const SERVICE_NAME: string = \"Inset\";\n\ninterface IInsetEvent<T = unknown> {\n type: 'init' | 'update';\n data: T;\n}\n\ntype IInsetInitEvent = IInsetEvent<string>;\ninterface IInsetUpdateEvent extends IInsetEvent<IInset> {\n id: string;\n}\n\nexport class Inset {\n private $currentInset: IInset;\n private $listeners: IInsetCallbackFunc[];\n private $id: string;\n\n private constructor() {\n this.$id = null;\n this.$listeners = [];\n this.$currentInset = {\n top: 0,\n left: 0,\n right: 0,\n bottom: 0\n };\n }\n\n /**\n * Gets the native identifier\n * \n * @returns \n */\n public getID(): string {\n return this.$id;\n }\n\n /**\n * Gets the last emitted inset information\n * \n * @returns\n */\n public getInsets(): IInset {\n console.warn('getInsets() is deprecated, use getInset instead()', new Error().stack);\n return this.getInset();\n }\n\n public getInset(): IInset {\n return this.$currentInset;\n }\n\n /**\n * See the static Inset.free method for details\n * \n * This is the equivilant of calling Inset.free(insetInstance)\n * \n * @returns \n */\n public async free(): Promise<void> {\n return await Inset.free(this);\n }\n\n /**\n * Adds a listener to this inset configuration.\n * \n * Note that this may fire even if nothing has actually\n * changed.\n * \n * Retain the listener reference to remove it later if\n * necessary.\n * \n * @param listener \n */\n public addListener(listener: IInsetCallbackFunc): void {\n this.$listeners.push(listener);\n listener(this.$currentInset);\n }\n\n /**\n * Frees the listener reference\n * \n * @param listener \n */\n public removeListener(listener: IInsetCallbackFunc): void {\n let idx: number = this.$listeners.indexOf(listener);\n if (idx > -1) {\n this.$listeners.splice(idx, 1);\n }\n }\n\n private $onUpdate(insets: IInset): void {\n this.$currentInset = insets;\n\n for (let i = 0; i < this.$listeners.length; i++) {\n this.$listeners[i](insets);\n }\n }\n\n private static $generateID(): string {\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {\n const r = Math.random() * 16 | 0,\n v = c === 'x' ? r : (r & 0x3 | 0x8);\n return v.toString(16);\n });\n }\n\n /**\n * Configures a new Inset instance to listen for inset changes\n * It's valid to have multiple instances, with different configurations\n * Each instance may have 0-to-many listeners attached via addListener\n * \n * If this instance is no longer needed/used, call `free` to free\n * resources.\n * \n * It will be more performant to keep the instance count low. If only one\n * configuration set is needed, then it would be recommended to create a\n * single instance and share it rather than every object having it's own\n * inset listener instance.\n * \n * @param config \n * @returns \n */\n public static create(config: IInsetConfiguration): Promise<Inset> {\n return new Promise<Inset>((resolve, reject) => {\n if (!config) {\n config = {};\n }\n\n if (cordova.platformId === 'ios') {\n let instance: Inset = new Inset();\n instance.$id = Inset.$generateID();\n resolve(instance);\n return;\n }\n\n let inset: Inset = new Inset();\n\n cordova.exec(\n (e: IInsetEvent) => {\n if (Inset.$isInitEvent(e)) {\n inset.$id = e.data;\n resolve(inset);\n }\n else if (Inset.$isUpdateEvent(e)) {\n inset.$onUpdate(e.data);\n }\n },\n reject,\n SERVICE_NAME,\n \"create\",\n [config]\n );\n });\n }\n\n /**\n * Frees the native resources associated with the given\n * inset.\n * \n * After freeing, the inset is no longer usable and it will\n * not receive anymore inset updates. If you retain any\n * references to inset listeners, they should also be dereferenced\n * to allow for garbage collection.\n * \n * This is the equivilant of calling `await inset.free()`\n * \n * @param inset \n * @returns \n */\n public static free(inset: Inset | string): Promise<void> {\n let id: string = null;\n\n if (typeof inset === 'string') {\n id = inset;\n }\n else {\n id = inset.getID();\n }\n\n return new Promise<void>((resolve, reject) => {\n if (cordova.platformId === 'ios') {\n resolve();\n return;\n }\n\n cordova.exec(\n () => {\n resolve();\n },\n reject,\n SERVICE_NAME,\n \"delete\",\n [id]\n );\n });\n }\n\n private static $isInitEvent(e: IInsetEvent): e is IInsetInitEvent {\n return e.type === 'init';\n }\n\n private static $isUpdateEvent(e: IInsetEvent): e is IInsetUpdateEvent {\n return e.type === 'update';\n }\n}\n\ndeclare global {\n interface ITotalpave {\n Inset: Inset;\n }\n interface Window {\n totalpave: ITotalpave;\n }\n}\n","/*\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\n/**\n * An enumeration of Inset Types.\n * These are mapped to android's native WindowInsetsCompat.TYPE\n * \n * See https://developer.android.com/reference/androidx/core/view/WindowInsetsCompat.Type\n * for more information.\n * \n * Note that the native constant values is an implementation detail,\n * therefore the values here isn't a direct mapping, but will be resolved\n * appropriately.\n */\nexport enum InsetMask {\n CAPTION_BAR = 1,\n DISPLAY_CUTOUT = 1 << 1,\n IME = 1 << 2,\n MANDATORY_SYSTEM_GESTURES = 1 << 3,\n NAVIGATION_BARS = 1 << 4,\n STATUS_BARS = 1 << 5,\n SYSTEM_BARS = 1 << 6,\n SYSTEM_GESTURES = 1 << 7,\n TAPPABLE_ELEMENT = 1 << 8\n};\n"],"names":["InsetMask"],"mappings":";;AAAA;;;;;;;;;;;;;;AAcE;AAMK,MAAM,YAAY,GAAW,OAAO,CAAC;MAY/B,KAAK,CAAA;AAKd,IAAA,WAAA,GAAA;AACI,QAAA,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC;AAChB,QAAA,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;QACrB,IAAI,CAAC,aAAa,GAAG;AACjB,YAAA,GAAG,EAAE,CAAC;AACN,YAAA,IAAI,EAAE,CAAC;AACP,YAAA,KAAK,EAAE,CAAC;AACR,YAAA,MAAM,EAAE,CAAC;SACZ,CAAC;KACL;AAED;;;;AAIG;IACI,KAAK,GAAA;QACR,OAAO,IAAI,CAAC,GAAG,CAAC;KACnB;AAED;;;;AAIG;IACI,SAAS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AA,SAAA,CAAA,SAAA,CAAA,aAAA,CAAA,GAAA,EAAA,CAAA,GAAA,aAAoC,CAAA;AACpC,IAAA,SAAA,CAAA,SAAA,CAAA,aAAA,CAAA,GAAA,EAAA,CAAA,GAAA,aAAoC,CAAA;AACpC,IAAA,SAAA,CAAA,SAAA,CAAA,iBAAA,CAAA,GAAA,GAAA,CAAA,GAAA,iBAAoC,CAAA;AACpC,IAAA,SAAA,CAAA,SAAA,CAAA,kBAAA,CAAA,GAAA,GAAA,CAAA,GAAA,kBAAoC,CAAA;AACxC,CAAC,EAVWA,iBAAS,KAATA,iBAAS,GAUpB,EAAA,CAAA,CAAA;;;;"}
@@ -1,136 +0,0 @@
1
- /*
2
- Copyright 2019 Total Pave Inc.
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- */
16
-
17
- package com.totalpave.cordova.insets;
18
-
19
- import android.os.Build;
20
- import android.view.RoundedCorner;
21
- import android.view.WindowInsets;
22
- import androidx.core.view.ViewCompat;
23
- import androidx.core.view.WindowInsetsCompat;
24
- import org.apache.cordova.CallbackContext;
25
- import org.apache.cordova.CordovaPlugin;
26
- import org.apache.cordova.PluginResult.Status;
27
- import org.apache.cordova.PluginResult;
28
- import org.json.JSONArray;
29
- import org.json.JSONObject;
30
- import org.json.JSONException;
31
- import java.lang.NumberFormatException;
32
-
33
- public class Insets extends CordovaPlugin {
34
- public CallbackContext listener;
35
- private JSONObject insets;
36
-
37
- @Override
38
- protected void pluginInitialize() {
39
- ViewCompat.setOnApplyWindowInsetsListener(
40
- this.cordova.getActivity().findViewById(android.R.id.content), (v, insetProvider) -> {
41
- JSONObject result = new JSONObject();
42
-
43
- try {
44
- float density = this.cordova.getActivity().getResources().getDisplayMetrics().density;
45
-
46
- // Ideally, we'd import this, but it shares the same name as our plugin
47
- int insetTypes = WindowInsetsCompat.Type.displayCutout() | WindowInsetsCompat.Type.systemBars();
48
- androidx.core.graphics.Insets insets = insetProvider.getInsets(insetTypes);
49
-
50
- double topLeftRadius = 0.0;
51
- double topRightRadius = 0.0;
52
- double botLeftRadius = 0.0;
53
- double botRightRadius = 0.0;
54
-
55
- WindowInsets sourceInsets = insetProvider.toWindowInsets();
56
- if (sourceInsets != null) {
57
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
58
- RoundedCorner topLeft = sourceInsets.getRoundedCorner(RoundedCorner.POSITION_TOP_LEFT);
59
- RoundedCorner topRight = sourceInsets.getRoundedCorner(RoundedCorner.POSITION_TOP_RIGHT);
60
- RoundedCorner botLeft = sourceInsets.getRoundedCorner(RoundedCorner.POSITION_BOTTOM_LEFT);
61
- RoundedCorner botRight = sourceInsets.getRoundedCorner(RoundedCorner.POSITION_BOTTOM_RIGHT);
62
-
63
- if (topLeft != null) {
64
- int radius = topLeft.getRadius();
65
- topLeftRadius = (double)radius / density;
66
- }
67
-
68
- if (topRight != null) {
69
- int radius = topRight.getRadius();
70
- topRightRadius = (double)radius / density;
71
- }
72
-
73
- if (botLeft != null) {
74
- int radius = botLeft.getRadius();
75
- botLeftRadius = (double)radius / density;
76
- }
77
-
78
- if (botRight != null) {
79
- int radius = botRight.getRadius();
80
- botRightRadius = (double)radius / density;
81
- }
82
- }
83
- }
84
-
85
- double top = insets.top / density;
86
- double right = insets.right / density;
87
- double bottom = insets.bottom / density;
88
- double left = insets.left / density;
89
-
90
- // Insets do not include rounded corner radius. If an inset is present, it generally will be big enough to cover the rounded corner. This is a coincidence, not a designed thing.
91
- // In either case, we need to determine how much space is required to cover the rounded corner and take the higher betwen the inset and the rounded corner.
92
-
93
- top = Math.max(Math.max(top, topLeftRadius), topRightRadius);
94
- bottom = Math.max(Math.max(bottom, botLeftRadius), botRightRadius);
95
- left = Math.max(Math.max(left, topLeftRadius), botLeftRadius);
96
- right = Math.max(Math.max(right, topRightRadius), botRightRadius);
97
-
98
- result.put("top", top);
99
- result.put("right", right);
100
- result.put("bottom", bottom);
101
- result.put("left", left);
102
- } catch (JSONException e) {
103
- e.printStackTrace();
104
- return insetProvider.CONSUMED; // Stop dispatching to child views
105
- }
106
- this.insets = result;
107
- if (listener != null) {
108
- PluginResult presult = new PluginResult(Status.OK, this.insets);
109
- presult.setKeepCallback(true);
110
- listener.sendPluginResult(presult);
111
- }
112
- return insetProvider.CONSUMED; // Stop dispatching to child views
113
- }
114
- );
115
- }
116
-
117
- @Override
118
- public boolean execute(String action, JSONArray args, CallbackContext callback) throws JSONException, NumberFormatException {
119
- if (action.equals("setListener")) {
120
- listener = callback;
121
- cordova.getActivity().runOnUiThread(() -> {
122
- if (this.insets == null) {
123
- // Trigger a inset dispatch (will eventually jump to the ApplyWindowInsetsListener above)
124
- ViewCompat.requestApplyInsets(cordova.getActivity().findViewById(android.R.id.content));
125
- }
126
- else {
127
- PluginResult presult = new PluginResult(Status.OK, this.insets);
128
- presult.setKeepCallback(true);
129
- listener.sendPluginResult(presult);
130
- }
131
- });
132
- return true;
133
- }
134
- return false;
135
- }
136
- }
package/src/www/Insets.ts DELETED
@@ -1,118 +0,0 @@
1
- /*
2
- Copyright 2022 Total Pave Inc.
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- */
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
-
31
- export const SERVICE_NAME: string = "Insets";
32
-
33
- export interface IInsets {
34
- top: number;
35
- right: number;
36
- bottom: number;
37
- left: number;
38
- }
39
-
40
- export type IInsetCallbackFunc = (inset: IInsets) => void;
41
-
42
- class InsetsAPI implements IInsetsAPI {
43
- private initPromise: Promise<void>;
44
- private listeners: Array<Function> = [];
45
- private insets: IInsets = {
46
- top: 0,
47
- right: 0,
48
- bottom: 0,
49
- left: 0
50
- };
51
-
52
- /**
53
- * Initializes javascript side of the plugin.
54
- *
55
- * This function is called automatically on deviceready.
56
- * @internal
57
- */
58
- public __init(): Promise<void> {
59
- if (this.initPromise) {
60
- return this.initPromise;
61
- }
62
- this.initPromise = new Promise<void>((resolve, reject) => {
63
- // no-op on iOS, still installs to iOS so apps don't need to do platform checks.
64
- if (cordova.platformId === 'ios') {
65
- resolve();
66
- return;
67
- }
68
-
69
- // Setup promise resolving mechanism.
70
- // We don't use the cordova callback functions as they will be called multiple times over the lifespan of an app.
71
- let func = () => {
72
- resolve();
73
- this.removeListener(func);
74
- }
75
- this.addListener(func);
76
-
77
- // Setup cordova callback.
78
- let that = this;
79
- cordova.exec(
80
- (insets: IInsets) => {
81
- that.insets = insets;
82
- for (let i = 0, listeners = that.listeners.slice(), length = listeners.length; i < length; ++i) {
83
- listeners[i](insets);
84
- }
85
- },
86
- reject,
87
- SERVICE_NAME,
88
- "setListener",
89
- []
90
- );
91
- });
92
- }
93
-
94
- public addListener(callback: IInsetCallbackFunc) {
95
- this.listeners.push(callback);
96
- }
97
-
98
- public removeListener(callback: IInsetCallbackFunc) {
99
- let index = this.listeners.indexOf(callback);
100
- if (index === -1) {
101
- return;
102
- }
103
- this.listeners.splice(index, 1);
104
- }
105
-
106
- /**
107
- * @returns Last emitted insets.
108
- */
109
- public getInsets(): IInsets {
110
- return this.insets;
111
- }
112
- };
113
-
114
- export const Insets = new InsetsAPI();
115
-
116
- document.addEventListener('deviceready', function() {
117
- Insets.__init();
118
- });