@ng-native/device 0.0.1 → 0.1.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/LICENSE +21 -0
- package/README.md +72 -1
- package/dist/accessibility.d.ts +60 -0
- package/dist/accessibility.js +101 -0
- package/dist/accessibility.js.map +1 -0
- package/dist/android-permissions.d.ts +31 -0
- package/dist/android-permissions.js +51 -0
- package/dist/android-permissions.js.map +1 -0
- package/dist/app-state.d.ts +27 -0
- package/dist/app-state.js +45 -0
- package/dist/app-state.js.map +1 -0
- package/dist/color-scheme.d.ts +33 -0
- package/dist/color-scheme.js +50 -0
- package/dist/color-scheme.js.map +1 -0
- package/dist/conditions.d.ts +48 -0
- package/dist/conditions.js +91 -0
- package/dist/conditions.js.map +1 -0
- package/dist/deep-links.d.ts +35 -0
- package/dist/deep-links.js +119 -0
- package/dist/deep-links.js.map +1 -0
- package/dist/dev-menu.d.ts +48 -0
- package/dist/dev-menu.js +52 -0
- package/dist/dev-menu.js.map +1 -0
- package/dist/dialogs.d.ts +111 -0
- package/dist/dialogs.js +186 -0
- package/dist/dialogs.js.map +1 -0
- package/dist/direction.d.ts +49 -0
- package/dist/direction.js +57 -0
- package/dist/direction.js.map +1 -0
- package/dist/hardware-back.d.ts +27 -0
- package/dist/hardware-back.js +41 -0
- package/dist/hardware-back.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/keyboard.d.ts +67 -0
- package/dist/keyboard.js +103 -0
- package/dist/keyboard.js.map +1 -0
- package/dist/layout-animation.d.ts +54 -0
- package/dist/layout-animation.js +75 -0
- package/dist/layout-animation.js.map +1 -0
- package/dist/react-native.d.ts +176 -0
- package/dist/react-native.js +38 -0
- package/dist/react-native.js.map +1 -0
- package/dist/safe-area.d.ts +52 -0
- package/dist/safe-area.js +51 -0
- package/dist/safe-area.js.map +1 -0
- package/dist/screen-in-front.d.ts +10 -0
- package/dist/screen-in-front.js +14 -0
- package/dist/screen-in-front.js.map +1 -0
- package/dist/screen.d.ts +78 -0
- package/dist/screen.js +90 -0
- package/dist/screen.js.map +1 -0
- package/dist/sharing.d.ts +37 -0
- package/dist/sharing.js +61 -0
- package/dist/sharing.js.map +1 -0
- package/dist/status-bar.d.ts +69 -0
- package/dist/status-bar.js +101 -0
- package/dist/status-bar.js.map +1 -0
- package/dist/vibration.d.ts +38 -0
- package/dist/vibration.js +43 -0
- package/dist/vibration.js.map +1 -0
- package/package.json +59 -3
package/dist/keyboard.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The software keyboard: where it is, and how long it takes to get there.
|
|
3
|
+
*
|
|
4
|
+
* On iOS the metrics change as the keyboard starts to move, with the duration and curve it is
|
|
5
|
+
* moving on, so a layout can move with it; on Android, once it has arrived. See `keyboardSource`.
|
|
6
|
+
*/
|
|
7
|
+
import { DestroyRef, InjectionToken, Service, computed, inject, signal, } from '@angular/core';
|
|
8
|
+
import { reactNative } from "./react-native.js";
|
|
9
|
+
import * as i0 from "@angular/core";
|
|
10
|
+
/** The timing a keyboard event carries, when it carries any. */
|
|
11
|
+
function timingOf(event) {
|
|
12
|
+
if (event.duration === undefined)
|
|
13
|
+
return {};
|
|
14
|
+
return { duration: event.duration, easing: event.easing };
|
|
15
|
+
}
|
|
16
|
+
const metricsOf = (event) => ({
|
|
17
|
+
height: event.endCoordinates.height,
|
|
18
|
+
screenY: event.endCoordinates.screenY,
|
|
19
|
+
...timingOf(event),
|
|
20
|
+
});
|
|
21
|
+
/**
|
|
22
|
+
* The events RN's own KeyboardAvoidingView listens for, which differ by platform.
|
|
23
|
+
*
|
|
24
|
+
* On iOS the Will events: they arrive as the keyboard starts to move, carrying its duration and
|
|
25
|
+
* curve, so a layout configured from them moves with the keyboard. The Did events arrive once it
|
|
26
|
+
* has landed, and a layout that waits for them moves after it. `keyboardWillChangeFrame` covers a
|
|
27
|
+
* keyboard that changes size while it is up - the predictive bar, another language's layout - and
|
|
28
|
+
* is ignored while it is down: UIKit posts one beside every show and hide as well, and the one
|
|
29
|
+
* beside a hide is the frame the keyboard leaves by, off the bottom of the screen.
|
|
30
|
+
*
|
|
31
|
+
* Android sends no Will events at all, so there it is the Did events, which arrive with a
|
|
32
|
+
* duration of zero because the platform animates its own keyboard.
|
|
33
|
+
*/
|
|
34
|
+
export function keyboardSource() {
|
|
35
|
+
const native = reactNative();
|
|
36
|
+
if (!native)
|
|
37
|
+
return { subscribe: () => () => { }, dismiss: () => { } };
|
|
38
|
+
const { Keyboard: keyboard, Platform } = native;
|
|
39
|
+
return {
|
|
40
|
+
subscribe: (listener) => {
|
|
41
|
+
if (Platform?.OS !== 'ios') {
|
|
42
|
+
const subscriptions = [
|
|
43
|
+
keyboard.addListener('keyboardDidShow', (event) => listener(metricsOf(event))),
|
|
44
|
+
keyboard.addListener('keyboardDidHide', () => listener({ height: 0 })),
|
|
45
|
+
];
|
|
46
|
+
return () => subscriptions.forEach((subscription) => subscription.remove());
|
|
47
|
+
}
|
|
48
|
+
let up = false;
|
|
49
|
+
const subscriptions = [
|
|
50
|
+
keyboard.addListener('keyboardWillShow', (event) => {
|
|
51
|
+
up = true;
|
|
52
|
+
listener(metricsOf(event));
|
|
53
|
+
}),
|
|
54
|
+
keyboard.addListener('keyboardWillChangeFrame', (event) => {
|
|
55
|
+
if (up)
|
|
56
|
+
listener(metricsOf(event));
|
|
57
|
+
}),
|
|
58
|
+
keyboard.addListener('keyboardWillHide', (event) => {
|
|
59
|
+
up = false;
|
|
60
|
+
listener({ height: 0, ...timingOf(event) });
|
|
61
|
+
}),
|
|
62
|
+
];
|
|
63
|
+
return () => subscriptions.forEach((subscription) => subscription.remove());
|
|
64
|
+
},
|
|
65
|
+
dismiss: () => keyboard.dismiss(),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Subscribed for the life of the app, which is the life of the service, and removed when the app
|
|
70
|
+
* is destroyed. A component that mounts mid-gesture wants the height that is already true rather
|
|
71
|
+
* than the next change, which is why the subscription is the service's and not the component's.
|
|
72
|
+
*/
|
|
73
|
+
export class Keyboard {
|
|
74
|
+
/**
|
|
75
|
+
* Where the metrics actually come from. Overriding this token is how a test drives the keyboard,
|
|
76
|
+
* and it is finer than replacing the service: the code under test stays the real thing.
|
|
77
|
+
*/
|
|
78
|
+
static SOURCE = new InjectionToken('angular-native.keyboardSource', {
|
|
79
|
+
factory: keyboardSource,
|
|
80
|
+
});
|
|
81
|
+
source = inject(Keyboard.SOURCE);
|
|
82
|
+
current = signal({ height: 0 }, /* @ts-ignore */
|
|
83
|
+
...(ngDevMode ? [{ debugName: "current" }] : /* istanbul ignore next */ []));
|
|
84
|
+
/** Everything the platform said, for a layout that needs the animation duration too. */
|
|
85
|
+
metrics = this.current.asReadonly();
|
|
86
|
+
height = computed(() => this.current().height, /* @ts-ignore */
|
|
87
|
+
...(ngDevMode ? [{ debugName: "height" }] : /* istanbul ignore next */ []));
|
|
88
|
+
visible = computed(() => this.current().height > 0, /* @ts-ignore */
|
|
89
|
+
...(ngDevMode ? [{ debugName: "visible" }] : /* istanbul ignore next */ []));
|
|
90
|
+
constructor() {
|
|
91
|
+
inject(DestroyRef).onDestroy(this.source.subscribe((metrics) => this.current.set(metrics)));
|
|
92
|
+
}
|
|
93
|
+
/** Put the keyboard away, as tapping outside a field would. */
|
|
94
|
+
dismiss() {
|
|
95
|
+
this.source.dismiss();
|
|
96
|
+
}
|
|
97
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: Keyboard, deps: [], target: i0.ɵɵFactoryTarget.Service });
|
|
98
|
+
static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.2.0", ngImport: i0, type: Keyboard });
|
|
99
|
+
}
|
|
100
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: Keyboard, decorators: [{
|
|
101
|
+
type: Service
|
|
102
|
+
}], ctorParameters: () => [] });
|
|
103
|
+
//# sourceMappingURL=keyboard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyboard.js","sourceRoot":"","sources":["../src/keyboard.ts"],"names":[],"mappings":"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","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, once it has arrived. 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. On\n * Android it is always `'keyboard'` paired with a duration of zero: the platform animates its\n * own keyboard, the event arrives once it has, and nothing here should try to animate alongside\n * it.\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 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, which arrive with a\n * duration of zero because the platform animates its own keyboard.\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 * 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\n /** Everything the platform said, for a layout that needs the animation duration too. */\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 constructor() {\n inject(DestroyRef).onDestroy(this.source.subscribe((metrics) => this.current.set(metrics)));\n }\n\n /** Put the keyboard away, as tapping outside a field would. */\n dismiss(): void {\n this.source.dismiss();\n }\n}\n"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Animating a layout *change*, which CSS cannot express.
|
|
3
|
+
*
|
|
4
|
+
* A transition animates a property from one value to another, and the engine already does that. It
|
|
5
|
+
* cannot animate a layout: when a row is removed and the rows below move up, nothing about those
|
|
6
|
+
* rows changed - their `top` was never set, Yoga computed it, and there is no old value to
|
|
7
|
+
* transition from. The web solves this with FLIP, measuring before and after in JavaScript; native
|
|
8
|
+
* solves it in the shadow tree, which is where the two layouts both exist.
|
|
9
|
+
*
|
|
10
|
+
* So this is not a nicer `LayoutAnimation` - it is the only way to say the thing at all. What it
|
|
11
|
+
* adds is the promise, and the scope: `configureNext` applies to the next commit *whenever that
|
|
12
|
+
* happens*, so a call that is not immediately followed by a change animates whatever change comes
|
|
13
|
+
* next, which may be an unrelated screen appearing.
|
|
14
|
+
*/
|
|
15
|
+
import { InjectionToken } from '@angular/core';
|
|
16
|
+
import * as i0 from "@angular/core";
|
|
17
|
+
/**
|
|
18
|
+
* How a change is eased. `spring` is the platform's own, and is what a native list uses.
|
|
19
|
+
* `keyboard` is the curve iOS moves its keyboard on, which a keyboard event reports by that name.
|
|
20
|
+
*/
|
|
21
|
+
export type LayoutEasing = 'spring' | 'linear' | 'easeInEaseOut' | 'easeIn' | 'easeOut' | 'keyboard';
|
|
22
|
+
export interface LayoutChange {
|
|
23
|
+
readonly duration?: number;
|
|
24
|
+
readonly easing?: LayoutEasing;
|
|
25
|
+
/** What a view appearing does. `opacity` fades it in; the default is to scale it up. */
|
|
26
|
+
readonly appear?: 'opacity' | 'scaleXY' | 'none';
|
|
27
|
+
/** What a view leaving does. */
|
|
28
|
+
readonly leave?: 'opacity' | 'scaleXY' | 'none';
|
|
29
|
+
}
|
|
30
|
+
export interface NativeLayoutAnimation {
|
|
31
|
+
configureNext(config: object, onDone?: () => void): void;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* `inject(LayoutAnimation).animate(() => this.rows.update(...))`.
|
|
35
|
+
*
|
|
36
|
+
* The only way to say "animate the layout this change produces": a transition needs a value to
|
|
37
|
+
* animate from, and a row that moves up because the one above it left never had one.
|
|
38
|
+
*/
|
|
39
|
+
export declare class LayoutAnimation {
|
|
40
|
+
/** Overridden in a test to watch a configuration without one being applied. */
|
|
41
|
+
static readonly SOURCE: InjectionToken<NativeLayoutAnimation | null>;
|
|
42
|
+
private readonly native;
|
|
43
|
+
/**
|
|
44
|
+
* Animate the layout the next commit produces, and run `change` to cause it.
|
|
45
|
+
*
|
|
46
|
+
* The change is taken rather than left to the caller because the two have to be adjacent: a
|
|
47
|
+
* `configureNext` with nothing after it animates whatever commit happens next, which may be a
|
|
48
|
+
* different screen entirely. Resolves when the animation ends, or immediately where the platform
|
|
49
|
+
* does not report that.
|
|
50
|
+
*/
|
|
51
|
+
animate(change: () => void, options?: LayoutChange): Promise<void>;
|
|
52
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<LayoutAnimation, never>;
|
|
53
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
54
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Animating a layout *change*, which CSS cannot express.
|
|
3
|
+
*
|
|
4
|
+
* A transition animates a property from one value to another, and the engine already does that. It
|
|
5
|
+
* cannot animate a layout: when a row is removed and the rows below move up, nothing about those
|
|
6
|
+
* rows changed - their `top` was never set, Yoga computed it, and there is no old value to
|
|
7
|
+
* transition from. The web solves this with FLIP, measuring before and after in JavaScript; native
|
|
8
|
+
* solves it in the shadow tree, which is where the two layouts both exist.
|
|
9
|
+
*
|
|
10
|
+
* So this is not a nicer `LayoutAnimation` - it is the only way to say the thing at all. What it
|
|
11
|
+
* adds is the promise, and the scope: `configureNext` applies to the next commit *whenever that
|
|
12
|
+
* happens*, so a call that is not immediately followed by a change animates whatever change comes
|
|
13
|
+
* next, which may be an unrelated screen appearing.
|
|
14
|
+
*/
|
|
15
|
+
import { InjectionToken, Service, inject } from '@angular/core';
|
|
16
|
+
import { reactNative } from "./react-native.js";
|
|
17
|
+
import * as i0 from "@angular/core";
|
|
18
|
+
const DEFAULTS = { duration: 300, easing: 'easeInEaseOut' };
|
|
19
|
+
/**
|
|
20
|
+
* `inject(LayoutAnimation).animate(() => this.rows.update(...))`.
|
|
21
|
+
*
|
|
22
|
+
* The only way to say "animate the layout this change produces": a transition needs a value to
|
|
23
|
+
* animate from, and a row that moves up because the one above it left never had one.
|
|
24
|
+
*/
|
|
25
|
+
export class LayoutAnimation {
|
|
26
|
+
/** Overridden in a test to watch a configuration without one being applied. */
|
|
27
|
+
static SOURCE = new InjectionToken('angular-native.layoutAnimationSource', { factory: () => reactNative()?.LayoutAnimation ?? null });
|
|
28
|
+
native = inject(LayoutAnimation.SOURCE);
|
|
29
|
+
/**
|
|
30
|
+
* Animate the layout the next commit produces, and run `change` to cause it.
|
|
31
|
+
*
|
|
32
|
+
* The change is taken rather than left to the caller because the two have to be adjacent: a
|
|
33
|
+
* `configureNext` with nothing after it animates whatever commit happens next, which may be a
|
|
34
|
+
* different screen entirely. Resolves when the animation ends, or immediately where the platform
|
|
35
|
+
* does not report that.
|
|
36
|
+
*/
|
|
37
|
+
async animate(change, options = {}) {
|
|
38
|
+
if (!this.native) {
|
|
39
|
+
change();
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const done = new Promise((resolve) => {
|
|
43
|
+
this.native.configureNext(config(options), resolve);
|
|
44
|
+
// Android does not call the completion, so nothing should wait on it forever.
|
|
45
|
+
setTimeout(resolve, (options.duration ?? DEFAULTS.duration) + 50);
|
|
46
|
+
});
|
|
47
|
+
change();
|
|
48
|
+
await done;
|
|
49
|
+
}
|
|
50
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: LayoutAnimation, deps: [], target: i0.ɵɵFactoryTarget.Service });
|
|
51
|
+
static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.2.0", ngImport: i0, type: LayoutAnimation });
|
|
52
|
+
}
|
|
53
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: LayoutAnimation, decorators: [{
|
|
54
|
+
type: Service
|
|
55
|
+
}] });
|
|
56
|
+
/**
|
|
57
|
+
* The config React Native takes, from the three things worth naming.
|
|
58
|
+
*
|
|
59
|
+
* `create` and `delete` need a `property` as well as a type, because a view appearing has no
|
|
60
|
+
* previous size to animate from - it has to be told what to animate *of*. Leaving that out is the
|
|
61
|
+
* most common way one of these does nothing.
|
|
62
|
+
*/
|
|
63
|
+
function config(options) {
|
|
64
|
+
const duration = options.duration ?? DEFAULTS.duration;
|
|
65
|
+
const easing = options.easing ?? DEFAULTS.easing;
|
|
66
|
+
const appear = options.appear ?? 'opacity';
|
|
67
|
+
const leave = options.leave ?? 'opacity';
|
|
68
|
+
return {
|
|
69
|
+
duration,
|
|
70
|
+
update: { type: easing, ...(easing === 'spring' ? { springDamping: 0.7 } : {}) },
|
|
71
|
+
...(appear === 'none' ? {} : { create: { type: easing, property: appear } }),
|
|
72
|
+
...(leave === 'none' ? {} : { delete: { type: easing, property: leave } }),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=layout-animation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layout-animation.js","sourceRoot":"","sources":["../src/layout-animation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;;AAsBhD,MAAM,QAAQ,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,eAA+B,EAAE,CAAC;AAE5E;;;;;GAKG;AAEH,MAAM,OAAO,eAAe;IAC1B,+EAA+E;IAC/E,MAAM,CAAU,MAAM,GAAG,IAAI,cAAc,CACzC,sCAAsC,EACtC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,WAAW,EAAE,EAAE,eAAe,IAAI,IAAI,EAAE,CAC1D,CAAC;IAEe,MAAM,GAAG,MAAM,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;IAEzD;;;;;;;OAOG;IACH,KAAK,CAAC,OAAO,CAAC,MAAkB,EAAE,UAAwB,EAAE;QAC1D,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,MAAM,EAAE,CAAC;YACT,OAAO;QACT,CAAC;QAED,MAAM,IAAI,GAAG,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;YACzC,IAAI,CAAC,MAAO,CAAC,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC;YACrD,8EAA8E;YAC9E,UAAU,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,QAAQ,IAAI,QAAQ,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC;QACpE,CAAC,CAAC,CAAC;QAEH,MAAM,EAAE,CAAC;QACT,MAAM,IAAI,CAAC;IACb,CAAC;uGA/BU,eAAe;wGAAf,eAAe;;2FAAf,eAAe;kBAD3B,OAAO;;AAmCR;;;;;;GAMG;AACH,SAAS,MAAM,CAAC,OAAqB;IACnC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,QAAQ,CAAC,QAAQ,CAAC;IACvD,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,QAAQ,CAAC,MAAM,CAAC;IACjD,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,SAAS,CAAC;IAC3C,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,SAAS,CAAC;IAEzC,OAAO;QACL,QAAQ;QACR,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE;QAChF,GAAG,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,CAAC;QAC5E,GAAG,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,CAAC;KAC3E,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Animating a layout *change*, which CSS cannot express.\n *\n * A transition animates a property from one value to another, and the engine already does that. It\n * cannot animate a layout: when a row is removed and the rows below move up, nothing about those\n * rows changed - their `top` was never set, Yoga computed it, and there is no old value to\n * transition from. The web solves this with FLIP, measuring before and after in JavaScript; native\n * solves it in the shadow tree, which is where the two layouts both exist.\n *\n * So this is not a nicer `LayoutAnimation` - it is the only way to say the thing at all. What it\n * adds is the promise, and the scope: `configureNext` applies to the next commit *whenever that\n * happens*, so a call that is not immediately followed by a change animates whatever change comes\n * next, which may be an unrelated screen appearing.\n */\n\nimport { InjectionToken, Service, inject } from '@angular/core';\nimport { reactNative } from './react-native.ts';\n\n/**\n * How a change is eased. `spring` is the platform's own, and is what a native list uses.\n * `keyboard` is the curve iOS moves its keyboard on, which a keyboard event reports by that name.\n */\nexport type LayoutEasing =\n 'spring' | 'linear' | 'easeInEaseOut' | 'easeIn' | 'easeOut' | 'keyboard';\n\nexport interface LayoutChange {\n readonly duration?: number;\n readonly easing?: LayoutEasing;\n /** What a view appearing does. `opacity` fades it in; the default is to scale it up. */\n readonly appear?: 'opacity' | 'scaleXY' | 'none';\n /** What a view leaving does. */\n readonly leave?: 'opacity' | 'scaleXY' | 'none';\n}\n\nexport interface NativeLayoutAnimation {\n configureNext(config: object, onDone?: () => void): void;\n}\n\nconst DEFAULTS = { duration: 300, easing: 'easeInEaseOut' as LayoutEasing };\n\n/**\n * `inject(LayoutAnimation).animate(() => this.rows.update(...))`.\n *\n * The only way to say \"animate the layout this change produces\": a transition needs a value to\n * animate from, and a row that moves up because the one above it left never had one.\n */\n@Service()\nexport class LayoutAnimation {\n /** Overridden in a test to watch a configuration without one being applied. */\n static readonly SOURCE = new InjectionToken<NativeLayoutAnimation | null>(\n 'angular-native.layoutAnimationSource',\n { factory: () => reactNative()?.LayoutAnimation ?? null },\n );\n\n private readonly native = inject(LayoutAnimation.SOURCE);\n\n /**\n * Animate the layout the next commit produces, and run `change` to cause it.\n *\n * The change is taken rather than left to the caller because the two have to be adjacent: a\n * `configureNext` with nothing after it animates whatever commit happens next, which may be a\n * different screen entirely. Resolves when the animation ends, or immediately where the platform\n * does not report that.\n */\n async animate(change: () => void, options: LayoutChange = {}): Promise<void> {\n if (!this.native) {\n change();\n return;\n }\n\n const done = new Promise<void>((resolve) => {\n this.native!.configureNext(config(options), resolve);\n // Android does not call the completion, so nothing should wait on it forever.\n setTimeout(resolve, (options.duration ?? DEFAULTS.duration) + 50);\n });\n\n change();\n await done;\n }\n}\n\n/**\n * The config React Native takes, from the three things worth naming.\n *\n * `create` and `delete` need a `property` as well as a type, because a view appearing has no\n * previous size to animate from - it has to be told what to animate *of*. Leaving that out is the\n * most common way one of these does nothing.\n */\nfunction config(options: LayoutChange): object {\n const duration = options.duration ?? DEFAULTS.duration;\n const easing = options.easing ?? DEFAULTS.easing;\n const appear = options.appear ?? 'opacity';\n const leave = options.leave ?? 'opacity';\n\n return {\n duration,\n update: { type: easing, ...(easing === 'spring' ? { springDamping: 0.7 } : {}) },\n ...(appear === 'none' ? {} : { create: { type: easing, property: appear } }),\n ...(leave === 'none' ? {} : { delete: { type: easing, property: leave } }),\n };\n}\n"]}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Native's own modules, fetched when a service is first constructed rather than when this
|
|
3
|
+
* file is loaded.
|
|
4
|
+
*
|
|
5
|
+
* The distinction matters more than it looks. React Native ships its JavaScript as Flow, which
|
|
6
|
+
* Node cannot parse, so a static `import ... from 'react-native'` anywhere in this package would
|
|
7
|
+
* make the package unimportable by the test suite - and by `@ng-native/components`, which
|
|
8
|
+
* the suite imports constantly. A call inside a factory is only ever executed on a device, where
|
|
9
|
+
* `react-native` is the most ordinary import there is.
|
|
10
|
+
*
|
|
11
|
+
* ponytail: a `require` in a codebase that otherwise has none. The alternative is the shape
|
|
12
|
+
* `@ng-native/expo` uses - a file per service outside `src`, importing the module and
|
|
13
|
+
* declaring the service - which is right there because Expo's packages are optional peer
|
|
14
|
+
* dependencies an app may not have installed. React Native is not optional, so the seam buys
|
|
15
|
+
* nothing but files.
|
|
16
|
+
*/
|
|
17
|
+
/** The subset of React Native this package reaches for, described so `require` has a type. */
|
|
18
|
+
export interface ReactNative {
|
|
19
|
+
AccessibilityInfo: {
|
|
20
|
+
isScreenReaderEnabled(): Promise<boolean>;
|
|
21
|
+
isReduceMotionEnabled(): Promise<boolean>;
|
|
22
|
+
isBoldTextEnabled(): Promise<boolean>;
|
|
23
|
+
announceForAccessibility(announcement: string): void;
|
|
24
|
+
addEventListener(event: 'screenReaderChanged' | 'reduceMotionChanged' | 'boldTextChanged', handler: (value: boolean) => void): {
|
|
25
|
+
remove(): void;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
AppState: {
|
|
29
|
+
currentState: string | null;
|
|
30
|
+
addEventListener(event: 'change', handler: (state: string) => void): {
|
|
31
|
+
remove(): void;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
Appearance: {
|
|
35
|
+
getColorScheme(): 'light' | 'dark' | null | undefined;
|
|
36
|
+
addChangeListener(handler: (preferences: {
|
|
37
|
+
colorScheme?: string | null;
|
|
38
|
+
}) => void): {
|
|
39
|
+
remove(): void;
|
|
40
|
+
};
|
|
41
|
+
setColorScheme?(scheme: 'light' | 'dark' | 'unspecified'): void;
|
|
42
|
+
};
|
|
43
|
+
BackHandler: {
|
|
44
|
+
addEventListener(event: 'hardwareBackPress', handler: () => boolean): {
|
|
45
|
+
remove(): void;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
Dimensions: {
|
|
49
|
+
get(dimension: 'window' | 'screen'): {
|
|
50
|
+
width: number;
|
|
51
|
+
height: number;
|
|
52
|
+
};
|
|
53
|
+
addEventListener(event: 'change', handler: (sizes: {
|
|
54
|
+
window: {
|
|
55
|
+
width: number;
|
|
56
|
+
height: number;
|
|
57
|
+
};
|
|
58
|
+
screen: {
|
|
59
|
+
width: number;
|
|
60
|
+
height: number;
|
|
61
|
+
};
|
|
62
|
+
}) => void): {
|
|
63
|
+
remove(): void;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
I18nManager: {
|
|
67
|
+
/** Whether the app is laid out right to left. Fixed for the lifetime of the process. */
|
|
68
|
+
isRTL: boolean;
|
|
69
|
+
};
|
|
70
|
+
Keyboard: {
|
|
71
|
+
dismiss(): void;
|
|
72
|
+
addListener(event: 'keyboardDidShow' | 'keyboardDidHide' | 'keyboardWillShow' | 'keyboardWillHide' | 'keyboardWillChangeFrame', handler: (event: NativeKeyboardEvent) => void): {
|
|
73
|
+
remove(): void;
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
StyleSheet: {
|
|
77
|
+
/** The thinnest line the screen can draw, in points. `1 / PixelRatio.get()`, near enough. */
|
|
78
|
+
hairlineWidth: number;
|
|
79
|
+
};
|
|
80
|
+
ActionSheetIOS?: {
|
|
81
|
+
showActionSheetWithOptions(options: {
|
|
82
|
+
title?: string;
|
|
83
|
+
options: string[];
|
|
84
|
+
cancelButtonIndex: number;
|
|
85
|
+
destructiveButtonIndex?: number;
|
|
86
|
+
}, callback: (index: number) => void): void;
|
|
87
|
+
};
|
|
88
|
+
Alert: {
|
|
89
|
+
alert(title: string, message?: string, buttons?: {
|
|
90
|
+
text?: string;
|
|
91
|
+
style?: string;
|
|
92
|
+
onPress?: () => void;
|
|
93
|
+
}[], options?: object): void;
|
|
94
|
+
/** iOS only. Absent on Android, where there is no such dialog. */
|
|
95
|
+
prompt?(title: string, message?: string, callbackOrButtons?: ((value: string) => void) | {
|
|
96
|
+
text?: string;
|
|
97
|
+
style?: string;
|
|
98
|
+
onPress?: (value?: string) => void;
|
|
99
|
+
}[], type?: string, defaultValue?: string): void;
|
|
100
|
+
};
|
|
101
|
+
PixelRatio: {
|
|
102
|
+
get(): number;
|
|
103
|
+
/** The user's text size setting, as a multiplier. One is the default. */
|
|
104
|
+
getFontScale(): number;
|
|
105
|
+
};
|
|
106
|
+
Platform: {
|
|
107
|
+
OS: string;
|
|
108
|
+
};
|
|
109
|
+
Share: {
|
|
110
|
+
share(content: {
|
|
111
|
+
message?: string;
|
|
112
|
+
url?: string;
|
|
113
|
+
title?: string;
|
|
114
|
+
}, options?: object): Promise<{
|
|
115
|
+
action: string;
|
|
116
|
+
activityType?: string | null;
|
|
117
|
+
}>;
|
|
118
|
+
};
|
|
119
|
+
ToastAndroid?: {
|
|
120
|
+
show(message: string, duration: number): void;
|
|
121
|
+
SHORT: number;
|
|
122
|
+
LONG: number;
|
|
123
|
+
};
|
|
124
|
+
Vibration: {
|
|
125
|
+
vibrate(pattern?: number | number[], repeat?: boolean): void;
|
|
126
|
+
cancel(): void;
|
|
127
|
+
};
|
|
128
|
+
DevSettings?: {
|
|
129
|
+
addMenuItem(title: string, handler: () => unknown): void;
|
|
130
|
+
reload(reason?: string): void;
|
|
131
|
+
};
|
|
132
|
+
LayoutAnimation: {
|
|
133
|
+
configureNext(config: object, onDone?: () => void, onFail?: () => void): void;
|
|
134
|
+
};
|
|
135
|
+
PermissionsAndroid?: {
|
|
136
|
+
check(permission: string): Promise<boolean>;
|
|
137
|
+
request(permission: string, rationale?: object): Promise<string>;
|
|
138
|
+
};
|
|
139
|
+
StatusBar: {
|
|
140
|
+
/** Android reports the bar's height in dp; iOS leaves it undefined. */
|
|
141
|
+
currentHeight?: number;
|
|
142
|
+
setBarStyle(style: string, animated?: boolean): void;
|
|
143
|
+
setHidden(hidden: boolean, animation?: string): void;
|
|
144
|
+
setBackgroundColor(color: string, animated?: boolean): void;
|
|
145
|
+
setTranslucent(translucent: boolean): void;
|
|
146
|
+
};
|
|
147
|
+
Linking: {
|
|
148
|
+
getInitialURL(): Promise<string | null>;
|
|
149
|
+
openURL(url: string): Promise<unknown>;
|
|
150
|
+
addEventListener(event: 'url', handler: (event: {
|
|
151
|
+
url: string;
|
|
152
|
+
}) => void): {
|
|
153
|
+
remove(): void;
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/** What RN hands a keyboard listener. */
|
|
158
|
+
export interface NativeKeyboardEvent {
|
|
159
|
+
readonly endCoordinates: {
|
|
160
|
+
readonly height: number;
|
|
161
|
+
readonly screenY: number;
|
|
162
|
+
};
|
|
163
|
+
readonly duration?: number;
|
|
164
|
+
/** One of `LayoutEasing`'s names; usually `'keyboard'` on iOS, and always on Android, with a zero duration. */
|
|
165
|
+
readonly easing?: string;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* `null` off a device, where each capability falls back to doing nothing - the same as an
|
|
169
|
+
* optional injection token nobody provided.
|
|
170
|
+
*
|
|
171
|
+
* The engine's presence is what tells the two apart. In Node there is no `nativeFabricUIManager`
|
|
172
|
+
* and no React Native either, which is the ordinary case for the test suite; on a device there is
|
|
173
|
+
* one, and a missing `require` would mean the bundler stopped emitting CommonJS under us. That is
|
|
174
|
+
* worth saying out loud rather than quietly rendering an app whose keyboard never moves.
|
|
175
|
+
*/
|
|
176
|
+
export declare function reactNative(): ReactNative | null;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Native's own modules, fetched when a service is first constructed rather than when this
|
|
3
|
+
* file is loaded.
|
|
4
|
+
*
|
|
5
|
+
* The distinction matters more than it looks. React Native ships its JavaScript as Flow, which
|
|
6
|
+
* Node cannot parse, so a static `import ... from 'react-native'` anywhere in this package would
|
|
7
|
+
* make the package unimportable by the test suite - and by `@ng-native/components`, which
|
|
8
|
+
* the suite imports constantly. A call inside a factory is only ever executed on a device, where
|
|
9
|
+
* `react-native` is the most ordinary import there is.
|
|
10
|
+
*
|
|
11
|
+
* ponytail: a `require` in a codebase that otherwise has none. The alternative is the shape
|
|
12
|
+
* `@ng-native/expo` uses - a file per service outside `src`, importing the module and
|
|
13
|
+
* declaring the service - which is right there because Expo's packages are optional peer
|
|
14
|
+
* dependencies an app may not have installed. React Native is not optional, so the seam buys
|
|
15
|
+
* nothing but files.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* `null` off a device, where each capability falls back to doing nothing - the same as an
|
|
19
|
+
* optional injection token nobody provided.
|
|
20
|
+
*
|
|
21
|
+
* The engine's presence is what tells the two apart. In Node there is no `nativeFabricUIManager`
|
|
22
|
+
* and no React Native either, which is the ordinary case for the test suite; on a device there is
|
|
23
|
+
* one, and a missing `require` would mean the bundler stopped emitting CommonJS under us. That is
|
|
24
|
+
* worth saying out loud rather than quietly rendering an app whose keyboard never moves.
|
|
25
|
+
*/
|
|
26
|
+
export function reactNative() {
|
|
27
|
+
// `require` has a type only where the app's tsconfig loads Node's or React Native's types, and
|
|
28
|
+
// a browser app's loads neither. `@ts-expect-error` would fail where it does.
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
if (typeof require === 'function')
|
|
31
|
+
return require('react-native');
|
|
32
|
+
if (globalThis.nativeFabricUIManager !== undefined) {
|
|
33
|
+
console.error('[angular-native] react-native could not be required, so every platform capability is ' +
|
|
34
|
+
'inert. The bundle is not CommonJS; check the Metro transform.');
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=react-native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-native.js","sourceRoot":"","sources":["../src/react-native.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AA8IH;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW;IACzB,+FAA+F;IAC/F,8EAA8E;IAC9E,aAAa;IACb,IAAI,OAAO,OAAO,KAAK,UAAU;QAAE,OAAO,OAAO,CAAC,cAAc,CAAgB,CAAC;IACjF,IAAK,UAAkD,CAAC,qBAAqB,KAAK,SAAS,EAAE,CAAC;QAC5F,OAAO,CAAC,KAAK,CACX,uFAAuF;YACrF,+DAA+D,CAClE,CAAC;IACJ,CAAC;IACD,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 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 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 Platform: { OS: string };\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 setBackgroundColor(color: string, animated?: boolean): void;\n setTranslucent(translucent: boolean): void;\n };\n Linking: {\n getInitialURL(): Promise<string | null>;\n openURL(url: string): Promise<unknown>;\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 * `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 there is no `nativeFabricUIManager`\n * and no React Native either, which is the ordinary case for the test suite; on a device there is\n * one, and a missing `require` would mean the bundler stopped emitting CommonJS under us. That is\n * worth saying out loud rather than quietly rendering an app whose keyboard never moves.\n */\nexport function reactNative(): ReactNative | null {\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 if ((globalThis as { nativeFabricUIManager?: unknown }).nativeFabricUIManager !== undefined) {\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 }\n return null;\n}\n"]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How much of the screen belongs to the system: the notch, the status bar, the home indicator,
|
|
3
|
+
* a rounded corner, and on Android the display cutout and the navigation bar.
|
|
4
|
+
*
|
|
5
|
+
* Unlike everything else here, this has no React Native module behind it. Insets are a property
|
|
6
|
+
* of a *view*, not of the device, and the only thing that can report them is a native view inside
|
|
7
|
+
* the window - `<safe-area-provider>` in `@ng-native/components`, which pushes what it
|
|
8
|
+
* measures in here. That is also why the values start at zero: nothing is known until a view has
|
|
9
|
+
* been laid out, which is one frame after the app mounts.
|
|
10
|
+
*
|
|
11
|
+
* Most layouts should not read this at all. A `<safe-area-view>` applies the insets natively,
|
|
12
|
+
* without a round trip through JavaScript, and a screen in a native stack has its header do it.
|
|
13
|
+
* This is for the cases neither covers: a floating button that must clear the home indicator, a
|
|
14
|
+
* scroll view whose content inset is computed, a sheet drawing its own chrome.
|
|
15
|
+
*/
|
|
16
|
+
import { type Signal } from '@angular/core';
|
|
17
|
+
import * as i0 from "@angular/core";
|
|
18
|
+
export interface Insets {
|
|
19
|
+
readonly top: number;
|
|
20
|
+
readonly right: number;
|
|
21
|
+
readonly bottom: number;
|
|
22
|
+
readonly left: number;
|
|
23
|
+
}
|
|
24
|
+
export interface Frame {
|
|
25
|
+
readonly x: number;
|
|
26
|
+
readonly y: number;
|
|
27
|
+
readonly width: number;
|
|
28
|
+
readonly height: number;
|
|
29
|
+
}
|
|
30
|
+
export declare class SafeArea {
|
|
31
|
+
private readonly current;
|
|
32
|
+
private readonly measured;
|
|
33
|
+
/** What the system occupies on each edge, in points. */
|
|
34
|
+
readonly insets: Signal<Insets>;
|
|
35
|
+
/**
|
|
36
|
+
* The provider's own frame: the area it was handed to lay out in.
|
|
37
|
+
*
|
|
38
|
+
* On Android 15 that includes the system bars, because the app draws behind them - which is why
|
|
39
|
+
* `Screen.window` reads this rather than `Dimensions`. Null until the provider has laid out,
|
|
40
|
+
* one frame after the app mounts.
|
|
41
|
+
*/
|
|
42
|
+
readonly frame: Signal<Frame | null>;
|
|
43
|
+
/** Whether anything has reported yet, for a layout that would rather wait than jump. */
|
|
44
|
+
readonly known: Signal<boolean>;
|
|
45
|
+
/**
|
|
46
|
+
* Called by `<safe-area-provider>` when native reports. Not for apps: an inset written from
|
|
47
|
+
* anywhere else is a number that stops matching the screen the moment the device rotates.
|
|
48
|
+
*/
|
|
49
|
+
report(insets: Insets, frame: Frame): void;
|
|
50
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<SafeArea, never>;
|
|
51
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
52
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How much of the screen belongs to the system: the notch, the status bar, the home indicator,
|
|
3
|
+
* a rounded corner, and on Android the display cutout and the navigation bar.
|
|
4
|
+
*
|
|
5
|
+
* Unlike everything else here, this has no React Native module behind it. Insets are a property
|
|
6
|
+
* of a *view*, not of the device, and the only thing that can report them is a native view inside
|
|
7
|
+
* the window - `<safe-area-provider>` in `@ng-native/components`, which pushes what it
|
|
8
|
+
* measures in here. That is also why the values start at zero: nothing is known until a view has
|
|
9
|
+
* been laid out, which is one frame after the app mounts.
|
|
10
|
+
*
|
|
11
|
+
* Most layouts should not read this at all. A `<safe-area-view>` applies the insets natively,
|
|
12
|
+
* without a round trip through JavaScript, and a screen in a native stack has its header do it.
|
|
13
|
+
* This is for the cases neither covers: a floating button that must clear the home indicator, a
|
|
14
|
+
* scroll view whose content inset is computed, a sheet drawing its own chrome.
|
|
15
|
+
*/
|
|
16
|
+
import { Service, computed, signal } from '@angular/core';
|
|
17
|
+
import * as i0 from "@angular/core";
|
|
18
|
+
const NOTHING = { top: 0, right: 0, bottom: 0, left: 0 };
|
|
19
|
+
export class SafeArea {
|
|
20
|
+
current = signal(NOTHING, /* @ts-ignore */
|
|
21
|
+
...(ngDevMode ? [{ debugName: "current" }] : /* istanbul ignore next */ []));
|
|
22
|
+
measured = signal(null, /* @ts-ignore */
|
|
23
|
+
...(ngDevMode ? [{ debugName: "measured" }] : /* istanbul ignore next */ []));
|
|
24
|
+
/** What the system occupies on each edge, in points. */
|
|
25
|
+
insets = this.current.asReadonly();
|
|
26
|
+
/**
|
|
27
|
+
* The provider's own frame: the area it was handed to lay out in.
|
|
28
|
+
*
|
|
29
|
+
* On Android 15 that includes the system bars, because the app draws behind them - which is why
|
|
30
|
+
* `Screen.window` reads this rather than `Dimensions`. Null until the provider has laid out,
|
|
31
|
+
* one frame after the app mounts.
|
|
32
|
+
*/
|
|
33
|
+
frame = this.measured.asReadonly();
|
|
34
|
+
/** Whether anything has reported yet, for a layout that would rather wait than jump. */
|
|
35
|
+
known = computed(() => this.measured() !== null, /* @ts-ignore */
|
|
36
|
+
...(ngDevMode ? [{ debugName: "known" }] : /* istanbul ignore next */ []));
|
|
37
|
+
/**
|
|
38
|
+
* Called by `<safe-area-provider>` when native reports. Not for apps: an inset written from
|
|
39
|
+
* anywhere else is a number that stops matching the screen the moment the device rotates.
|
|
40
|
+
*/
|
|
41
|
+
report(insets, frame) {
|
|
42
|
+
this.current.set(insets);
|
|
43
|
+
this.measured.set(frame);
|
|
44
|
+
}
|
|
45
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: SafeArea, deps: [], target: i0.ɵɵFactoryTarget.Service });
|
|
46
|
+
static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.2.0", ngImport: i0, type: SafeArea });
|
|
47
|
+
}
|
|
48
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: SafeArea, decorators: [{
|
|
49
|
+
type: Service
|
|
50
|
+
}] });
|
|
51
|
+
//# sourceMappingURL=safe-area.js.map
|
|
@@ -0,0 +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;IAEvD,wDAAwD;IAC/C,MAAM,GAAmB,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;IAE5D;;;;;;OAMG;IACM,KAAK,GAAyB,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;IAElE,wFAAwF;IAC/E,KAAK,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,IAAI;8EAAC,CAAC;IAE1D;;;OAGG;IACH,MAAM,CAAC,MAAc,EAAE,KAAY;QACjC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACzB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC3B,CAAC;uGA1BU,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\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.\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): void {\n this.current.set(insets);\n this.measured.set(frame);\n }\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { InjectionToken, type Signal } from '@angular/core';
|
|
2
|
+
/**
|
|
3
|
+
* Whether the screen something is on is the one in front: false while another screen is pushed
|
|
4
|
+
* over it or presented from it, or while its tab is not the selected one. A navigation outlet
|
|
5
|
+
* provides it for each screen it shows; outside one it is always true.
|
|
6
|
+
*
|
|
7
|
+
* For what native keeps showing whatever covers a screen: a bar docked on the keyboard belongs to
|
|
8
|
+
* the keyboard's window, above every screen the app has, and has to step down itself.
|
|
9
|
+
*/
|
|
10
|
+
export declare const SCREEN_IN_FRONT: InjectionToken<Signal<boolean>>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { InjectionToken, signal } from '@angular/core';
|
|
2
|
+
const ALWAYS = signal(true).asReadonly();
|
|
3
|
+
/**
|
|
4
|
+
* Whether the screen something is on is the one in front: false while another screen is pushed
|
|
5
|
+
* over it or presented from it, or while its tab is not the selected one. A navigation outlet
|
|
6
|
+
* provides it for each screen it shows; outside one it is always true.
|
|
7
|
+
*
|
|
8
|
+
* For what native keeps showing whatever covers a screen: a bar docked on the keyboard belongs to
|
|
9
|
+
* the keyboard's window, above every screen the app has, and has to step down itself.
|
|
10
|
+
*/
|
|
11
|
+
export const SCREEN_IN_FRONT = new InjectionToken('angular-native.screenInFront', {
|
|
12
|
+
factory: () => ALWAYS,
|
|
13
|
+
});
|
|
14
|
+
//# sourceMappingURL=screen-in-front.js.map
|