@totalpave/cordova-plugin-insets 0.2.0 → 0.3.1
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/CHANGELOG.md +50 -1
- package/README.md +1 -1
- package/docs.md +100 -17
- package/package.json +4 -4
- package/plugin.xml +6 -6
- package/plugin.xml.ejs +5 -5
- package/src/android/com/totalpave/cordova/inset/Inset.java +337 -0
- package/src/www/IInset.ts +22 -0
- package/src/www/IInsetCallbackFunc.ts +19 -0
- package/src/www/IInsetConfiguration.ts +32 -0
- package/src/www/Inset.ts +234 -0
- package/src/www/InsetMask.ts +38 -0
- package/src/www/api.ts +6 -5
- package/www/IInset.d.ts +6 -0
- package/www/IInsetCallbackFunc.d.ts +2 -0
- package/www/IInsetConfiguration.d.ts +15 -0
- package/www/Inset.d.ts +93 -0
- package/www/InsetMask.d.ts +22 -0
- package/www/api.d.ts +5 -1
- package/www/insets.js +180 -48
- package/www/insets.js.map +1 -1
- package/src/android/com/totalpave/cordova/insets/Insets.java +0 -136
- package/src/www/Insets.ts +0 -118
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2022-2024 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
|
+
import {IInset} from './IInset';
|
|
18
|
+
|
|
19
|
+
export type IInsetCallbackFunc = (inset: IInset) => void;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2022-2024 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 IInsetConfiguration {
|
|
18
|
+
/**
|
|
19
|
+
* A bit mask of InsetMask
|
|
20
|
+
*
|
|
21
|
+
* @defaults DISPLAY_CUTOUT | SYSTEM_BARS
|
|
22
|
+
*/
|
|
23
|
+
mask?: number;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* If true, includes rounded corners in the inset information
|
|
27
|
+
* Only available on Android API 31 ("S") and later.
|
|
28
|
+
*
|
|
29
|
+
* @defaults true
|
|
30
|
+
*/
|
|
31
|
+
includeRoundedCorners?: boolean;
|
|
32
|
+
}
|
package/src/www/Inset.ts
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2022-2024 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
|
+
import {IInsetConfiguration} from './IInsetConfiguration';
|
|
18
|
+
import {IInsetCallbackFunc} from './IInsetCallbackFunc';
|
|
19
|
+
import {IInset} from './IInset';
|
|
20
|
+
|
|
21
|
+
export const SERVICE_NAME: string = "Inset";
|
|
22
|
+
|
|
23
|
+
interface IInsetEvent<T = unknown> {
|
|
24
|
+
type: 'init' | 'update';
|
|
25
|
+
data: T;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
type IInsetInitEvent = IInsetEvent<string>;
|
|
29
|
+
interface IInsetUpdateEvent extends IInsetEvent<IInset> {
|
|
30
|
+
id: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export class Inset {
|
|
34
|
+
private $currentInset: IInset;
|
|
35
|
+
private $listeners: IInsetCallbackFunc[];
|
|
36
|
+
private $id: string;
|
|
37
|
+
|
|
38
|
+
private constructor() {
|
|
39
|
+
this.$id = null;
|
|
40
|
+
this.$listeners = [];
|
|
41
|
+
this.$currentInset = {
|
|
42
|
+
top: 0,
|
|
43
|
+
left: 0,
|
|
44
|
+
right: 0,
|
|
45
|
+
bottom: 0
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Gets the native identifier
|
|
51
|
+
*
|
|
52
|
+
* @returns
|
|
53
|
+
*/
|
|
54
|
+
public getID(): string {
|
|
55
|
+
return this.$id;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Gets the last emitted inset information
|
|
60
|
+
*
|
|
61
|
+
* @returns
|
|
62
|
+
*/
|
|
63
|
+
public getInsets(): IInset {
|
|
64
|
+
console.warn('getInsets() is deprecated, use getInset instead()', new Error().stack);
|
|
65
|
+
return this.getInset();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public getInset(): IInset {
|
|
69
|
+
return this.$currentInset;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* See the static Inset.free method for details
|
|
74
|
+
*
|
|
75
|
+
* This is the equivilant of calling Inset.free(insetInstance)
|
|
76
|
+
*
|
|
77
|
+
* @returns
|
|
78
|
+
*/
|
|
79
|
+
public async free(): Promise<void> {
|
|
80
|
+
return await Inset.free(this);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Adds a listener to this inset configuration.
|
|
85
|
+
*
|
|
86
|
+
* Note that this may fire even if nothing has actually
|
|
87
|
+
* changed.
|
|
88
|
+
*
|
|
89
|
+
* Retain the listener reference to remove it later if
|
|
90
|
+
* necessary.
|
|
91
|
+
*
|
|
92
|
+
* @param listener
|
|
93
|
+
*/
|
|
94
|
+
public addListener(listener: IInsetCallbackFunc): void {
|
|
95
|
+
this.$listeners.push(listener);
|
|
96
|
+
listener(this.$currentInset);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Frees the listener reference
|
|
101
|
+
*
|
|
102
|
+
* @param listener
|
|
103
|
+
*/
|
|
104
|
+
public removeListener(listener: IInsetCallbackFunc): void {
|
|
105
|
+
let idx: number = this.$listeners.indexOf(listener);
|
|
106
|
+
if (idx > -1) {
|
|
107
|
+
this.$listeners.splice(idx, 1);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private $onUpdate(insets: IInset): void {
|
|
112
|
+
this.$currentInset = insets;
|
|
113
|
+
|
|
114
|
+
for (let i = 0; i < this.$listeners.length; i++) {
|
|
115
|
+
this.$listeners[i](insets);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
private static $generateID(): string {
|
|
120
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
|
121
|
+
const r = Math.random() * 16 | 0,
|
|
122
|
+
v = c === 'x' ? r : (r & 0x3 | 0x8);
|
|
123
|
+
return v.toString(16);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Configures a new Inset instance to listen for inset changes
|
|
129
|
+
* It's valid to have multiple instances, with different configurations
|
|
130
|
+
* Each instance may have 0-to-many listeners attached via addListener
|
|
131
|
+
*
|
|
132
|
+
* If this instance is no longer needed/used, call `free` to free
|
|
133
|
+
* resources.
|
|
134
|
+
*
|
|
135
|
+
* It will be more performant to keep the instance count low. If only one
|
|
136
|
+
* configuration set is needed, then it would be recommended to create a
|
|
137
|
+
* single instance and share it rather than every object having it's own
|
|
138
|
+
* inset listener instance.
|
|
139
|
+
*
|
|
140
|
+
* @param config
|
|
141
|
+
* @returns
|
|
142
|
+
*/
|
|
143
|
+
public static create(config: IInsetConfiguration): Promise<Inset> {
|
|
144
|
+
return new Promise<Inset>((resolve, reject) => {
|
|
145
|
+
if (!config) {
|
|
146
|
+
config = {};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (cordova.platformId === 'ios') {
|
|
150
|
+
let instance: Inset = new Inset();
|
|
151
|
+
instance.$id = Inset.$generateID();
|
|
152
|
+
resolve(instance);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
let inset: Inset = new Inset();
|
|
157
|
+
|
|
158
|
+
cordova.exec(
|
|
159
|
+
(e: IInsetEvent) => {
|
|
160
|
+
if (Inset.$isInitEvent(e)) {
|
|
161
|
+
inset.$id = e.data;
|
|
162
|
+
resolve(inset);
|
|
163
|
+
}
|
|
164
|
+
else if (Inset.$isUpdateEvent(e)) {
|
|
165
|
+
inset.$onUpdate(e.data);
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
reject,
|
|
169
|
+
SERVICE_NAME,
|
|
170
|
+
"create",
|
|
171
|
+
[config]
|
|
172
|
+
);
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Frees the native resources associated with the given
|
|
178
|
+
* inset.
|
|
179
|
+
*
|
|
180
|
+
* After freeing, the inset is no longer usable and it will
|
|
181
|
+
* not receive anymore inset updates. If you retain any
|
|
182
|
+
* references to inset listeners, they should also be dereferenced
|
|
183
|
+
* to allow for garbage collection.
|
|
184
|
+
*
|
|
185
|
+
* This is the equivilant of calling `await inset.free()`
|
|
186
|
+
*
|
|
187
|
+
* @param inset
|
|
188
|
+
* @returns
|
|
189
|
+
*/
|
|
190
|
+
public static free(inset: Inset | string): Promise<void> {
|
|
191
|
+
let id: string = null;
|
|
192
|
+
|
|
193
|
+
if (typeof inset === 'string') {
|
|
194
|
+
id = inset;
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
id = inset.getID();
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return new Promise<void>((resolve, reject) => {
|
|
201
|
+
if (cordova.platformId === 'ios') {
|
|
202
|
+
resolve();
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
cordova.exec(
|
|
207
|
+
() => {
|
|
208
|
+
resolve();
|
|
209
|
+
},
|
|
210
|
+
reject,
|
|
211
|
+
SERVICE_NAME,
|
|
212
|
+
"delete",
|
|
213
|
+
[id]
|
|
214
|
+
);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
private static $isInitEvent(e: IInsetEvent): e is IInsetInitEvent {
|
|
219
|
+
return e.type === 'init';
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
private static $isUpdateEvent(e: IInsetEvent): e is IInsetUpdateEvent {
|
|
223
|
+
return e.type === 'update';
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
declare global {
|
|
228
|
+
interface ITotalpave {
|
|
229
|
+
Inset: Inset;
|
|
230
|
+
}
|
|
231
|
+
interface Window {
|
|
232
|
+
totalpave: ITotalpave;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
/**
|
|
18
|
+
* An enumeration of Inset Types.
|
|
19
|
+
* These are mapped to android's native WindowInsetsCompat.TYPE
|
|
20
|
+
*
|
|
21
|
+
* See https://developer.android.com/reference/androidx/core/view/WindowInsetsCompat.Type
|
|
22
|
+
* for more information.
|
|
23
|
+
*
|
|
24
|
+
* Note that the native constant values is an implementation detail,
|
|
25
|
+
* therefore the values here isn't a direct mapping, but will be resolved
|
|
26
|
+
* appropriately.
|
|
27
|
+
*/
|
|
28
|
+
export enum InsetMask {
|
|
29
|
+
CAPTION_BAR = 1,
|
|
30
|
+
DISPLAY_CUTOUT = 1 << 1,
|
|
31
|
+
IME = 1 << 2,
|
|
32
|
+
MANDATORY_SYSTEM_GESTURES = 1 << 3,
|
|
33
|
+
NAVIGATION_BARS = 1 << 4,
|
|
34
|
+
STATUS_BARS = 1 << 5,
|
|
35
|
+
SYSTEM_BARS = 1 << 6,
|
|
36
|
+
SYSTEM_GESTURES = 1 << 7,
|
|
37
|
+
TAPPABLE_ELEMENT = 1 << 8
|
|
38
|
+
};
|
package/src/www/api.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
|
|
2
2
|
// Core API
|
|
3
3
|
export {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from './
|
|
4
|
+
Inset
|
|
5
|
+
} from './Inset';
|
|
6
|
+
export {IInset} from './IInset';
|
|
7
|
+
export {InsetMask} from './InsetMask';
|
|
8
|
+
export {IInsetCallbackFunc} from './IInsetCallbackFunc';
|
|
9
|
+
export {IInsetConfiguration} from './IInsetConfiguration';
|
package/www/IInset.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface IInsetConfiguration {
|
|
2
|
+
/**
|
|
3
|
+
* A bit mask of InsetMask
|
|
4
|
+
*
|
|
5
|
+
* @defaults DISPLAY_CUTOUT | SYSTEM_BARS
|
|
6
|
+
*/
|
|
7
|
+
mask?: number;
|
|
8
|
+
/**
|
|
9
|
+
* If true, includes rounded corners in the inset information
|
|
10
|
+
* Only available on Android API 31 ("S") and later.
|
|
11
|
+
*
|
|
12
|
+
* @defaults true
|
|
13
|
+
*/
|
|
14
|
+
includeRoundedCorners?: boolean;
|
|
15
|
+
}
|
package/www/Inset.d.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { IInsetConfiguration } from './IInsetConfiguration';
|
|
2
|
+
import { IInsetCallbackFunc } from './IInsetCallbackFunc';
|
|
3
|
+
import { IInset } from './IInset';
|
|
4
|
+
export declare const SERVICE_NAME: string;
|
|
5
|
+
export declare class Inset {
|
|
6
|
+
private $currentInset;
|
|
7
|
+
private $listeners;
|
|
8
|
+
private $id;
|
|
9
|
+
private constructor();
|
|
10
|
+
/**
|
|
11
|
+
* Gets the native identifier
|
|
12
|
+
*
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
getID(): string;
|
|
16
|
+
/**
|
|
17
|
+
* Gets the last emitted inset information
|
|
18
|
+
*
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
getInsets(): IInset;
|
|
22
|
+
getInset(): IInset;
|
|
23
|
+
/**
|
|
24
|
+
* See the static Inset.free method for details
|
|
25
|
+
*
|
|
26
|
+
* This is the equivilant of calling Inset.free(insetInstance)
|
|
27
|
+
*
|
|
28
|
+
* @returns
|
|
29
|
+
*/
|
|
30
|
+
free(): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Adds a listener to this inset configuration.
|
|
33
|
+
*
|
|
34
|
+
* Note that this may fire even if nothing has actually
|
|
35
|
+
* changed.
|
|
36
|
+
*
|
|
37
|
+
* Retain the listener reference to remove it later if
|
|
38
|
+
* necessary.
|
|
39
|
+
*
|
|
40
|
+
* @param listener
|
|
41
|
+
*/
|
|
42
|
+
addListener(listener: IInsetCallbackFunc): void;
|
|
43
|
+
/**
|
|
44
|
+
* Frees the listener reference
|
|
45
|
+
*
|
|
46
|
+
* @param listener
|
|
47
|
+
*/
|
|
48
|
+
removeListener(listener: IInsetCallbackFunc): void;
|
|
49
|
+
private $onUpdate;
|
|
50
|
+
private static $generateID;
|
|
51
|
+
/**
|
|
52
|
+
* Configures a new Inset instance to listen for inset changes
|
|
53
|
+
* It's valid to have multiple instances, with different configurations
|
|
54
|
+
* Each instance may have 0-to-many listeners attached via addListener
|
|
55
|
+
*
|
|
56
|
+
* If this instance is no longer needed/used, call `free` to free
|
|
57
|
+
* resources.
|
|
58
|
+
*
|
|
59
|
+
* It will be more performant to keep the instance count low. If only one
|
|
60
|
+
* configuration set is needed, then it would be recommended to create a
|
|
61
|
+
* single instance and share it rather than every object having it's own
|
|
62
|
+
* inset listener instance.
|
|
63
|
+
*
|
|
64
|
+
* @param config
|
|
65
|
+
* @returns
|
|
66
|
+
*/
|
|
67
|
+
static create(config: IInsetConfiguration): Promise<Inset>;
|
|
68
|
+
/**
|
|
69
|
+
* Frees the native resources associated with the given
|
|
70
|
+
* inset.
|
|
71
|
+
*
|
|
72
|
+
* After freeing, the inset is no longer usable and it will
|
|
73
|
+
* not receive anymore inset updates. If you retain any
|
|
74
|
+
* references to inset listeners, they should also be dereferenced
|
|
75
|
+
* to allow for garbage collection.
|
|
76
|
+
*
|
|
77
|
+
* This is the equivilant of calling `await inset.free()`
|
|
78
|
+
*
|
|
79
|
+
* @param inset
|
|
80
|
+
* @returns
|
|
81
|
+
*/
|
|
82
|
+
static free(inset: Inset | string): Promise<void>;
|
|
83
|
+
private static $isInitEvent;
|
|
84
|
+
private static $isUpdateEvent;
|
|
85
|
+
}
|
|
86
|
+
declare global {
|
|
87
|
+
interface ITotalpave {
|
|
88
|
+
Inset: Inset;
|
|
89
|
+
}
|
|
90
|
+
interface Window {
|
|
91
|
+
totalpave: ITotalpave;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An enumeration of Inset Types.
|
|
3
|
+
* These are mapped to android's native WindowInsetsCompat.TYPE
|
|
4
|
+
*
|
|
5
|
+
* See https://developer.android.com/reference/androidx/core/view/WindowInsetsCompat.Type
|
|
6
|
+
* for more information.
|
|
7
|
+
*
|
|
8
|
+
* Note that the native constant values is an implementation detail,
|
|
9
|
+
* therefore the values here isn't a direct mapping, but will be resolved
|
|
10
|
+
* appropriately.
|
|
11
|
+
*/
|
|
12
|
+
export declare enum InsetMask {
|
|
13
|
+
CAPTION_BAR = 1,
|
|
14
|
+
DISPLAY_CUTOUT = 2,
|
|
15
|
+
IME = 4,
|
|
16
|
+
MANDATORY_SYSTEM_GESTURES = 8,
|
|
17
|
+
NAVIGATION_BARS = 16,
|
|
18
|
+
STATUS_BARS = 32,
|
|
19
|
+
SYSTEM_BARS = 64,
|
|
20
|
+
SYSTEM_GESTURES = 128,
|
|
21
|
+
TAPPABLE_ELEMENT = 256
|
|
22
|
+
}
|
package/www/api.d.ts
CHANGED
|
@@ -1 +1,5 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { Inset } from './Inset';
|
|
2
|
+
export { IInset } from './IInset';
|
|
3
|
+
export { InsetMask } from './InsetMask';
|
|
4
|
+
export { IInsetCallbackFunc } from './IInsetCallbackFunc';
|
|
5
|
+
export { IInsetConfiguration } from './IInsetConfiguration';
|