@ng-native/device 0.17.1 → 0.18.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/dist/accessibility.js +24 -8
- package/dist/accessibility.js.map +1 -1
- package/dist/conditions.js +11 -4
- package/dist/conditions.js.map +1 -1
- package/dist/dialogs.d.ts +7 -1
- package/dist/dialogs.js +7 -2
- package/dist/dialogs.js.map +1 -1
- package/dist/hardware-back.d.ts +3 -1
- package/dist/hardware-back.js +19 -2
- package/dist/hardware-back.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/keyboard.d.ts +48 -3
- package/dist/keyboard.js +97 -6
- package/dist/keyboard.js.map +1 -1
- package/dist/navigation-bar.js +5 -4
- package/dist/navigation-bar.js.map +1 -1
- package/dist/os.d.ts +10 -0
- package/dist/os.js +18 -0
- package/dist/os.js.map +1 -0
- package/dist/react-native.d.ts +12 -1
- package/dist/react-native.js +8 -0
- package/dist/react-native.js.map +1 -1
- package/dist/safe-area.d.ts +11 -2
- package/dist/safe-area.js +25 -2
- package/dist/safe-area.js.map +1 -1
- package/dist/status-bar.js +6 -9
- package/dist/status-bar.js.map +1 -1
- package/dist/window-claims.d.ts +6 -3
- package/dist/window-claims.js +15 -9
- package/dist/window-claims.js.map +1 -1
- package/package.json +2 -2
package/dist/keyboard.js
CHANGED
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
* going, as it starts to move, with no duration, so a layout jumps there while the keyboard slides;
|
|
7
7
|
* `@ng-native/expo`'s `provideNativeKeyboard()` adds the duration and curve. See `keyboardSource`.
|
|
8
8
|
*/
|
|
9
|
-
import { DestroyRef, InjectionToken, Service, computed, inject, signal, } from '@angular/core';
|
|
10
|
-
import {
|
|
9
|
+
import { ApplicationRef, DestroyRef, InjectionToken, Service, computed, inject, signal, } from '@angular/core';
|
|
10
|
+
import { HostEngine, nativePlatform } from '@ng-native/fabric';
|
|
11
|
+
import { edgeToEdgeFlag, reactNative, } from "./react-native.js";
|
|
11
12
|
import * as i0 from "@angular/core";
|
|
12
13
|
/** The timing a keyboard event carries, when it carries any. */
|
|
13
14
|
function timingOf(event) {
|
|
@@ -25,7 +26,8 @@ const metricsOf = (event) => ({
|
|
|
25
26
|
*
|
|
26
27
|
* On iOS the Will events: they arrive as the keyboard starts to move, carrying its duration and
|
|
27
28
|
* curve, so a layout configured from them moves with the keyboard. The Did events arrive once it
|
|
28
|
-
* has landed, and a layout that waits for them moves after it
|
|
29
|
+
* has landed, and a layout that waits for them moves after it, so they are heard only until the
|
|
30
|
+
first Will event, for a keyboard already moving when listening starts. `keyboardWillChangeFrame` covers a
|
|
29
31
|
* keyboard that changes size while it is up - the predictive bar, another language's layout - and
|
|
30
32
|
* is ignored while it is down: UIKit posts one beside every show and hide as well, and the one
|
|
31
33
|
* beside a hide is the frame the keyboard leaves by, off the bottom of the screen.
|
|
@@ -33,6 +35,12 @@ const metricsOf = (event) => ({
|
|
|
33
35
|
* Android sends no Will events at all, so there it is the Did events. They arrive once the
|
|
34
36
|
* window's insets have changed, which is as the keyboard starts to move rather than once it has
|
|
35
37
|
* stopped, with a duration of zero: they say nothing of the motion.
|
|
38
|
+
*
|
|
39
|
+
* Both platforms report the keyboard's `screenY` from the top of the screen. iOS measures a view
|
|
40
|
+
* from there too. Android measures it from below the status bar when React Native's edge-to-edge
|
|
41
|
+
* flag is off, even in an app drawn under the bar, such as Expo Go, which leaves the flag off: its
|
|
42
|
+
* `measureInWindow` leaves out the bar's inset then. `windowTop` is that inset, zero when the flag
|
|
43
|
+
* is on, which a layout takes off `screenY` to compare the keyboard with a view it measured.
|
|
36
44
|
*/
|
|
37
45
|
export function keyboardSource() {
|
|
38
46
|
const native = reactNative();
|
|
@@ -40,18 +48,31 @@ export function keyboardSource() {
|
|
|
40
48
|
return { subscribe: () => () => { }, dismiss: () => { } };
|
|
41
49
|
const { Keyboard: keyboard, Platform } = native;
|
|
42
50
|
return {
|
|
51
|
+
get windowTop() {
|
|
52
|
+
return windowTopOf(native);
|
|
53
|
+
},
|
|
43
54
|
subscribe: (listener) => {
|
|
55
|
+
// A keyboard already up says nothing until it next moves. `Keyboard.js` keeps the last show
|
|
56
|
+
// it heard, from whenever React Native first loaded it.
|
|
57
|
+
const shown = keyboard.metrics?.();
|
|
58
|
+
const already = shown ? { height: shown.height, screenY: shown.screenY } : null;
|
|
44
59
|
if (Platform?.OS !== 'ios') {
|
|
45
60
|
const subscriptions = [
|
|
46
61
|
keyboard.addListener('keyboardDidShow', (event) => listener(metricsOf(event))),
|
|
47
62
|
keyboard.addListener('keyboardDidHide', () => listener({ height: 0 })),
|
|
48
63
|
];
|
|
64
|
+
if (already)
|
|
65
|
+
listener(already);
|
|
49
66
|
return () => subscriptions.forEach((subscription) => subscription.remove());
|
|
50
67
|
}
|
|
51
|
-
let up =
|
|
68
|
+
let up = already !== null;
|
|
69
|
+
// Started while the keyboard moves, the Will event is missed and `Keyboard.js` still holds
|
|
70
|
+
// where it started from, so the Did event says where it landed. After a Will event, the
|
|
71
|
+
// Will events say it all: a show a hide interrupts can land after the hide begins.
|
|
72
|
+
let heard = false;
|
|
52
73
|
const subscriptions = [
|
|
53
74
|
keyboard.addListener('keyboardWillShow', (event) => {
|
|
54
|
-
up = true;
|
|
75
|
+
up = heard = true;
|
|
55
76
|
listener(metricsOf(event));
|
|
56
77
|
}),
|
|
57
78
|
keyboard.addListener('keyboardWillChangeFrame', (event) => {
|
|
@@ -60,14 +81,54 @@ export function keyboardSource() {
|
|
|
60
81
|
}),
|
|
61
82
|
keyboard.addListener('keyboardWillHide', (event) => {
|
|
62
83
|
up = false;
|
|
84
|
+
heard = true;
|
|
63
85
|
listener({ height: 0, ...timingOf(event) });
|
|
64
86
|
}),
|
|
87
|
+
keyboard.addListener('keyboardDidShow', (event) => {
|
|
88
|
+
if (heard)
|
|
89
|
+
return;
|
|
90
|
+
up = true;
|
|
91
|
+
listener({ height: event.endCoordinates.height, screenY: event.endCoordinates.screenY });
|
|
92
|
+
}),
|
|
93
|
+
keyboard.addListener('keyboardDidHide', () => {
|
|
94
|
+
if (heard)
|
|
95
|
+
return;
|
|
96
|
+
up = false;
|
|
97
|
+
listener({ height: 0 });
|
|
98
|
+
}),
|
|
65
99
|
];
|
|
100
|
+
if (already)
|
|
101
|
+
listener(already);
|
|
66
102
|
return () => subscriptions.forEach((subscription) => subscription.remove());
|
|
67
103
|
},
|
|
68
104
|
dismiss: () => keyboard.dismiss(),
|
|
69
105
|
};
|
|
70
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Require React Native's `Keyboard.js` now, so it records each show and hide from here on.
|
|
109
|
+
*
|
|
110
|
+
* It keeps the last one it heard, which `keyboardSource` starts from, but only from when it is
|
|
111
|
+
* first required. Left to the `Keyboard` service, that is when the first `text-input` appears, and
|
|
112
|
+
* a keyboard the native header's search bar opened before then reads as down until it next moves.
|
|
113
|
+
*/
|
|
114
|
+
export function recordKeyboard() {
|
|
115
|
+
const native = reactNative();
|
|
116
|
+
if (native)
|
|
117
|
+
void native.Keyboard;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* What React Native's Android `measureInWindow` leaves out above a view: the status bar's height,
|
|
121
|
+
* unless its edge-to-edge flag is on. Zero on iOS.
|
|
122
|
+
*/
|
|
123
|
+
function windowTopOf(native) {
|
|
124
|
+
if (native.Platform?.OS !== 'android' || edgeToEdgeFlag(native))
|
|
125
|
+
return 0;
|
|
126
|
+
// `StatusBar.currentHeight` is the bar's height when the app started. The module's own constant
|
|
127
|
+
// is read from the window's current insets on each call, as the inset `measureInWindow` leaves
|
|
128
|
+
// out is: after a rotation the two still agree.
|
|
129
|
+
const manager = native.TurboModuleRegistry?.get('StatusBarManager');
|
|
130
|
+
return manager?.getConstants?.().HEIGHT ?? native.StatusBar?.currentHeight ?? 0;
|
|
131
|
+
}
|
|
71
132
|
export const KEYBOARD_MOTION = new InjectionToken('angular-native.keyboardMotion', { providedIn: 'root', factory: () => null });
|
|
72
133
|
/**
|
|
73
134
|
* Subscribed for the life of the app, which is the life of the service, and removed when the app
|
|
@@ -83,6 +144,8 @@ export class Keyboard {
|
|
|
83
144
|
factory: keyboardSource,
|
|
84
145
|
});
|
|
85
146
|
source = inject(Keyboard.SOURCE);
|
|
147
|
+
engine = inject(HostEngine, { optional: true });
|
|
148
|
+
app = inject(ApplicationRef, { optional: true });
|
|
86
149
|
current = signal({ height: 0 }, /* @ts-ignore */
|
|
87
150
|
...(ngDevMode ? [{ debugName: "current" }] : /* istanbul ignore next */ []));
|
|
88
151
|
frame = signal(null, /* @ts-ignore */
|
|
@@ -102,6 +165,26 @@ export class Keyboard {
|
|
|
102
165
|
* move with it instead. Elsewhere it is `metrics`, and a layout animates to where that says.
|
|
103
166
|
*/
|
|
104
167
|
followsMotion = this.source.subscribeMotion !== undefined;
|
|
168
|
+
/**
|
|
169
|
+
* How far below the top of the screen the window `measureInWindow` reports in starts: the status
|
|
170
|
+
* bar's height on Android unless React Native's edge-to-edge flag is on, and zero otherwise. The
|
|
171
|
+
* keyboard's top edge in that window is `screenY` less this. It changes with a rotation, so read
|
|
172
|
+
* it when comparing rather than keeping it.
|
|
173
|
+
*
|
|
174
|
+
* On Android, read from where React Native measures the app's root, which is drawn from the top
|
|
175
|
+
* of the screen: React Native takes the bar off its measurements as it lays the root out, and keeps
|
|
176
|
+
* doing so when the bar is hidden or shown later, until the root is laid out again. The bar's
|
|
177
|
+
* own height stands in where the root has not been measured.
|
|
178
|
+
*/
|
|
179
|
+
get windowTop() {
|
|
180
|
+
let top = this.source.windowTop ?? 0;
|
|
181
|
+
// ponytail: the first root component is taken to start at the top of the screen, as an app's
|
|
182
|
+
// root does; a root placed lower would read as a window starting higher.
|
|
183
|
+
const root = this.app?.components[0]?.location.nativeElement;
|
|
184
|
+
if (root && nativePlatform() === 'android')
|
|
185
|
+
this.engine?.measure(root, (frame) => (top = -frame.y));
|
|
186
|
+
return top;
|
|
187
|
+
}
|
|
105
188
|
/** Where the keyboard is now: at every frame of its motion where `followsMotion`. */
|
|
106
189
|
position = computed(() => this.frame() ?? this.current(), /* @ts-ignore */
|
|
107
190
|
...(ngDevMode ? [{ debugName: "position" }] : /* istanbul ignore next */ []));
|
|
@@ -112,8 +195,16 @@ export class Keyboard {
|
|
|
112
195
|
if (stop)
|
|
113
196
|
destroyRef.onDestroy(stop);
|
|
114
197
|
}
|
|
115
|
-
/**
|
|
198
|
+
/**
|
|
199
|
+
* Put the keyboard away, as tapping outside a field would: the focused text field is sent
|
|
200
|
+
* `blur`, as a scroll view does at such a tap. A focused view or button is left as it is.
|
|
201
|
+
*
|
|
202
|
+
* React Native's own `Keyboard.dismiss()`, which the source calls too, blurs only a field its
|
|
203
|
+
* `TextInput` component recorded in `TextInputState`. A `text-input` here is the native component
|
|
204
|
+
* with no `TextInput.js` around it, so nothing is recorded and that call alone blurs nothing.
|
|
205
|
+
*/
|
|
116
206
|
dismiss() {
|
|
207
|
+
this.engine?.blurFocused();
|
|
117
208
|
this.source.dismiss();
|
|
118
209
|
}
|
|
119
210
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: Keyboard, deps: [], target: i0.ɵɵFactoryTarget.Service });
|
package/dist/keyboard.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyboard.js","sourceRoot":"","sources":["../src/keyboard.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACL,UAAU,EACV,cAAc,EACd,OAAO,EACP,QAAQ,EACR,MAAM,EACN,MAAM,GAEP,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,WAAW,EAA4B,MAAM,mBAAmB,CAAC;;AA+B1E,gEAAgE;AAChE,SAAS,QAAQ,CAAC,KAA0B;IAC1C,IAAI,KAAK,CAAC,QAAQ,KAAK,SAAS;QAAE,OAAO,EAAE,CAAC;IAC5C,OAAO,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAA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EAAC,CAAC;IAE9D;;;OAGG;IACM,OAAO,GAA4B,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;IAC7D,MAAM,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,MAAM;+EAAC,CAAC;IAC/C,OAAO,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,MAAM,GAAG,CAAC;gFAAC,CAAC;IAE7D;;;;OAIG;IACM,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC,eAAe,KAAK,SAAS,CAAC;IAEnE,qFAAqF;IAC5E,QAAQ,GAA4B,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,IAAI,CAAC,OAAO,EAAE;iFAAC,CAAC;IAE5F;QACE,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;QACtC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACpF,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;QAC7E,IAAI,IAAI;YAAE,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;IAED,+DAA+D;IAC/D,OAAO;QACL,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;IACxB,CAAC;uGAzCU,QAAQ;wGAAR,QAAQ;;2FAAR,QAAQ;kBADpB,OAAO","sourcesContent":["/**\n * The software keyboard: where it is, and how long it takes to get there.\n *\n * On iOS the metrics change as the keyboard starts to move, with the duration and curve it is\n * moving on, so a layout can move with it. On Android React Native says only where the keyboard is\n * going, as it starts to move, with no duration, so a layout jumps there while the keyboard slides;\n * `@ng-native/expo`'s `provideNativeKeyboard()` adds the duration and curve. See `keyboardSource`.\n */\nimport {\n DestroyRef,\n InjectionToken,\n Service,\n computed,\n inject,\n signal,\n type Signal,\n} from '@angular/core';\nimport { reactNative, type NativeKeyboardEvent } from './react-native.ts';\n\n/** What the platform reports when the keyboard moves. */\nexport interface KeyboardMetrics {\n /** Height in dp; zero when the keyboard is hidden. */\n readonly height: number;\n /** Where its top edge is, from the top of the screen. Absent when hidden. */\n readonly screenY?: number;\n /** How long its own animation takes, in ms, for anything moving with it. */\n readonly duration?: number;\n /**\n * The curve its own animation runs on, for anything moving with it to match: one of\n * `LayoutEasing`'s names. On iOS that is usually `'keyboard'`, the keyboard's own curve. React\n * Native's own events on Android carry `'keyboard'` with a duration of zero: they say where the\n * keyboard is going and nothing of how it gets there, so nothing should try to animate alongside\n * them. `provideNativeKeyboard()` reports Android's duration, with `'easeOut'`.\n */\n readonly easing?: string;\n}\n\n/** Where the metrics come from. A fake stands in for the platform in tests. */\nexport interface KeyboardSource {\n subscribe(listener: (metrics: KeyboardMetrics) => void): () => void;\n /**\n * Where the keyboard is at each frame of its motion, for a source that knows: before the motion\n * starts, at every frame of it, and null once it is over. One that does not has no such method.\n */\n subscribeMotion?(listener: (frame: KeyboardMetrics | null) => void): () => void;\n dismiss(): void;\n}\n\n/** The timing a keyboard event carries, when it carries any. */\nfunction timingOf(event: NativeKeyboardEvent): Pick<KeyboardMetrics, 'duration' | 'easing'> {\n if (event.duration === undefined) return {};\n return { duration: event.duration, easing: event.easing };\n}\n\nconst metricsOf = (event: NativeKeyboardEvent): KeyboardMetrics => ({\n height: event.endCoordinates.height,\n screenY: event.endCoordinates.screenY,\n ...timingOf(event),\n});\n\n/**\n * The events RN's own KeyboardAvoidingView listens for, which differ by platform.\n *\n * On iOS the Will events: they arrive as the keyboard starts to move, carrying its duration and\n * curve, so a layout configured from them moves with the keyboard. The Did events arrive once it\n * has landed, and a layout that waits for them moves after it. `keyboardWillChangeFrame` covers a\n * keyboard that changes size while it is up - the predictive bar, another language's layout - and\n * is ignored while it is down: UIKit posts one beside every show and hide as well, and the one\n * beside a hide is the frame the keyboard leaves by, off the bottom of the screen.\n *\n * Android sends no Will events at all, so there it is the Did events. They arrive once the\n * window's insets have changed, which is as the keyboard starts to move rather than once it has\n * stopped, with a duration of zero: they say nothing of the motion.\n */\nexport function keyboardSource(): KeyboardSource {\n const native = reactNative();\n if (!native) return { subscribe: () => () => {}, dismiss: () => {} };\n const { Keyboard: keyboard, Platform } = native;\n\n return {\n subscribe: (listener) => {\n if (Platform?.OS !== 'ios') {\n const subscriptions = [\n keyboard.addListener('keyboardDidShow', (event) => listener(metricsOf(event))),\n keyboard.addListener('keyboardDidHide', () => listener({ height: 0 })),\n ];\n return () => subscriptions.forEach((subscription) => subscription.remove());\n }\n let up = false;\n const subscriptions = [\n keyboard.addListener('keyboardWillShow', (event) => {\n up = true;\n listener(metricsOf(event));\n }),\n keyboard.addListener('keyboardWillChangeFrame', (event) => {\n if (up) listener(metricsOf(event));\n }),\n keyboard.addListener('keyboardWillHide', (event) => {\n up = false;\n listener({ height: 0, ...timingOf(event) });\n }),\n ];\n return () => subscriptions.forEach((subscription) => subscription.remove());\n },\n dismiss: () => keyboard.dismiss(),\n };\n}\n\n/**\n * A native view that reports the keyboard's motion frame by frame, for a view to follow it on the\n * native side: a `<keyboard-dock>` on Android, where React Native says only where the keyboard\n * is going. `@ng-native/expo`'s `provideNativeKeyboard()` provides one; without it this is null.\n *\n * The view sends `onKeyboardMoveStart`, `onKeyboardMove` and `onKeyboardMoveEnd`, each with the\n * `height` of the keyboard over the view's own bottom edge, in points, and is laid out over the\n * element it reports for.\n */\nexport interface KeyboardMotion {\n /** The Fabric name of the view. */\n readonly viewName: string;\n}\n\nexport const KEYBOARD_MOTION = new InjectionToken<KeyboardMotion | null>(\n 'angular-native.keyboardMotion',\n { providedIn: 'root', factory: () => null },\n);\n\n/**\n * Subscribed for the life of the app, which is the life of the service, and removed when the app\n * is destroyed. A component that mounts mid-gesture wants the height that is already true rather\n * than the next change, which is why the subscription is the service's and not the component's.\n */\n@Service()\nexport class Keyboard {\n /**\n * Where the metrics actually come from. Overriding this token is how a test drives the keyboard,\n * and it is finer than replacing the service: the code under test stays the real thing.\n */\n static readonly SOURCE = new InjectionToken<KeyboardSource>('angular-native.keyboardSource', {\n factory: keyboardSource,\n });\n\n private readonly source = inject(Keyboard.SOURCE);\n private readonly current = signal<KeyboardMetrics>({ height: 0 });\n private readonly frame = signal<KeyboardMetrics | null>(null);\n\n /**\n * Everything the platform said, for a layout that needs the animation duration too. It changes\n * as the keyboard starts to move, to where the keyboard is going.\n */\n readonly metrics: Signal<KeyboardMetrics> = this.current.asReadonly();\n readonly height = computed(() => this.current().height);\n readonly visible = computed(() => this.current().height > 0);\n\n /**\n * Whether `position` follows the keyboard frame by frame: on Android with `@ng-native/expo`'s\n * `provideNativeKeyboard()`, where a layout cannot animate alongside the keyboard and has to\n * move with it instead. Elsewhere it is `metrics`, and a layout animates to where that says.\n */\n readonly followsMotion = this.source.subscribeMotion !== undefined;\n\n /** Where the keyboard is now: at every frame of its motion where `followsMotion`. */\n readonly position: Signal<KeyboardMetrics> = computed(() => this.frame() ?? this.current());\n\n constructor() {\n const destroyRef = inject(DestroyRef);\n destroyRef.onDestroy(this.source.subscribe((metrics) => this.current.set(metrics)));\n const stop = this.source.subscribeMotion?.((frame) => this.frame.set(frame));\n if (stop) destroyRef.onDestroy(stop);\n }\n\n /** Put the keyboard away, as tapping outside a field would. */\n dismiss(): void {\n this.source.dismiss();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"keyboard.js","sourceRoot":"","sources":["../src/keyboard.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACL,cAAc,EACd,UAAU,EACV,cAAc,EACd,OAAO,EACP,QAAQ,EACR,MAAM,EACN,MAAM,GAEP,MAAM,eAAe,CAAC;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AAQ;wGAAR,QAAQ;;2FAAR,QAAQ;kBADpB,OAAO","sourcesContent":["/**\n * The software keyboard: where it is, and how long it takes to get there.\n *\n * On iOS the metrics change as the keyboard starts to move, with the duration and curve it is\n * moving on, so a layout can move with it. On Android React Native says only where the keyboard is\n * going, as it starts to move, with no duration, so a layout jumps there while the keyboard slides;\n * `@ng-native/expo`'s `provideNativeKeyboard()` adds the duration and curve. See `keyboardSource`.\n */\nimport {\n ApplicationRef,\n DestroyRef,\n InjectionToken,\n Service,\n computed,\n inject,\n signal,\n type Signal,\n} from '@angular/core';\nimport { HostEngine, nativePlatform, type HostNode } from '@ng-native/fabric';\nimport {\n edgeToEdgeFlag,\n reactNative,\n type NativeKeyboardEvent,\n type ReactNative,\n} from './react-native.ts';\n\n/** What the platform reports when the keyboard moves. */\nexport interface KeyboardMetrics {\n /** Height in dp; zero when the keyboard is hidden. */\n readonly height: number;\n /**\n * Where its top edge is, from the top of the screen. Absent when hidden. A view measured in the\n * window is compared with it less `Keyboard.windowTop`.\n */\n readonly screenY?: number;\n /** How long its own animation takes, in ms, for anything moving with it. */\n readonly duration?: number;\n /**\n * The curve its own animation runs on, for anything moving with it to match: one of\n * `LayoutEasing`'s names. On iOS that is usually `'keyboard'`, the keyboard's own curve. React\n * Native's own events on Android carry `'keyboard'` with a duration of zero: they say where the\n * keyboard is going and nothing of how it gets there, so nothing should try to animate alongside\n * them. `provideNativeKeyboard()` reports Android's duration, with `'easeOut'`.\n */\n readonly easing?: string;\n}\n\n/** Where the metrics come from. A fake stands in for the platform in tests. */\nexport interface KeyboardSource {\n subscribe(listener: (metrics: KeyboardMetrics) => void): () => void;\n /**\n * Where the keyboard is at each frame of its motion, for a source that knows: before the motion\n * starts, at every frame of it, and null once it is over. One that does not has no such method.\n */\n subscribeMotion?(listener: (frame: KeyboardMetrics | null) => void): () => void;\n dismiss(): void;\n /**\n * How far below the top of the screen the window a view is measured in starts, in points, for\n * a source that knows it is not zero. Read when it is compared, as it changes with the status\n * bar. See `keyboardSource`.\n */\n readonly windowTop?: number;\n}\n\n/** The timing a keyboard event carries, when it carries any. */\nfunction timingOf(event: NativeKeyboardEvent): Pick<KeyboardMetrics, 'duration' | 'easing'> {\n if (event.duration === undefined) return {};\n return { duration: event.duration, easing: event.easing };\n}\n\nconst metricsOf = (event: NativeKeyboardEvent): KeyboardMetrics => ({\n height: event.endCoordinates.height,\n screenY: event.endCoordinates.screenY,\n ...timingOf(event),\n});\n\n/**\n * The events RN's own KeyboardAvoidingView listens for, which differ by platform.\n *\n * On iOS the Will events: they arrive as the keyboard starts to move, carrying its duration and\n * curve, so a layout configured from them moves with the keyboard. The Did events arrive once it\n * has landed, and a layout that waits for them moves after it, so they are heard only until the\nfirst Will event, for a keyboard already moving when listening starts. `keyboardWillChangeFrame` covers a\n * keyboard that changes size while it is up - the predictive bar, another language's layout - and\n * is ignored while it is down: UIKit posts one beside every show and hide as well, and the one\n * beside a hide is the frame the keyboard leaves by, off the bottom of the screen.\n *\n * Android sends no Will events at all, so there it is the Did events. They arrive once the\n * window's insets have changed, which is as the keyboard starts to move rather than once it has\n * stopped, with a duration of zero: they say nothing of the motion.\n *\n * Both platforms report the keyboard's `screenY` from the top of the screen. iOS measures a view\n * from there too. Android measures it from below the status bar when React Native's edge-to-edge\n * flag is off, even in an app drawn under the bar, such as Expo Go, which leaves the flag off: its\n * `measureInWindow` leaves out the bar's inset then. `windowTop` is that inset, zero when the flag\n * is on, which a layout takes off `screenY` to compare the keyboard with a view it measured.\n */\nexport function keyboardSource(): KeyboardSource {\n const native = reactNative();\n if (!native) return { subscribe: () => () => {}, dismiss: () => {} };\n const { Keyboard: keyboard, Platform } = native;\n\n return {\n get windowTop() {\n return windowTopOf(native);\n },\n subscribe: (listener) => {\n // A keyboard already up says nothing until it next moves. `Keyboard.js` keeps the last show\n // it heard, from whenever React Native first loaded it.\n const shown = keyboard.metrics?.();\n const already = shown ? { height: shown.height, screenY: shown.screenY } : null;\n if (Platform?.OS !== 'ios') {\n const subscriptions = [\n keyboard.addListener('keyboardDidShow', (event) => listener(metricsOf(event))),\n keyboard.addListener('keyboardDidHide', () => listener({ height: 0 })),\n ];\n if (already) listener(already);\n return () => subscriptions.forEach((subscription) => subscription.remove());\n }\n let up = already !== null;\n // Started while the keyboard moves, the Will event is missed and `Keyboard.js` still holds\n // where it started from, so the Did event says where it landed. After a Will event, the\n // Will events say it all: a show a hide interrupts can land after the hide begins.\n let heard = false;\n const subscriptions = [\n keyboard.addListener('keyboardWillShow', (event) => {\n up = heard = true;\n listener(metricsOf(event));\n }),\n keyboard.addListener('keyboardWillChangeFrame', (event) => {\n if (up) listener(metricsOf(event));\n }),\n keyboard.addListener('keyboardWillHide', (event) => {\n up = false;\n heard = true;\n listener({ height: 0, ...timingOf(event) });\n }),\n keyboard.addListener('keyboardDidShow', (event) => {\n if (heard) return;\n up = true;\n listener({ height: event.endCoordinates.height, screenY: event.endCoordinates.screenY });\n }),\n keyboard.addListener('keyboardDidHide', () => {\n if (heard) return;\n up = false;\n listener({ height: 0 });\n }),\n ];\n if (already) listener(already);\n return () => subscriptions.forEach((subscription) => subscription.remove());\n },\n dismiss: () => keyboard.dismiss(),\n };\n}\n\n/**\n * Require React Native's `Keyboard.js` now, so it records each show and hide from here on.\n *\n * It keeps the last one it heard, which `keyboardSource` starts from, but only from when it is\n * first required. Left to the `Keyboard` service, that is when the first `text-input` appears, and\n * a keyboard the native header's search bar opened before then reads as down until it next moves.\n */\nexport function recordKeyboard(): void {\n const native = reactNative();\n if (native) void native.Keyboard;\n}\n\n/**\n * What React Native's Android `measureInWindow` leaves out above a view: the status bar's height,\n * unless its edge-to-edge flag is on. Zero on iOS.\n */\nfunction windowTopOf(native: ReactNative): number {\n if (native.Platform?.OS !== 'android' || edgeToEdgeFlag(native)) return 0;\n // `StatusBar.currentHeight` is the bar's height when the app started. The module's own constant\n // is read from the window's current insets on each call, as the inset `measureInWindow` leaves\n // out is: after a rotation the two still agree.\n const manager = native.TurboModuleRegistry?.get('StatusBarManager') as\n { getConstants?(): { HEIGHT?: number } } | null | undefined;\n return manager?.getConstants?.().HEIGHT ?? native.StatusBar?.currentHeight ?? 0;\n}\n\n/**\n * A native view that reports the keyboard's motion frame by frame, for a view to follow it on the\n * native side: a `<keyboard-dock>` on Android, where React Native says only where the keyboard\n * is going. `@ng-native/expo`'s `provideNativeKeyboard()` provides one; without it this is null.\n *\n * The view sends `onKeyboardMoveStart`, `onKeyboardMove` and `onKeyboardMoveEnd`, each with the\n * `height` of the keyboard over the view's own bottom edge, in points, and is laid out over the\n * element it reports for.\n */\nexport interface KeyboardMotion {\n /** The Fabric name of the view. */\n readonly viewName: string;\n}\n\nexport const KEYBOARD_MOTION = new InjectionToken<KeyboardMotion | null>(\n 'angular-native.keyboardMotion',\n { providedIn: 'root', factory: () => null },\n);\n\n/**\n * Subscribed for the life of the app, which is the life of the service, and removed when the app\n * is destroyed. A component that mounts mid-gesture wants the height that is already true rather\n * than the next change, which is why the subscription is the service's and not the component's.\n */\n@Service()\nexport class Keyboard {\n /**\n * Where the metrics actually come from. Overriding this token is how a test drives the keyboard,\n * and it is finer than replacing the service: the code under test stays the real thing.\n */\n static readonly SOURCE = new InjectionToken<KeyboardSource>('angular-native.keyboardSource', {\n factory: keyboardSource,\n });\n\n private readonly source = inject(Keyboard.SOURCE);\n private readonly engine = inject(HostEngine, { optional: true });\n private readonly app = inject(ApplicationRef, { optional: true });\n private readonly current = signal<KeyboardMetrics>({ height: 0 });\n private readonly frame = signal<KeyboardMetrics | null>(null);\n\n /**\n * Everything the platform said, for a layout that needs the animation duration too. It changes\n * as the keyboard starts to move, to where the keyboard is going.\n */\n readonly metrics: Signal<KeyboardMetrics> = this.current.asReadonly();\n readonly height = computed(() => this.current().height);\n readonly visible = computed(() => this.current().height > 0);\n\n /**\n * Whether `position` follows the keyboard frame by frame: on Android with `@ng-native/expo`'s\n * `provideNativeKeyboard()`, where a layout cannot animate alongside the keyboard and has to\n * move with it instead. Elsewhere it is `metrics`, and a layout animates to where that says.\n */\n readonly followsMotion = this.source.subscribeMotion !== undefined;\n\n /**\n * How far below the top of the screen the window `measureInWindow` reports in starts: the status\n * bar's height on Android unless React Native's edge-to-edge flag is on, and zero otherwise. The\n * keyboard's top edge in that window is `screenY` less this. It changes with a rotation, so read\n * it when comparing rather than keeping it.\n *\n * On Android, read from where React Native measures the app's root, which is drawn from the top\n * of the screen: React Native takes the bar off its measurements as it lays the root out, and keeps\n * doing so when the bar is hidden or shown later, until the root is laid out again. The bar's\n * own height stands in where the root has not been measured.\n */\n get windowTop(): number {\n let top = this.source.windowTop ?? 0;\n // ponytail: the first root component is taken to start at the top of the screen, as an app's\n // root does; a root placed lower would read as a window starting higher.\n const root = this.app?.components[0]?.location.nativeElement as HostNode | undefined;\n if (root && nativePlatform() === 'android')\n this.engine?.measure(root, (frame) => (top = -frame.y));\n return top;\n }\n\n /** Where the keyboard is now: at every frame of its motion where `followsMotion`. */\n readonly position: Signal<KeyboardMetrics> = computed(() => this.frame() ?? this.current());\n\n constructor() {\n const destroyRef = inject(DestroyRef);\n destroyRef.onDestroy(this.source.subscribe((metrics) => this.current.set(metrics)));\n const stop = this.source.subscribeMotion?.((frame) => this.frame.set(frame));\n if (stop) destroyRef.onDestroy(stop);\n }\n\n /**\n * Put the keyboard away, as tapping outside a field would: the focused text field is sent\n * `blur`, as a scroll view does at such a tap. A focused view or button is left as it is.\n *\n * React Native's own `Keyboard.dismiss()`, which the source calls too, blurs only a field its\n * `TextInput` component recorded in `TextInputState`. A `text-input` here is the native component\n * with no `TextInput.js` around it, so nothing is recorded and that call alone blurs nothing.\n */\n dismiss(): void {\n this.engine?.blurFocused();\n this.source.dismiss();\n }\n}\n"]}
|
package/dist/navigation-bar.js
CHANGED
|
@@ -18,16 +18,17 @@ import { WindowClaims, onWindowFront, sharedBySource } from "./window-claims.js"
|
|
|
18
18
|
import * as i0 from "@angular/core";
|
|
19
19
|
const NONE = { setStyle: () => { }, setHidden: () => { } };
|
|
20
20
|
export function navigationBarSource() {
|
|
21
|
+
// Copies: with no bar to share, each app claims its own.
|
|
21
22
|
if (reactNative()?.Platform?.OS !== 'android')
|
|
22
|
-
return NONE;
|
|
23
|
+
return { ...NONE };
|
|
23
24
|
const modules = globalThis.expo?.modules;
|
|
24
25
|
const native = modules?.['ExpoNavigationBar'];
|
|
25
26
|
// Without the module a claim changes nothing, so it does not ride on the screens either, where
|
|
26
27
|
// react-native-screens would hide the bar the next time one appears.
|
|
27
28
|
if (!native)
|
|
28
|
-
return NONE;
|
|
29
|
+
return { ...NONE };
|
|
29
30
|
// One per module, so every app the runtime mounts claims the same bar.
|
|
30
|
-
return sharedBySource(native, () => ({
|
|
31
|
+
return sharedBySource(navigationBarSource, native, () => ({
|
|
31
32
|
setStyle: (style) => void native.setStyle?.(style)?.catch(() => { }),
|
|
32
33
|
setHidden: (hidden) => void native.setHidden?.(hidden)?.catch(() => { }),
|
|
33
34
|
screensSetBar: true,
|
|
@@ -45,7 +46,7 @@ export class NavigationBar {
|
|
|
45
46
|
/** This app, among the apps claiming the bar: its scheme is what an `auto` style it claims follows. */
|
|
46
47
|
owner = { scheme: inject(ColorScheme) };
|
|
47
48
|
/** Every app's claims on this bar: the window is the runtime's, not an app's. */
|
|
48
|
-
window = sharedBySource(this.source, () => new NavigationBarWindow(this.source));
|
|
49
|
+
window = sharedBySource(NavigationBarWindow, this.source, () => new NavigationBarWindow(this.source));
|
|
49
50
|
/** What is actually showing: every claim in order, later ones winning per property. */
|
|
50
51
|
state = this.window.state;
|
|
51
52
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"navigation-bar.js","sourceRoot":"","sources":["../src/navigation-bar.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EACL,UAAU,EACV,cAAc,EACd,OAAO,EACP,QAAQ,EACR,MAAM,EACN,SAAS,GAEV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,WAAW,EAAe,MAAM,mBAAmB,CAAC;AAC7D,OAAO,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S,CAAC,CAAC;QACrE,OAAO,KAAK,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,KAAM,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;IACpE,CAAC;IAEO,OAAO,CAAC,QAAkC,EAAE,KAAc;QAChE,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC9D,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED,yFAAyF;AACzF,SAAS,OAAO,CAAC,KAAyB,EAAE,MAAc;IACxD,IAAI,KAAK,KAAK,MAAM;QAAE,OAAO,KAAK,CAAC;IACnC,OAAO,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;AAC9C,CAAC","sourcesContent":["/**\n * Android's navigation bar: the colour of its buttons, and whether it is there at all.\n *\n * The same stack of claims as `StatusBar`, so a video player can hide the bar while it is open and\n * the screen behind gets the bar back when it closes. `style: 'auto'` follows `ColorScheme`, a\n * theme the app sets included, and a fixed style holds through a scheme change.\n *\n * Driven through `expo-navigation-bar`'s native module, reached by name so nothing here imports the\n * package. Expo Go carries it; a development build has it once the app installs\n * `expo-navigation-bar`. Without it, and on iOS, which has no navigation bar, every claim is kept\n * but changes nothing.\n */\nimport {\n DestroyRef,\n InjectionToken,\n Service,\n computed,\n inject,\n untracked,\n type Signal,\n} from '@angular/core';\nimport { ColorScheme, type Scheme } from './color-scheme.ts';\nimport { mergeClaims } from './merge-claims.ts';\nimport { reactNative } from './react-native.ts';\nimport { WindowClaims, onWindowFront, sharedBySource } from './window-claims.ts';\n\n/**\n * The colour of the bar's buttons. `dark` is dark buttons, for a light screen behind them, and\n * `light` light ones, as `StatusBarStyle` names its text. `auto` is dark buttons in the light\n * colour scheme and light ones in the dark one, and follows `ColorScheme`.\n */\nexport type NavigationBarStyle = 'light' | 'dark' | 'auto';\n\n/** What a claim asks for. Anything absent is left as whatever the claim underneath said. */\nexport interface NavigationBarState {\n readonly style?: NavigationBarStyle;\n /** Hide the bar until a swipe from the edge of the screen shows it for a moment. */\n readonly hidden?: boolean;\n}\n\n/** Where the bar actually is. A fake stands in for the platform in tests. */\nexport interface NavigationBarSource {\n setStyle(style: Exclude<NavigationBarStyle, 'auto'>): void;\n setHidden(hidden: boolean): void;\n /**\n * react-native-screens shows or hides the bar each time a screen appears, from that screen's own\n * `navigationBarHidden`, once any screen has set one. So a hidden claim rides on every screen too.\n */\n readonly screensSetBar?: boolean;\n /** Calls `listener` when a window comes to the front, to be given the whole bar again. */\n onWindowFront?(listener: () => void): () => void;\n}\n\n/** `expo-navigation-bar`'s native module, as much of it as this uses. */\ninterface NativeNavigationBar {\n setStyle?(style: 'light' | 'dark'): Promise<void>;\n setHidden?(hidden: boolean): Promise<void>;\n}\n\nconst NONE: NavigationBarSource = { setStyle: () => {}, setHidden: () => {} };\n\nexport function navigationBarSource(): NavigationBarSource {\n if (reactNative()?.Platform?.OS !== 'android') return NONE;\n const modules = (globalThis as { expo?: { modules?: Record<string, unknown> } }).expo?.modules;\n const native = modules?.['ExpoNavigationBar'] as NativeNavigationBar | undefined;\n // Without the module a claim changes nothing, so it does not ride on the screens either, where\n // react-native-screens would hide the bar the next time one appears.\n if (!native) return NONE;\n // One per module, so every app the runtime mounts claims the same bar.\n return sharedBySource(native, () => ({\n setStyle: (style) => void native.setStyle?.(style)?.catch(() => {}),\n setHidden: (hidden) => void native.setHidden?.(hidden)?.catch(() => {}),\n screensSetBar: true,\n onWindowFront,\n }));\n}\n\n/**\n * A stack, not a setter, for the same reason as `StatusBar`'s: whatever hid the bar has to give it\n * back to whatever was there before. `push` returns the function that drops the claim.\n */\n@Service()\nexport class NavigationBar {\n /** Overridden in a test to watch the bar without one on screen. */\n static readonly SOURCE = new InjectionToken<NavigationBarSource>(\n 'angular-native.navigationBarSource',\n { factory: navigationBarSource },\n );\n\n private readonly source = inject(NavigationBar.SOURCE);\n /** This app, among the apps claiming the bar: its scheme is what an `auto` style it claims follows. */\n private readonly owner: Owner = { scheme: inject(ColorScheme) };\n /** Every app's claims on this bar: the window is the runtime's, not an app's. */\n private readonly window = sharedBySource(this.source, () => new NavigationBarWindow(this.source));\n\n /** What is actually showing: every claim in order, later ones winning per property. */\n readonly state: Signal<NavigationBarState> = this.window.state;\n\n /**\n * What a screen with no `navigationBarHidden` of its own carries, so the claim still holds when\n * it appears. Empty but on Android. The router passes it on.\n */\n readonly forScreens: Signal<{ readonly hidden?: boolean }> = computed(() =>\n this.source.screensSetBar ? { hidden: this.state().hidden } : {},\n );\n\n constructor() {\n // Straight from the source, as `StatusBar` does, so the buttons change in the same turn as the\n // scheme.\n const stop = inject(ColorScheme.SOURCE).subscribe((scheme) =>\n this.window.schemeChanged(this.owner, scheme),\n );\n inject(DestroyRef).onDestroy(() => {\n stop();\n // An app that goes takes its claims with it, and leaves the bar to the apps still here.\n this.window.claims.drop(this.owner);\n this.window.apply();\n });\n }\n\n /** The base claim, for an app that sets the bar once at startup. */\n set(state: NavigationBarState): void {\n this.window.claims.setBase(this.owner, state);\n this.window.apply();\n }\n\n /** A claim on top of whatever is there. Call the returned function to drop it. */\n push(state: NavigationBarState): () => void {\n const drop = this.window.claims.push(this.owner, { ...state });\n this.window.apply();\n return () => {\n drop();\n this.window.apply();\n };\n }\n}\n\ninterface Owner {\n readonly scheme: ColorScheme;\n}\n\n/** The bar, as every app on one source claims it. */\nclass NavigationBarWindow {\n readonly claims = new WindowClaims<NavigationBarState, Owner>();\n readonly state: Signal<NavigationBarState> = computed(() =>\n mergeClaims(this.claims.all().map((claim) => claim.value)),\n );\n\n /** The properties a claim has had the platform change, which no claim names any more. */\n private readonly changed = new Set<keyof NavigationBarState>();\n\n /** Whether a claim has ever set the style, after which an unclaimed bar follows the scheme. */\n private styled = false;\n\n private readonly source: NavigationBarSource;\n\n constructor(source: NavigationBarSource) {\n this.source = source;\n // Lives as long as the source, which is the runtime's.\n source.onWindowFront?.(() => this.apply(true));\n }\n\n /**\n * Android puts the buttons back to the new scheme's own on a scheme change, so a fixed style is\n * sent again too. A bar no style claim names any more is `auto`, once one has named a style, and\n * follows the scheme the listener heard.\n */\n schemeChanged(owner: Owner, scheme: Scheme): void {\n const claimed = untracked(() => this.styleOwner());\n if (claimed && claimed.owner !== owner) return;\n const style = claimed?.style ?? (this.styled ? 'auto' : undefined);\n if (style !== undefined) this.source.setStyle(resolve(style, scheme));\n }\n\n /**\n * Push the merged state at the platform. A property the last claim to name it has dropped goes\n * back, once: the style to `auto`, which then keeps following the scheme, and the bar to shown.\n * A window come to the front is given what is claimed, and an `auto` style once one was named.\n */\n apply(front = false): void {\n const { style, hidden } = untracked(this.state);\n if (this.changes('style', style) || (front && this.styled)) {\n this.styled = true;\n this.source.setStyle(\n resolve(\n style ?? 'auto',\n untracked(() => this.scheme()),\n ),\n );\n }\n if (this.changes('hidden', hidden)) this.source.setHidden(hidden ?? false);\n }\n\n /** The scheme of the app whose style is in force, or of the app that claimed last. */\n private scheme(): Scheme {\n const owner = this.styleOwner()?.owner ?? this.claims.owners().at(-1);\n return owner?.scheme.current() ?? 'light';\n }\n\n /** The style in force and the app whose claim it is. */\n private styleOwner(): { style: NavigationBarStyle; owner: Owner } | undefined {\n const claim = this.claims.last((state) => state.style !== undefined);\n return claim && { style: claim.value.style!, owner: claim.owner };\n }\n\n private changes(property: keyof NavigationBarState, value: unknown): boolean {\n if (value === undefined) return this.changed.delete(property);\n this.changed.add(property);\n return true;\n }\n}\n\n/** Dark buttons on the light scheme's light background, light ones on the dark one's. */\nfunction resolve(style: NavigationBarStyle, scheme: Scheme): 'light' | 'dark' {\n if (style !== 'auto') return style;\n return scheme === 'dark' ? 'light' : 'dark';\n}\n"]}
|
|
1
|
+
{"version":3,"file":"navigation-bar.js","sourceRoot":"","sources":["../src/navigation-bar.ts"],"names":[],"mappings":"AAA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AAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QACtE,OAAO,KAAK,EAAE,MAAM,CAAC,OAAO,EAAE,IAAI,OAAO,CAAC;IAC5C,CAAC;IAED,wDAAwD;IAChD,UAAU;QAChB,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC;QACrE,OAAO,KAAK,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,KAAM,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;IACpE,CAAC;IAEO,OAAO,CAAC,QAAkC,EAAE,KAAc;QAChE,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC9D,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED,yFAAyF;AACzF,SAAS,OAAO,CAAC,KAAyB,EAAE,MAAc;IACxD,IAAI,KAAK,KAAK,MAAM;QAAE,OAAO,KAAK,CAAC;IACnC,OAAO,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;AAC9C,CAAC","sourcesContent":["/**\n * Android's navigation bar: the colour of its buttons, and whether it is there at all.\n *\n * The same stack of claims as `StatusBar`, so a video player can hide the bar while it is open and\n * the screen behind gets the bar back when it closes. `style: 'auto'` follows `ColorScheme`, a\n * theme the app sets included, and a fixed style holds through a scheme change.\n *\n * Driven through `expo-navigation-bar`'s native module, reached by name so nothing here imports the\n * package. Expo Go carries it; a development build has it once the app installs\n * `expo-navigation-bar`. Without it, and on iOS, which has no navigation bar, every claim is kept\n * but changes nothing.\n */\nimport {\n DestroyRef,\n InjectionToken,\n Service,\n computed,\n inject,\n untracked,\n type Signal,\n} from '@angular/core';\nimport { ColorScheme, type Scheme } from './color-scheme.ts';\nimport { mergeClaims } from './merge-claims.ts';\nimport { reactNative } from './react-native.ts';\nimport { WindowClaims, onWindowFront, sharedBySource } from './window-claims.ts';\n\n/**\n * The colour of the bar's buttons. `dark` is dark buttons, for a light screen behind them, and\n * `light` light ones, as `StatusBarStyle` names its text. `auto` is dark buttons in the light\n * colour scheme and light ones in the dark one, and follows `ColorScheme`.\n */\nexport type NavigationBarStyle = 'light' | 'dark' | 'auto';\n\n/** What a claim asks for. Anything absent is left as whatever the claim underneath said. */\nexport interface NavigationBarState {\n readonly style?: NavigationBarStyle;\n /** Hide the bar until a swipe from the edge of the screen shows it for a moment. */\n readonly hidden?: boolean;\n}\n\n/** Where the bar actually is. A fake stands in for the platform in tests. */\nexport interface NavigationBarSource {\n setStyle(style: Exclude<NavigationBarStyle, 'auto'>): void;\n setHidden(hidden: boolean): void;\n /**\n * react-native-screens shows or hides the bar each time a screen appears, from that screen's own\n * `navigationBarHidden`, once any screen has set one. So a hidden claim rides on every screen too.\n */\n readonly screensSetBar?: boolean;\n /** Calls `listener` when a window comes to the front, to be given the whole bar again. */\n onWindowFront?(listener: () => void): () => void;\n}\n\n/** `expo-navigation-bar`'s native module, as much of it as this uses. */\ninterface NativeNavigationBar {\n setStyle?(style: 'light' | 'dark'): Promise<void>;\n setHidden?(hidden: boolean): Promise<void>;\n}\n\nconst NONE: NavigationBarSource = { setStyle: () => {}, setHidden: () => {} };\n\nexport function navigationBarSource(): NavigationBarSource {\n // Copies: with no bar to share, each app claims its own.\n if (reactNative()?.Platform?.OS !== 'android') return { ...NONE };\n const modules = (globalThis as { expo?: { modules?: Record<string, unknown> } }).expo?.modules;\n const native = modules?.['ExpoNavigationBar'] as NativeNavigationBar | undefined;\n // Without the module a claim changes nothing, so it does not ride on the screens either, where\n // react-native-screens would hide the bar the next time one appears.\n if (!native) return { ...NONE };\n // One per module, so every app the runtime mounts claims the same bar.\n return sharedBySource(navigationBarSource, native, () => ({\n setStyle: (style) => void native.setStyle?.(style)?.catch(() => {}),\n setHidden: (hidden) => void native.setHidden?.(hidden)?.catch(() => {}),\n screensSetBar: true,\n onWindowFront,\n }));\n}\n\n/**\n * A stack, not a setter, for the same reason as `StatusBar`'s: whatever hid the bar has to give it\n * back to whatever was there before. `push` returns the function that drops the claim.\n */\n@Service()\nexport class NavigationBar {\n /** Overridden in a test to watch the bar without one on screen. */\n static readonly SOURCE = new InjectionToken<NavigationBarSource>(\n 'angular-native.navigationBarSource',\n { factory: navigationBarSource },\n );\n\n private readonly source = inject(NavigationBar.SOURCE);\n /** This app, among the apps claiming the bar: its scheme is what an `auto` style it claims follows. */\n private readonly owner: Owner = { scheme: inject(ColorScheme) };\n /** Every app's claims on this bar: the window is the runtime's, not an app's. */\n private readonly window = sharedBySource(\n NavigationBarWindow,\n this.source,\n () => new NavigationBarWindow(this.source),\n );\n\n /** What is actually showing: every claim in order, later ones winning per property. */\n readonly state: Signal<NavigationBarState> = this.window.state;\n\n /**\n * What a screen with no `navigationBarHidden` of its own carries, so the claim still holds when\n * it appears. Empty but on Android. The router passes it on.\n */\n readonly forScreens: Signal<{ readonly hidden?: boolean }> = computed(() =>\n this.source.screensSetBar ? { hidden: this.state().hidden } : {},\n );\n\n constructor() {\n // Straight from the source, as `StatusBar` does, so the buttons change in the same turn as the\n // scheme.\n const stop = inject(ColorScheme.SOURCE).subscribe((scheme) =>\n this.window.schemeChanged(this.owner, scheme),\n );\n inject(DestroyRef).onDestroy(() => {\n stop();\n // An app that goes takes its claims with it, and leaves the bar to the apps still here.\n this.window.claims.drop(this.owner);\n this.window.apply();\n });\n }\n\n /** The base claim, for an app that sets the bar once at startup. */\n set(state: NavigationBarState): void {\n this.window.claims.setBase(this.owner, state);\n this.window.apply();\n }\n\n /** A claim on top of whatever is there. Call the returned function to drop it. */\n push(state: NavigationBarState): () => void {\n const drop = this.window.claims.push(this.owner, { ...state });\n this.window.apply();\n return () => {\n drop();\n this.window.apply();\n };\n }\n}\n\ninterface Owner {\n readonly scheme: ColorScheme;\n}\n\n/** The bar, as every app on one source claims it. */\nclass NavigationBarWindow {\n readonly claims = new WindowClaims<NavigationBarState, Owner>();\n readonly state: Signal<NavigationBarState> = computed(() =>\n mergeClaims(this.claims.all().map((claim) => claim.value)),\n );\n\n /** The properties a claim has had the platform change, which no claim names any more. */\n private readonly changed = new Set<keyof NavigationBarState>();\n\n /** Whether a claim has ever set the style, after which an unclaimed bar follows the scheme. */\n private styled = false;\n\n private readonly source: NavigationBarSource;\n\n constructor(source: NavigationBarSource) {\n this.source = source;\n // Lives as long as the source, which is the runtime's.\n source.onWindowFront?.(() => this.apply(true));\n }\n\n /**\n * Android puts the buttons back to the new scheme's own on a scheme change, so a fixed style is\n * sent again too. A bar no style claim names any more is `auto`, once one has named a style, and\n * follows the scheme the listener heard.\n */\n schemeChanged(owner: Owner, scheme: Scheme): void {\n const claimed = untracked(() => this.styleOwner());\n if (claimed && claimed.owner !== owner) return;\n const style = claimed?.style ?? (this.styled ? 'auto' : undefined);\n if (style !== undefined) this.source.setStyle(resolve(style, scheme));\n }\n\n /**\n * Push the merged state at the platform. A property the last claim to name it has dropped goes\n * back, once: the style to `auto`, which then keeps following the scheme, and the bar to shown.\n * A window come to the front is given what is claimed, and an `auto` style once one was named.\n */\n apply(front = false): void {\n const { style, hidden } = untracked(this.state);\n if (this.changes('style', style) || (front && this.styled)) {\n this.styled = true;\n this.source.setStyle(\n resolve(\n style ?? 'auto',\n untracked(() => this.scheme()),\n ),\n );\n }\n if (this.changes('hidden', hidden)) this.source.setHidden(hidden ?? false);\n }\n\n /** The scheme of the app whose style is in force, or of the app that claimed last. */\n private scheme(): Scheme {\n const owner = this.styleOwner()?.owner ?? this.claims.owners().at(-1);\n return owner?.scheme.current() ?? 'light';\n }\n\n /** The style in force and the app whose claim it is. */\n private styleOwner(): { style: NavigationBarStyle; owner: Owner } | undefined {\n const claim = this.claims.last((state) => state.style !== undefined);\n return claim && { style: claim.value.style!, owner: claim.owner };\n }\n\n private changes(property: keyof NavigationBarState, value: unknown): boolean {\n if (value === undefined) return this.changed.delete(property);\n this.changed.add(property);\n return true;\n }\n}\n\n/** Dark buttons on the light scheme's light background, light ones on the dark one's. */\nfunction resolve(style: NavigationBarStyle, scheme: Scheme): 'light' | 'dark' {\n if (style !== 'auto') return style;\n return scheme === 'dark' ? 'light' : 'dark';\n}\n"]}
|
package/dist/os.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { InjectionToken } from '@angular/core';
|
|
2
|
+
/**
|
|
3
|
+
* The operating system the app runs on: `Platform.OS` on a device, and `'web'` in the web host,
|
|
4
|
+
* which provides it. Off a device, in a test in Node, it is the platform the engine renders as,
|
|
5
|
+
* iOS unless `registerPlatformComponents` said otherwise.
|
|
6
|
+
*
|
|
7
|
+
* For a feature that depends on the platform, beside `OS_VERSION`, whose number is the API level
|
|
8
|
+
* on Android: a check for iOS 26 needs both. A test provides the OS it wants.
|
|
9
|
+
*/
|
|
10
|
+
export declare const OS: InjectionToken<"android" | "ios" | "web">;
|
package/dist/os.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { InjectionToken } from '@angular/core';
|
|
2
|
+
import { nativePlatform } from '@ng-native/fabric';
|
|
3
|
+
import { reactNative } from "./react-native.js";
|
|
4
|
+
/**
|
|
5
|
+
* The operating system the app runs on: `Platform.OS` on a device, and `'web'` in the web host,
|
|
6
|
+
* which provides it. Off a device, in a test in Node, it is the platform the engine renders as,
|
|
7
|
+
* iOS unless `registerPlatformComponents` said otherwise.
|
|
8
|
+
*
|
|
9
|
+
* For a feature that depends on the platform, beside `OS_VERSION`, whose number is the API level
|
|
10
|
+
* on Android: a check for iOS 26 needs both. A test provides the OS it wants.
|
|
11
|
+
*/
|
|
12
|
+
export const OS = new InjectionToken('angular-native.os', {
|
|
13
|
+
factory: () => {
|
|
14
|
+
const os = reactNative()?.Platform.OS ?? nativePlatform();
|
|
15
|
+
return os === 'android' || os === 'web' ? os : 'ios';
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
//# sourceMappingURL=os.js.map
|
package/dist/os.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"os.js","sourceRoot":"","sources":["../src/os.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,EAAE,GAAG,IAAI,cAAc,CAA4B,mBAAmB,EAAE;IACnF,OAAO,EAAE,GAAG,EAAE;QACZ,MAAM,EAAE,GAAG,WAAW,EAAE,EAAE,QAAQ,CAAC,EAAE,IAAI,cAAc,EAAE,CAAC;QAC1D,OAAO,EAAE,KAAK,SAAS,IAAI,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;IACvD,CAAC;CACF,CAAC,CAAC","sourcesContent":["import { InjectionToken } from '@angular/core';\nimport { nativePlatform } from '@ng-native/fabric';\nimport { reactNative } from './react-native.ts';\n\n/**\n * The operating system the app runs on: `Platform.OS` on a device, and `'web'` in the web host,\n * which provides it. Off a device, in a test in Node, it is the platform the engine renders as,\n * iOS unless `registerPlatformComponents` said otherwise.\n *\n * For a feature that depends on the platform, beside `OS_VERSION`, whose number is the API level\n * on Android: a check for iOS 26 needs both. A test provides the OS it wants.\n */\nexport const OS = new InjectionToken<'ios' | 'android' | 'web'>('angular-native.os', {\n factory: () => {\n const os = reactNative()?.Platform.OS ?? nativePlatform();\n return os === 'android' || os === 'web' ? os : 'ios';\n },\n});\n"]}
|
package/dist/react-native.d.ts
CHANGED
|
@@ -69,6 +69,11 @@ export interface ReactNative {
|
|
|
69
69
|
};
|
|
70
70
|
Keyboard: {
|
|
71
71
|
dismiss(): void;
|
|
72
|
+
/** Where the last show `Keyboard.js` heard put the keyboard, or nothing once it hid. */
|
|
73
|
+
metrics?(): {
|
|
74
|
+
height: number;
|
|
75
|
+
screenY: number;
|
|
76
|
+
} | null | undefined;
|
|
72
77
|
addListener(event: 'keyboardDidShow' | 'keyboardDidHide' | 'keyboardWillShow' | 'keyboardWillHide' | 'keyboardWillChangeFrame', handler: (event: NativeKeyboardEvent) => void): {
|
|
73
78
|
remove(): void;
|
|
74
79
|
};
|
|
@@ -80,6 +85,7 @@ export interface ReactNative {
|
|
|
80
85
|
ActionSheetIOS?: {
|
|
81
86
|
showActionSheetWithOptions(options: {
|
|
82
87
|
title?: string;
|
|
88
|
+
message?: string;
|
|
83
89
|
options: string[];
|
|
84
90
|
cancelButtonIndex: number;
|
|
85
91
|
destructiveButtonIndex?: number;
|
|
@@ -108,7 +114,7 @@ export interface ReactNative {
|
|
|
108
114
|
OS: string;
|
|
109
115
|
Version?: string | number;
|
|
110
116
|
};
|
|
111
|
-
/** Optional:
|
|
117
|
+
/** Optional: the status bar and keyboard read it, for `DeviceInfo`'s `isEdgeToEdge` on Android. */
|
|
112
118
|
TurboModuleRegistry?: {
|
|
113
119
|
get(name: string): unknown;
|
|
114
120
|
};
|
|
@@ -173,6 +179,11 @@ export interface NativeKeyboardEvent {
|
|
|
173
179
|
/** One of `LayoutEasing`'s names; usually `'keyboard'` on iOS, and always on Android, with a zero duration. */
|
|
174
180
|
readonly easing?: string;
|
|
175
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* React Native's edge-to-edge flag on Android, which its `DeviceInfo` module reports: whether it
|
|
184
|
+
* treats the app as drawn under the system bars, for its status bar and for where it measures from.
|
|
185
|
+
*/
|
|
186
|
+
export declare function edgeToEdgeFlag(native: ReactNative): boolean;
|
|
176
187
|
/**
|
|
177
188
|
* `null` off a device, where each capability falls back to doing nothing - the same as an
|
|
178
189
|
* optional injection token nobody provided.
|
package/dist/react-native.js
CHANGED
|
@@ -14,6 +14,14 @@
|
|
|
14
14
|
* dependencies an app may not have installed. React Native is not optional, so the seam buys
|
|
15
15
|
* nothing but files.
|
|
16
16
|
*/
|
|
17
|
+
/**
|
|
18
|
+
* React Native's edge-to-edge flag on Android, which its `DeviceInfo` module reports: whether it
|
|
19
|
+
* treats the app as drawn under the system bars, for its status bar and for where it measures from.
|
|
20
|
+
*/
|
|
21
|
+
export function edgeToEdgeFlag(native) {
|
|
22
|
+
const info = native.TurboModuleRegistry?.get('DeviceInfo');
|
|
23
|
+
return info?.getConstants?.().isEdgeToEdge === true;
|
|
24
|
+
}
|
|
17
25
|
/**
|
|
18
26
|
* `null` off a device, where each capability falls back to doing nothing - the same as an
|
|
19
27
|
* optional injection token nobody provided.
|
package/dist/react-native.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-native.js","sourceRoot":"","sources":["../src/react-native.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;
|
|
1
|
+
{"version":3,"file":"react-native.js","sourceRoot":"","sources":["../src/react-native.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAuJH;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,MAAmB;IAChD,MAAM,IAAI,GAAG,MAAM,CAAC,mBAAmB,EAAE,GAAG,CAAC,YAAY,CACW,CAAC;IACrE,OAAO,IAAI,EAAE,YAAY,EAAE,EAAE,CAAC,YAAY,KAAK,IAAI,CAAC;AACtD,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,WAAW;IACzB,IAAK,UAAkD,CAAC,qBAAqB,KAAK,SAAS,EAAE,CAAC;QAC5F,OAAO,IAAI,CAAC;IACd,CAAC;IACD,+FAA+F;IAC/F,8EAA8E;IAC9E,aAAa;IACb,IAAI,OAAO,OAAO,KAAK,UAAU;QAAE,OAAO,OAAO,CAAC,cAAc,CAAgB,CAAC;IACjF,OAAO,CAAC,KAAK,CACX,uFAAuF;QACrF,+DAA+D,CAClE,CAAC;IACF,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["/**\n * React Native's own modules, fetched when a service is first constructed rather than when this\n * file is loaded.\n *\n * The distinction matters more than it looks. React Native ships its JavaScript as Flow, which\n * Node cannot parse, so a static `import ... from 'react-native'` anywhere in this package would\n * make the package unimportable by the test suite - and by `@ng-native/components`, which\n * the suite imports constantly. A call inside a factory is only ever executed on a device, where\n * `react-native` is the most ordinary import there is.\n *\n * ponytail: a `require` in a codebase that otherwise has none. The alternative is the shape\n * `@ng-native/expo` uses - a file per service outside `src`, importing the module and\n * declaring the service - which is right there because Expo's packages are optional peer\n * dependencies an app may not have installed. React Native is not optional, so the seam buys\n * nothing but files.\n */\n\n/** The subset of React Native this package reaches for, described so `require` has a type. */\nexport interface ReactNative {\n AccessibilityInfo: {\n isScreenReaderEnabled(): Promise<boolean>;\n isReduceMotionEnabled(): Promise<boolean>;\n isBoldTextEnabled(): Promise<boolean>;\n announceForAccessibility(announcement: string): void;\n addEventListener(\n event: 'screenReaderChanged' | 'reduceMotionChanged' | 'boldTextChanged',\n handler: (value: boolean) => void,\n ): { remove(): void };\n };\n AppState: {\n currentState: string | null;\n addEventListener(event: 'change', handler: (state: string) => void): { remove(): void };\n };\n Appearance: {\n getColorScheme(): 'light' | 'dark' | null | undefined;\n addChangeListener(handler: (preferences: { colorScheme?: string | null }) => void): {\n remove(): void;\n };\n setColorScheme?(scheme: 'light' | 'dark' | 'unspecified'): void;\n };\n BackHandler: {\n addEventListener(event: 'hardwareBackPress', handler: () => boolean): { remove(): void };\n };\n Dimensions: {\n get(dimension: 'window' | 'screen'): { width: number; height: number };\n addEventListener(\n event: 'change',\n handler: (sizes: {\n window: { width: number; height: number };\n screen: { width: number; height: number };\n }) => void,\n ): { remove(): void };\n };\n I18nManager: {\n /** Whether the app is laid out right to left. Fixed for the lifetime of the process. */\n isRTL: boolean;\n };\n Keyboard: {\n dismiss(): void;\n /** Where the last show `Keyboard.js` heard put the keyboard, or nothing once it hid. */\n metrics?(): { height: number; screenY: number } | null | undefined;\n addListener(\n event:\n | 'keyboardDidShow'\n | 'keyboardDidHide'\n | 'keyboardWillShow'\n | 'keyboardWillHide'\n | 'keyboardWillChangeFrame',\n handler: (event: NativeKeyboardEvent) => void,\n ): { remove(): void };\n };\n StyleSheet: {\n /** The thinnest line the screen can draw, in points. `1 / PixelRatio.get()`, near enough. */\n hairlineWidth: number;\n };\n ActionSheetIOS?: {\n showActionSheetWithOptions(\n options: {\n title?: string;\n message?: string;\n options: string[];\n cancelButtonIndex: number;\n destructiveButtonIndex?: number;\n },\n callback: (index: number) => void,\n ): void;\n };\n Alert: {\n alert(\n title: string,\n message?: string,\n buttons?: { text?: string; style?: string; onPress?: () => void }[],\n options?: object,\n ): void;\n /** iOS only. Absent on Android, where there is no such dialog. */\n prompt?(\n title: string,\n message?: string,\n callbackOrButtons?:\n | ((value: string) => void)\n | { text?: string; style?: string; onPress?: (value?: string) => void }[],\n type?: string,\n defaultValue?: string,\n ): void;\n };\n PixelRatio: {\n get(): number;\n /** The user's text size setting, as a multiplier. One is the default. */\n getFontScale(): number;\n };\n /** `Version` is a string on iOS, `'26.5'`, and the API level, a number, on Android. */\n Platform: { OS: string; Version?: string | number };\n /** Optional: the status bar and keyboard read it, for `DeviceInfo`'s `isEdgeToEdge` on Android. */\n TurboModuleRegistry?: { get(name: string): unknown };\n Share: {\n share(\n content: { message?: string; url?: string; title?: string },\n options?: object,\n ): Promise<{ action: string; activityType?: string | null }>;\n };\n ToastAndroid?: {\n show(message: string, duration: number): void;\n SHORT: number;\n LONG: number;\n };\n Vibration: {\n vibrate(pattern?: number | number[], repeat?: boolean): void;\n cancel(): void;\n };\n DevSettings?: {\n addMenuItem(title: string, handler: () => unknown): void;\n reload(reason?: string): void;\n };\n LayoutAnimation: {\n configureNext(config: object, onDone?: () => void, onFail?: () => void): void;\n };\n PermissionsAndroid?: {\n check(permission: string): Promise<boolean>;\n request(permission: string, rationale?: object): Promise<string>;\n };\n StatusBar: {\n /** Android reports the bar's height in dp; iOS leaves it undefined. */\n currentHeight?: number;\n setBarStyle(style: string, animated?: boolean): void;\n setHidden(hidden: boolean, animation?: string): void;\n /** Removed in React Native 0.88, with edge-to-edge on every Android app. */\n setBackgroundColor?(color: string, animated?: boolean): void;\n /** Removed in React Native 0.88, with `setBackgroundColor`. */\n setTranslucent?(translucent: boolean): void;\n };\n Linking: {\n getInitialURL(): Promise<string | null>;\n openURL(url: string): Promise<unknown>;\n openSettings(): Promise<void>;\n addEventListener(event: 'url', handler: (event: { url: string }) => void): { remove(): void };\n };\n}\n\n/** What RN hands a keyboard listener. */\nexport interface NativeKeyboardEvent {\n readonly endCoordinates: { readonly height: number; readonly screenY: number };\n readonly duration?: number;\n /** One of `LayoutEasing`'s names; usually `'keyboard'` on iOS, and always on Android, with a zero duration. */\n readonly easing?: string;\n}\n\n/**\n * React Native's edge-to-edge flag on Android, which its `DeviceInfo` module reports: whether it\n * treats the app as drawn under the system bars, for its status bar and for where it measures from.\n */\nexport function edgeToEdgeFlag(native: ReactNative): boolean {\n const info = native.TurboModuleRegistry?.get('DeviceInfo') as\n { getConstants?(): { isEdgeToEdge?: boolean } } | null | undefined;\n return info?.getConstants?.().isEdgeToEdge === true;\n}\n\n/**\n * `null` off a device, where each capability falls back to doing nothing - the same as an\n * optional injection token nobody provided.\n *\n * The engine's presence is what tells the two apart. In Node and in a browser there is no\n * `nativeFabricUIManager`; on a device there is one, and a missing `require` would mean the bundler\n * stopped emitting CommonJS under us. That is worth saying out loud rather than quietly rendering\n * an app whose keyboard never moves.\n *\n * `require` alone cannot tell them apart: a browser bundle can have one. Rolldown gives a `vite\n * build` its own `require` for an external module, which passes `typeof require === 'function'`\n * and throws when called.\n */\nexport function reactNative(): ReactNative | null {\n if ((globalThis as { nativeFabricUIManager?: unknown }).nativeFabricUIManager === undefined) {\n return null;\n }\n // `require` has a type only where the app's tsconfig loads Node's or React Native's types, and\n // a browser app's loads neither. `@ts-expect-error` would fail where it does.\n // @ts-ignore\n if (typeof require === 'function') return require('react-native') as ReactNative;\n console.error(\n '[angular-native] react-native could not be required, so every platform capability is ' +\n 'inert. The bundle is not CommonJS; check the Metro transform.',\n );\n return null;\n}\n"]}
|
package/dist/safe-area.d.ts
CHANGED
|
@@ -30,6 +30,9 @@ export interface Frame {
|
|
|
30
30
|
export declare class SafeArea {
|
|
31
31
|
private readonly current;
|
|
32
32
|
private readonly measured;
|
|
33
|
+
/** What each provider still up last reported, the latest last. */
|
|
34
|
+
private readonly reports;
|
|
35
|
+
private reporter;
|
|
33
36
|
/** What the system occupies on each edge, in points. */
|
|
34
37
|
readonly insets: Signal<Insets>;
|
|
35
38
|
/**
|
|
@@ -37,7 +40,7 @@ export declare class SafeArea {
|
|
|
37
40
|
*
|
|
38
41
|
* On Android 15 that includes the system bars, because the app draws behind them - which is why
|
|
39
42
|
* `Screen.window` reads this rather than `Dimensions`. Null until the provider has laid out,
|
|
40
|
-
* one frame after the app mounts.
|
|
43
|
+
* one frame after the app mounts, and again once every provider that reported is destroyed.
|
|
41
44
|
*/
|
|
42
45
|
readonly frame: Signal<Frame | null>;
|
|
43
46
|
/** Whether anything has reported yet, for a layout that would rather wait than jump. */
|
|
@@ -46,7 +49,13 @@ export declare class SafeArea {
|
|
|
46
49
|
* Called by `<safe-area-provider>` when native reports. Not for apps: an inset written from
|
|
47
50
|
* anywhere else is a number that stops matching the screen the moment the device rotates.
|
|
48
51
|
*/
|
|
49
|
-
report(insets: Insets, frame: Frame): void;
|
|
52
|
+
report(insets: Insets, frame: Frame, from?: object): void;
|
|
53
|
+
/**
|
|
54
|
+
* Called by `<safe-area-provider>` as it goes: forgets its report. When that report was the
|
|
55
|
+
* latest, what a provider still up last reported takes its place, or nothing when none is.
|
|
56
|
+
* True when the values changed.
|
|
57
|
+
*/
|
|
58
|
+
withdraw(from: object): boolean;
|
|
50
59
|
static ɵfac: i0.ɵɵFactoryDeclaration<SafeArea, never>;
|
|
51
60
|
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
52
61
|
}
|
package/dist/safe-area.js
CHANGED
|
@@ -21,6 +21,9 @@ export class SafeArea {
|
|
|
21
21
|
...(ngDevMode ? [{ debugName: "current" }] : /* istanbul ignore next */ []));
|
|
22
22
|
measured = signal(null, /* @ts-ignore */
|
|
23
23
|
...(ngDevMode ? [{ debugName: "measured" }] : /* istanbul ignore next */ []));
|
|
24
|
+
/** What each provider still up last reported, the latest last. */
|
|
25
|
+
reports = new Map();
|
|
26
|
+
reporter = null;
|
|
24
27
|
/** What the system occupies on each edge, in points. */
|
|
25
28
|
insets = this.current.asReadonly();
|
|
26
29
|
/**
|
|
@@ -28,7 +31,7 @@ export class SafeArea {
|
|
|
28
31
|
*
|
|
29
32
|
* On Android 15 that includes the system bars, because the app draws behind them - which is why
|
|
30
33
|
* `Screen.window` reads this rather than `Dimensions`. Null until the provider has laid out,
|
|
31
|
-
* one frame after the app mounts.
|
|
34
|
+
* one frame after the app mounts, and again once every provider that reported is destroyed.
|
|
32
35
|
*/
|
|
33
36
|
frame = this.measured.asReadonly();
|
|
34
37
|
/** Whether anything has reported yet, for a layout that would rather wait than jump. */
|
|
@@ -38,9 +41,29 @@ export class SafeArea {
|
|
|
38
41
|
* Called by `<safe-area-provider>` when native reports. Not for apps: an inset written from
|
|
39
42
|
* anywhere else is a number that stops matching the screen the moment the device rotates.
|
|
40
43
|
*/
|
|
41
|
-
report(insets, frame) {
|
|
44
|
+
report(insets, frame, from) {
|
|
42
45
|
this.current.set(insets);
|
|
43
46
|
this.measured.set(frame);
|
|
47
|
+
this.reporter = from ?? null;
|
|
48
|
+
if (!from)
|
|
49
|
+
return;
|
|
50
|
+
this.reports.delete(from);
|
|
51
|
+
this.reports.set(from, { insets, frame });
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Called by `<safe-area-provider>` as it goes: forgets its report. When that report was the
|
|
55
|
+
* latest, what a provider still up last reported takes its place, or nothing when none is.
|
|
56
|
+
* True when the values changed.
|
|
57
|
+
*/
|
|
58
|
+
withdraw(from) {
|
|
59
|
+
this.reports.delete(from);
|
|
60
|
+
if (this.reporter !== from)
|
|
61
|
+
return false;
|
|
62
|
+
const [previous] = [...this.reports].slice(-1);
|
|
63
|
+
this.reporter = previous?.[0] ?? null;
|
|
64
|
+
this.current.set(previous?.[1].insets ?? NOTHING);
|
|
65
|
+
this.measured.set(previous?.[1].frame ?? null);
|
|
66
|
+
return true;
|
|
44
67
|
}
|
|
45
68
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: SafeArea, deps: [], target: i0.ɵɵFactoryTarget.Service });
|
|
46
69
|
static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.2.0", ngImport: i0, type: SafeArea });
|
package/dist/safe-area.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"safe-area.js","sourceRoot":"","sources":["../src/safe-area.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAe,MAAM,eAAe,CAAC;;AAgBvE,MAAM,OAAO,GAAW,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;AAGjE,MAAM,OAAO,QAAQ;IACF,OAAO,GAAG,MAAM,CAAS,OAAO;gFAAC,CAAC;IAClC,QAAQ,GAAG,MAAM,CAAe,IAAI;iFAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"safe-area.js","sourceRoot":"","sources":["../src/safe-area.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAe,MAAM,eAAe,CAAC;;AAgBvE,MAAM,OAAO,GAAW,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,E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AAC,CAAC;QAC/C,IAAI,CAAC,QAAQ,GAAG,QAAQ,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;QACtC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,OAAO,CAAC,CAAC;QAClD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC;QAC/C,OAAO,IAAI,CAAC;IACd,CAAC;uGAhDU,QAAQ;wGAAR,QAAQ;;2FAAR,QAAQ;kBADpB,OAAO","sourcesContent":["/**\n * How much of the screen belongs to the system: the notch, the status bar, the home indicator,\n * a rounded corner, and on Android the display cutout and the navigation bar.\n *\n * Unlike everything else here, this has no React Native module behind it. Insets are a property\n * of a *view*, not of the device, and the only thing that can report them is a native view inside\n * the window - `<safe-area-provider>` in `@ng-native/components`, which pushes what it\n * measures in here. That is also why the values start at zero: nothing is known until a view has\n * been laid out, which is one frame after the app mounts.\n *\n * Most layouts should not read this at all. A `<safe-area-view>` applies the insets natively,\n * without a round trip through JavaScript, and a screen in a native stack has its header do it.\n * This is for the cases neither covers: a floating button that must clear the home indicator, a\n * scroll view whose content inset is computed, a sheet drawing its own chrome.\n */\nimport { Service, computed, signal, type Signal } from '@angular/core';\n\nexport interface Insets {\n readonly top: number;\n readonly right: number;\n readonly bottom: number;\n readonly left: number;\n}\n\nexport interface Frame {\n readonly x: number;\n readonly y: number;\n readonly width: number;\n readonly height: number;\n}\n\nconst NOTHING: Insets = { top: 0, right: 0, bottom: 0, left: 0 };\n\n@Service()\nexport class SafeArea {\n private readonly current = signal<Insets>(NOTHING);\n private readonly measured = signal<Frame | null>(null);\n /** What each provider still up last reported, the latest last. */\n private readonly reports = new Map<object, { insets: Insets; frame: Frame }>();\n private reporter: object | null = null;\n\n /** What the system occupies on each edge, in points. */\n readonly insets: Signal<Insets> = this.current.asReadonly();\n\n /**\n * The provider's own frame: the area it was handed to lay out in.\n *\n * On Android 15 that includes the system bars, because the app draws behind them - which is why\n * `Screen.window` reads this rather than `Dimensions`. Null until the provider has laid out,\n * one frame after the app mounts, and again once every provider that reported is destroyed.\n */\n readonly frame: Signal<Frame | null> = this.measured.asReadonly();\n\n /** Whether anything has reported yet, for a layout that would rather wait than jump. */\n readonly known = computed(() => this.measured() !== null);\n\n /**\n * Called by `<safe-area-provider>` when native reports. Not for apps: an inset written from\n * anywhere else is a number that stops matching the screen the moment the device rotates.\n */\n report(insets: Insets, frame: Frame, from?: object): void {\n this.current.set(insets);\n this.measured.set(frame);\n this.reporter = from ?? null;\n if (!from) return;\n this.reports.delete(from);\n this.reports.set(from, { insets, frame });\n }\n\n /**\n * Called by `<safe-area-provider>` as it goes: forgets its report. When that report was the\n * latest, what a provider still up last reported takes its place, or nothing when none is.\n * True when the values changed.\n */\n withdraw(from: object): boolean {\n this.reports.delete(from);\n if (this.reporter !== from) return false;\n const [previous] = [...this.reports].slice(-1);\n this.reporter = previous?.[0] ?? null;\n this.current.set(previous?.[1].insets ?? NOTHING);\n this.measured.set(previous?.[1].frame ?? null);\n return true;\n }\n}\n"]}
|