@ng-native/device 0.17.0 → 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 +16 -3
- 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 +10 -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/accessibility.js
CHANGED
|
@@ -27,13 +27,24 @@ export function accessibilitySource() {
|
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
29
|
const info = native.AccessibilityInfo;
|
|
30
|
+
// A read that fails is the neutral setting, so the other three still arrive.
|
|
31
|
+
const read = async (ask) => {
|
|
32
|
+
try {
|
|
33
|
+
return await ask();
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
30
39
|
return {
|
|
31
|
-
current: async () =>
|
|
32
|
-
screenReader
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
current: async () => {
|
|
41
|
+
const [screenReader, reduceMotion, boldText] = await Promise.all([
|
|
42
|
+
read(() => info.isScreenReaderEnabled()),
|
|
43
|
+
read(() => info.isReduceMotionEnabled()),
|
|
44
|
+
read(() => info.isBoldTextEnabled()),
|
|
45
|
+
]);
|
|
46
|
+
return { screenReader, reduceMotion, boldText, fontScale: native.PixelRatio.getFontScale() };
|
|
47
|
+
},
|
|
37
48
|
subscribe: (listener) => {
|
|
38
49
|
const subscriptions = [
|
|
39
50
|
info.addEventListener('screenReaderChanged', (screenReader) => listener({ screenReader })),
|
|
@@ -81,8 +92,13 @@ export class Accessibility {
|
|
|
81
92
|
fontScale = computed(() => this.settings().fontScale, /* @ts-ignore */
|
|
82
93
|
...(ngDevMode ? [{ debugName: "fontScale" }] : /* istanbul ignore next */ []));
|
|
83
94
|
constructor() {
|
|
84
|
-
|
|
85
|
-
|
|
95
|
+
let heard = {};
|
|
96
|
+
// A read that fails leaves the neutral settings, which the change events still correct.
|
|
97
|
+
this.source.current().then((settings) => this.settings.set({ ...settings, ...heard }), () => { });
|
|
98
|
+
const stop = this.source.subscribe((change) => {
|
|
99
|
+
heard = { ...heard, ...change };
|
|
100
|
+
this.settings.update((current) => ({ ...current, ...change }));
|
|
101
|
+
});
|
|
86
102
|
inject(DestroyRef).onDestroy(stop);
|
|
87
103
|
}
|
|
88
104
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accessibility.js","sourceRoot":"","sources":["../src/accessibility.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EACL,UAAU,EACV,cAAc,EACd,OAAO,EACP,QAAQ,EACR,MAAM,EACN,MAAM,GAEP,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;;AAsBhD,MAAM,UAAU,mBAAmB;IACjC,MAAM,MAAM,GAAG,WAAW,EAAE,CAAC;IAC7B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AC,MAAM,CAAC,OAAO,EAAE,CAAC,IAAI,CACxB,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,GAAG,QAAQ,EAAE,GAAG,KAAK,EAAE,CAAC,EAC1D,GAAG,EAAE,GAAE,CAAC,CACT,CAAC;QACF,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,EAAE;YAC5C,KAAK,GAAG,EAAE,GAAG,KAAK,EAAE,GAAG,MAAM,EAAE,CAAC;YAChC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC,CAAC;QACjE,CAAC,CAAC,CAAC;QACH,MAAM,CAAC,UAAU,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IAED;;;OAGG;IACH,QAAQ,CAAC,OAAe;QACtB,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAChC,CAAC;uGAlDU,aAAa;wGAAb,aAAa;;2FAAb,aAAa;kBADzB,OAAO","sourcesContent":["/**\n * What the user has turned on in the system's accessibility settings.\n *\n * The components apply the defaults React Native's wrappers do - roles, labels, whether a view is\n * an element at all - without anything being injected. This is for the decisions those defaults\n * cannot make: not animating when the user asked for less motion, announcing something that\n * changed off screen, giving a screen reader a different affordance than a finger gets.\n *\n * Every value starts at its neutral setting and is corrected once the platform answers, because\n * React Native reports all three asynchronously. A first paint therefore assumes nothing is on.\n */\nimport {\n DestroyRef,\n InjectionToken,\n Service,\n computed,\n inject,\n signal,\n type Signal,\n} from '@angular/core';\nimport { reactNative } from './react-native.ts';\n\nexport interface AccessibilitySettings {\n readonly screenReader: boolean;\n readonly reduceMotion: boolean;\n readonly boldText: boolean;\n /**\n * The user's text size, as a multiplier of the default.\n *\n * Not an event: it is read at startup and again when the app comes back, because changing it\n * means leaving for Settings. Text scales natively without anything here, so this is for the\n * layouts that have to give way to it - a row height, a line clamp, an icon beside a label.\n */\n readonly fontScale: number;\n}\n\nexport interface AccessibilitySource {\n current(): Promise<AccessibilitySettings>;\n subscribe(listener: (settings: Partial<AccessibilitySettings>) => void): () => void;\n announce(message: string): void;\n}\n\nexport function accessibilitySource(): AccessibilitySource {\n const native = reactNative();\n if (!native) {\n return {\n current: () =>\n Promise.resolve({\n screenReader: false,\n reduceMotion: false,\n boldText: false,\n fontScale: 1,\n }),\n subscribe: () => () => {},\n announce: () => {},\n };\n }\n\n const info = native.AccessibilityInfo;\n // A read that fails is the neutral setting, so the other three still arrive.\n const read = async (ask: () => Promise<boolean>) => {\n try {\n return await ask();\n } catch {\n return false;\n }\n };\n return {\n current: async () => {\n const [screenReader, reduceMotion, boldText] = await Promise.all([\n read(() => info.isScreenReaderEnabled()),\n read(() => info.isReduceMotionEnabled()),\n read(() => info.isBoldTextEnabled()),\n ]);\n return { screenReader, reduceMotion, boldText, fontScale: native.PixelRatio.getFontScale() };\n },\n subscribe: (listener) => {\n const subscriptions = [\n info.addEventListener('screenReaderChanged', (screenReader) => listener({ screenReader })),\n info.addEventListener('reduceMotionChanged', (reduceMotion) => listener({ reduceMotion })),\n info.addEventListener('boldTextChanged', (boldText) => listener({ boldText })),\n // `fontScale` has no change event of its own - changing it means leaving for Settings -\n // so the app coming back to the foreground is what stands in for one.\n native.AppState.addEventListener('change', (state) => {\n if (state === 'active') listener({ fontScale: native.PixelRatio.getFontScale() });\n }),\n ];\n return () => subscriptions.forEach((subscription) => subscription.remove());\n },\n announce: (message) => info.announceForAccessibility(message),\n };\n}\n\n@Service()\nexport class Accessibility {\n /** Overridden in a test to turn a setting on. */\n static readonly SOURCE = new InjectionToken<AccessibilitySource>(\n 'angular-native.accessibilitySource',\n { factory: accessibilitySource },\n );\n\n private readonly source = inject(Accessibility.SOURCE);\n private readonly settings = signal<AccessibilitySettings>({\n screenReader: false,\n reduceMotion: false,\n boldText: false,\n fontScale: 1,\n });\n\n /** VoiceOver or TalkBack is running. */\n readonly screenReader: Signal<boolean> = computed(() => this.settings().screenReader);\n /**\n * The user asked for less animation. `@media (prefers-reduced-motion: reduce)` reads the same\n * setting and is the better answer wherever the motion is styling rather than logic.\n */\n readonly reduceMotion: Signal<boolean> = computed(() => this.settings().reduceMotion);\n /** The system font is heavier, so hand-tuned weights may need to give way. */\n readonly boldText: Signal<boolean> = computed(() => this.settings().boldText);\n /**\n * How much larger the user has asked text to be. One is the default; the largest accessibility\n * sizes are past three, which is where a row built for one line stops working.\n */\n readonly fontScale: Signal<number> = computed(() => this.settings().fontScale);\n\n constructor() {\n let heard: Partial<AccessibilitySettings> = {};\n // A read that fails leaves the neutral settings, which the change events still correct.\n this.source.current().then(\n (settings) => this.settings.set({ ...settings, ...heard }),\n () => {},\n );\n const stop = this.source.subscribe((change) => {\n heard = { ...heard, ...change };\n this.settings.update((current) => ({ ...current, ...change }));\n });\n inject(DestroyRef).onDestroy(stop);\n }\n\n /**\n * Say something to a screen reader that no focus change would have said. A list that reordered,\n * a search that returned nothing: changes a sighted user sees and a screen reader would miss.\n */\n announce(message: string): void {\n this.source.announce(message);\n }\n}\n"]}
|
package/dist/conditions.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { accessibilitySource } from "./accessibility.js";
|
|
2
2
|
import { colorSchemeSource } from "./color-scheme.js";
|
|
3
3
|
import { directionSource } from "./direction.js";
|
|
4
|
+
import { recordKeyboard } from "./keyboard.js";
|
|
4
5
|
import { screenSource } from "./screen.js";
|
|
5
6
|
import { reactNative } from "./react-native.js";
|
|
6
7
|
/** The system text size, as a multiplier. One off a device. */
|
|
@@ -50,6 +51,8 @@ export function deviceTokens() {
|
|
|
50
51
|
* bootstrap will never use it.
|
|
51
52
|
*/
|
|
52
53
|
export function watchConditions(engine, options = {}) {
|
|
54
|
+
// Not a condition, but this is what runs at startup: see `recordKeyboard`.
|
|
55
|
+
recordKeyboard();
|
|
53
56
|
const screen = screenSource();
|
|
54
57
|
const colors = colorSchemeSource();
|
|
55
58
|
const accessibility = accessibilitySource();
|
|
@@ -82,16 +85,20 @@ export function watchConditions(engine, options = {}) {
|
|
|
82
85
|
};
|
|
83
86
|
const sizes = screen.subscribe(({ window }) => resize({ width: window.width, height: window.height, pixelRatio: pixelRatio() }, fontScale()));
|
|
84
87
|
const scheme = colors.subscribe((colorScheme) => push({ colorScheme }));
|
|
88
|
+
let heardReduceMotion = false;
|
|
89
|
+
let stopped = false;
|
|
85
90
|
const settings = accessibility.subscribe((change) => {
|
|
86
91
|
if (change.fontScale !== undefined && change.fontScale !== scale)
|
|
87
92
|
resize({}, change.fontScale);
|
|
88
|
-
if (change.reduceMotion !== undefined)
|
|
93
|
+
if (change.reduceMotion !== undefined) {
|
|
94
|
+
heardReduceMotion = true;
|
|
89
95
|
push({ reducedMotion: change.reduceMotion });
|
|
96
|
+
}
|
|
90
97
|
});
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
.then(({ reduceMotion }) => reduceMotion && push({ reducedMotion: true }));
|
|
98
|
+
// A read that fails leaves no reduced motion, as the first paint assumed.
|
|
99
|
+
accessibility.current().then(({ reduceMotion }) => !stopped && !heardReduceMotion && reduceMotion && push({ reducedMotion: true }), () => { });
|
|
94
100
|
return () => {
|
|
101
|
+
stopped = true;
|
|
95
102
|
sizes();
|
|
96
103
|
scheme();
|
|
97
104
|
settings();
|
package/dist/conditions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conditions.js","sourceRoot":"","sources":["../src/conditions.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,O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S,CAAC,CAAC;QAC/F,IAAI,MAAM,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;YACtC,iBAAiB,GAAG,IAAI,CAAC;YACzB,IAAI,CAAC,EAAE,aAAa,EAAE,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC,CAAC,CAAC;IACH,0EAA0E;IAC1E,aAAa,CAAC,OAAO,EAAE,CAAC,IAAI,CAC1B,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CACnB,CAAC,OAAO,IAAI,CAAC,iBAAiB,IAAI,YAAY,IAAI,IAAI,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,EACjF,GAAG,EAAE,GAAE,CAAC,CACT,CAAC;IAEF,OAAO,GAAG,EAAE;QACV,OAAO,GAAG,IAAI,CAAC;QACf,KAAK,EAAE,CAAC;QACR,MAAM,EAAE,CAAC;QACT,QAAQ,EAAE,CAAC;IACb,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/**\n * What the engine evaluates media queries against, kept in step with the device.\n *\n * Not a service, because the engine is not injectable and has no reason to be: it is handed to\n * `mount` and handed back, and this connects the two. An app that wants `@media` to keep working\n * after a rotation or a theme change calls `watchConditions` once and never thinks about it again.\n *\n * A rotation changes no component and no binding, so nothing would be dirty and nothing would\n * re-render. The engine re-resolves and commits on its own when the conditions change.\n */\nimport type { Conditions, TokenValue } from '@ng-native/fabric';\nimport { accessibilitySource } from './accessibility.ts';\nimport { colorSchemeSource } from './color-scheme.ts';\nimport { directionSource } from './direction.ts';\nimport { recordKeyboard } from './keyboard.ts';\nimport { screenSource } from './screen.ts';\nimport { reactNative } from './react-native.ts';\n\n/** Just enough of the engine to be told. */\ninterface Resolves<Node = unknown> {\n readonly root: Node;\n updateConditions(conditions: Conditions): void;\n addClass(node: Node, name: string): void;\n removeClass(node: Node, name: string): void;\n /** Measure every text again, after the system text size changed. */\n remeasureText?(): void;\n}\n\n/** The system text size, as a multiplier. One off a device. */\nfunction fontScale(): number {\n return reactNative()?.PixelRatio.getFontScale() ?? 1;\n}\n\n/** The screen's pixels in a point. One off a device. */\nfunction pixelRatio(): number {\n return reactNative()?.PixelRatio.get() ?? 1;\n}\n\nexport interface WatchOptions {\n /**\n * Keep a `dark` class on the root in step with the system scheme, which is what\n * `@ng-native/tailwind`'s `dark:` variant matches. On by default; an app with its own theme\n * switch turns it off and puts `dark` on its own root view instead.\n */\n readonly darkClass?: boolean;\n}\n\nexport function currentConditions(): Conditions {\n const { window } = screenSource().current();\n return {\n width: window.width,\n height: window.height,\n colorScheme: colorSchemeSource().current(),\n // Asynchronous on both platforms, so the first paint says no preference and `watchConditions`\n // corrects it. Reduced motion is a preference about what happens next, not about the frame\n // already on screen, so nothing is lost by learning it a tick late.\n reducedMotion: false,\n fontScale: fontScale(),\n // Read again when the window is resized, which it is when it moves to a screen of another density.\n pixelRatio: pixelRatio(),\n // Settled while the native side starts up, and fixed until the app restarts.\n direction: directionSource().current(),\n };\n}\n\n/**\n * Custom properties the device settles before the first frame, for `mount`'s `tokens` option.\n *\n * Only the hairline so far: the thinnest line the screen can draw, which is a third of a point on\n * a 3x phone and half of one on a 2x. `1px` is what a browser would give and is a visibly fat\n * divider on a modern screen, so a native-looking rule has to ask. React Native works the number\n * out from the pixel ratio; off a device there is no answer, and inventing one would be a line of\n * the wrong weight in every test that draws one.\n *\n * Not watched, unlike the conditions: React Native works the hairline out once and keeps it, so\n * a window moved to a screen of another density keeps the first screen's, as a React Native app's\n * `StyleSheet.hairlineWidth` does. The safe-area insets arrive through `updateTokens`.\n */\nexport function deviceTokens(): Record<string, TokenValue> {\n const native = reactNative();\n return native ? { '--hairline': { length: native.StyleSheet.hairlineWidth } } : {};\n}\n\n/**\n * Keep the engine's conditions current. Returns an unsubscribe, though an app that calls this at\n * bootstrap will never use it.\n */\nexport function watchConditions<Node>(\n engine: Resolves<Node>,\n options: WatchOptions = {},\n): () => void {\n // Not a condition, but this is what runs at startup: see `recordKeyboard`.\n recordKeyboard();\n const screen = screenSource();\n const colors = colorSchemeSource();\n const accessibility = accessibilitySource();\n\n let conditions = currentConditions();\n const push = (change: Partial<Conditions>) => {\n conditions = { ...conditions, ...change };\n if (options.darkClass !== false) {\n if (conditions.colorScheme === 'dark') engine.addClass(engine.root, 'dark');\n else engine.removeClass(engine.root, 'dark');\n }\n engine.updateConditions(conditions);\n };\n // The class for the scheme the app started in, committed at once. Light needs nothing: an app\n // starting light is exactly what it already rendered.\n if (options.darkClass !== false && conditions.colorScheme === 'dark') push({});\n\n // The system text size. Every text on screen was measured at the old one, and keeps that box\n // until it is measured again, so a change goes into the conditions and then re-measures them\n // all. A change arrives as a `Dimensions` change on both platforms; the app coming back to the\n // foreground is checked as well, and the same change reported by both is re-measured once.\n let scale = conditions.fontScale ?? 1;\n const resize = (change: Partial<Conditions>, next: number) => {\n const rescaled = next !== scale;\n scale = next;\n push({ ...change, fontScale: next });\n if (rescaled) engine.remeasureText?.();\n };\n\n const sizes = screen.subscribe(({ window }) =>\n resize({ width: window.width, height: window.height, pixelRatio: pixelRatio() }, fontScale()),\n );\n const scheme = colors.subscribe((colorScheme) => push({ colorScheme }));\n let heardReduceMotion = false;\n let stopped = false;\n const settings = accessibility.subscribe((change) => {\n if (change.fontScale !== undefined && change.fontScale !== scale) resize({}, change.fontScale);\n if (change.reduceMotion !== undefined) {\n heardReduceMotion = true;\n push({ reducedMotion: change.reduceMotion });\n }\n });\n // A read that fails leaves no reduced motion, as the first paint assumed.\n accessibility.current().then(\n ({ reduceMotion }) =>\n !stopped && !heardReduceMotion && reduceMotion && push({ reducedMotion: true }),\n () => {},\n );\n\n return () => {\n stopped = true;\n sizes();\n scheme();\n settings();\n };\n}\n"]}
|
package/dist/dialogs.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ export interface NativeDialogs {
|
|
|
30
30
|
prompt?(title: string, message: string | undefined, onResult: (value: string | null) => void, defaultValue?: string): void;
|
|
31
31
|
actionSheet?(options: {
|
|
32
32
|
title?: string;
|
|
33
|
+
message?: string;
|
|
33
34
|
options: string[];
|
|
34
35
|
cancelButtonIndex: number;
|
|
35
36
|
destructiveButtonIndex?: number;
|
|
@@ -77,8 +78,13 @@ export declare class Dialogs {
|
|
|
77
78
|
*
|
|
78
79
|
* An action sheet on iOS and a dialog on Android, because that is what each platform means by
|
|
79
80
|
* this. A `cancel` choice is where the platform puts cancel rather than in the list.
|
|
81
|
+
*
|
|
82
|
+
* `message` is the smaller line under the title, the one that says what a destructive choice
|
|
83
|
+
* does: the action sheet's message on iOS and the dialog's message on Android.
|
|
80
84
|
*/
|
|
81
|
-
choose(title: string, choices: readonly Choice[]
|
|
85
|
+
choose(title: string, choices: readonly Choice[], options?: {
|
|
86
|
+
message?: string;
|
|
87
|
+
}): Promise<number | null>;
|
|
82
88
|
/**
|
|
83
89
|
* Say something small and transient.
|
|
84
90
|
*
|
package/dist/dialogs.js
CHANGED
|
@@ -75,8 +75,12 @@ export class Dialogs {
|
|
|
75
75
|
*
|
|
76
76
|
* An action sheet on iOS and a dialog on Android, because that is what each platform means by
|
|
77
77
|
* this. A `cancel` choice is where the platform puts cancel rather than in the list.
|
|
78
|
+
*
|
|
79
|
+
* `message` is the smaller line under the title, the one that says what a destructive choice
|
|
80
|
+
* does: the action sheet's message on iOS and the dialog's message on Android.
|
|
78
81
|
*/
|
|
79
|
-
choose(title, choices) {
|
|
82
|
+
choose(title, choices, options = {}) {
|
|
83
|
+
const { message } = options;
|
|
80
84
|
const cancelAt = choices.findIndex((choice) => choice.style === 'cancel');
|
|
81
85
|
const destructiveAt = choices.findIndex((choice) => choice.style === 'destructive');
|
|
82
86
|
return new Promise((resolve) => {
|
|
@@ -89,6 +93,7 @@ export class Dialogs {
|
|
|
89
93
|
const cancelIndex = cancelAt >= 0 ? cancelAt : labels.push('Cancel') - 1;
|
|
90
94
|
this.native.actionSheet({
|
|
91
95
|
title,
|
|
96
|
+
...(message !== undefined ? { message } : {}),
|
|
92
97
|
options: labels,
|
|
93
98
|
cancelButtonIndex: cancelIndex,
|
|
94
99
|
...(destructiveAt >= 0 ? { destructiveButtonIndex: destructiveAt } : {}),
|
|
@@ -118,7 +123,7 @@ export class Dialogs {
|
|
|
118
123
|
'at most three buttons, counting the cancel. The rest will not appear. Use a ' +
|
|
119
124
|
'`ui-select` or an `action-sheet`-shaped list for anything longer.');
|
|
120
125
|
}
|
|
121
|
-
this.native.alert(title,
|
|
126
|
+
this.native.alert(title, message, buttons);
|
|
122
127
|
});
|
|
123
128
|
}
|
|
124
129
|
/**
|
package/dist/dialogs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dialogs.js","sourceRoot":"","sources":["../src/dialogs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,WAAW,EAAoB,MAAM,mBAAmB,CAAC;;AAkClE;;;;;GAKG;AAEH,MAAM,OAAO,OAAO;IAClB,uEAAuE;IACvE,MAAM,CAAU,MAAM,GAAG,IAAI,cAAc,CAAuB,6BAA6B,EAAE;QAC/F,OAAO,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC;KAC3C,CAAC,CAAC;IAEc,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAEjD,6FAA6F;IAC7F,IAAI,CAAC,KAAa,EAAE,OAAgB,EAAE,OAAO,GAAG,IAAI;QAClD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC7B,IAAI,CAAC,IAAI,CAAC,MAAM;gBAAE,OAAO,OAAO,EAAE,CAAC;YACnC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;QACnF,CAAC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;aACJ;YACH,CAAC,CAAC,EAAE,CAAC;KACR,CAAC;AACJ,CAAC","sourcesContent":["/**\n * The platform's own dialogs: an alert, a confirmation, a prompt, an action sheet, a toast.\n *\n * All of these are callback APIs, and the reason to wrap them is that **a dialog is a question**.\n * `Alert.alert` hands its answer to one of several `onPress` callbacks, so asking something and\n * acting on the answer means splitting one thought across three functions. A promise puts it back\n * together, and `await` at the call site reads like what it is.\n *\n * The platform split is the other half. An action sheet is iOS's way of offering a short list of\n * choices and Android's is a dialog; a toast is Android's way of saying something small and iOS\n * has none. `choose` and `notify` pick per platform, so an app writes the intent rather than the\n * platform - and the one thing neither can do is fail silently on the platform it is not for.\n */\n\nimport { InjectionToken, Service, inject } from '@angular/core';\nimport { reactNative, type ReactNative } from './react-native.ts';\n\n/** One choice in a dialog or an action sheet. */\nexport interface Choice {\n readonly label: string;\n /** `cancel` is dismissal; `destructive` is the one the platform paints red. */\n readonly style?: 'default' | 'cancel' | 'destructive';\n}\n\nexport interface NativeDialogs {\n readonly platform: 'ios' | 'android' | string;\n alert(\n title: string,\n message: string | undefined,\n buttons: readonly { text: string; style?: string; onPress?: () => void }[],\n ): void;\n prompt?(\n title: string,\n message: string | undefined,\n onResult: (value: string | null) => void,\n defaultValue?: string,\n ): void;\n actionSheet?(\n options: {\n title?: string;\n options: string[];\n cancelButtonIndex: number;\n destructiveButtonIndex?: number;\n },\n onSelect: (index: number) => void,\n ): void;\n toast?(message: string, long: boolean): void;\n}\n\n/**\n * `inject(Dialogs).confirm('Delete this?', { destructive: true })`.\n *\n * A dialog is a question, so every method here resolves to the answer rather than handing it to\n * one of several callbacks.\n */\n@Service()\nexport class Dialogs {\n /** Overridden in a test to answer a dialog without one being shown. */\n static readonly SOURCE = new InjectionToken<NativeDialogs | null>('angular-native.dialogSource', {\n factory: () => dialogSource(reactNative()),\n });\n\n private readonly native = inject(Dialogs.SOURCE);\n\n /** Say something, and wait until it has been read. Resolves when the dialog is dismissed. */\n tell(title: string, message?: string, dismiss = 'OK'): Promise<void> {\n return new Promise((resolve) => {\n if (!this.native) return resolve();\n this.native.alert(title, message, [{ text: dismiss, onPress: () => resolve() }]);\n });\n }\n\n /**\n * Ask something with two answers. Resolves to whether they agreed.\n *\n * `destructive` paints the confirm button as the platform paints a delete, and puts cancel where\n * the platform puts it - which on iOS is the *right*, so a confirmation dialog does not train\n * people to tap the wrong thing.\n */\n confirm(\n title: string,\n options: { message?: string; confirm?: string; cancel?: string; destructive?: boolean } = {},\n ): Promise<boolean> {\n const { message, confirm = 'OK', cancel = 'Cancel', destructive = false } = options;\n return new Promise((resolve) => {\n if (!this.native) return resolve(false);\n this.native.alert(title, message, [\n { text: cancel, style: 'cancel', onPress: () => resolve(false) },\n {\n text: confirm,\n style: destructive ? 'destructive' : 'default',\n onPress: () => resolve(true),\n },\n ]);\n });\n }\n\n /**\n * Ask for a line of text. Resolves to null if they cancelled.\n *\n * iOS only: `Alert.prompt` has no Android equivalent, and inventing one out of a modal and a\n * text input would be a dialog that looks nothing like the platform's. On Android this resolves\n * to null so a caller can fall back to a screen of its own.\n */\n ask(title: string, options: { message?: string; value?: string } = {}): Promise<string | null> {\n return new Promise((resolve) => {\n if (!this.native?.prompt) return resolve(null);\n this.native.prompt(title, options.message, resolve, options.value);\n });\n }\n\n /**\n * Offer a short list of choices. Resolves to the index chosen, or null if dismissed.\n *\n * An action sheet on iOS and a dialog on Android, because that is what each platform means by\n * this. A `cancel` choice is where the platform puts cancel rather than in the list.\n */\n choose(title: string, choices: readonly Choice[]): Promise<number | null> {\n const cancelAt = choices.findIndex((choice) => choice.style === 'cancel');\n const destructiveAt = choices.findIndex((choice) => choice.style === 'destructive');\n\n return new Promise((resolve) => {\n if (!this.native) return resolve(null);\n\n if (this.native.actionSheet) {\n // iOS wants cancel last and named by index; a list with none gets one, because an action\n // sheet with no way out is one the user has to guess at.\n const labels = choices.map((choice) => choice.label);\n const cancelIndex = cancelAt >= 0 ? cancelAt : labels.push('Cancel') - 1;\n this.native.actionSheet(\n {\n title,\n options: labels,\n cancelButtonIndex: cancelIndex,\n ...(destructiveAt >= 0 ? { destructiveButtonIndex: destructiveAt } : {}),\n },\n (index) => resolve(index === cancelIndex ? null : index),\n );\n return;\n }\n\n /*\n * Android's alert is put up `cancelable: false` by React Native, so a press outside does\n * nothing and neither does the back button. Without a cancel among the choices there is no\n * way at all to decline - the user has to pick something - so one is appended, exactly as\n * the iOS branch above does for the same reason.\n *\n * Android's dialog holds three buttons: a negative, a neutral and a positive. Anything past\n * that is dropped by the platform without a word, and a choice the user cannot see is worse\n * than a list that refused to open, so it says so.\n */\n const buttons = choices.map((choice, index) => ({\n text: choice.label,\n style: choice.style,\n onPress: () => resolve(choice.style === 'cancel' ? null : index),\n }));\n if (cancelAt < 0) {\n buttons.push({ text: 'Cancel', style: 'cancel', onPress: () => resolve(null) });\n }\n if (buttons.length > 3) {\n console.error(\n `[angular-native] Dialogs.choose was given ${choices.length} choices and Android shows ` +\n 'at most three buttons, counting the cancel. The rest will not appear. Use a ' +\n '`ui-select` or an `action-sheet`-shaped list for anything longer.',\n );\n }\n this.native.alert(title, undefined, buttons);\n });\n }\n\n /**\n * Say something small and transient.\n *\n * A toast on Android. iOS has no such thing and never has, so this does nothing there rather\n * than putting up a modal alert for something that did not warrant interrupting anyone - and an\n * app that must be seen should use `tell`.\n */\n notify(message: string, options: { long?: boolean } = {}): void {\n this.native?.toast?.(message, options.long ?? false);\n }\n}\n\n/**\n * The platform's dialogs, from React Native's own modules.\n *\n * `Alert.prompt` and `ActionSheetIOS` are iOS-only and `ToastAndroid` is Android-only; each is\n * left absent rather than shimmed, which is what lets `ask`, `choose` and `notify` above decide\n * what to do about it.\n *\n * Which platform it is has to be asked outright, because React Native's own modules do not answer\n * it. `react-native` exports `ActionSheetIOS` on Android too - the object is there and so is\n * `showActionSheetWithOptions`; only the TurboModule underneath is null, and the invariant that\n * catches that throws out of the promise `choose` returns, so a press did nothing at all and said\n * nothing about it. `Alert.prompt` is worse: it exists on Android and its body is one\n * `Platform.OS === 'ios'` check, so it returns having called no callback and the promise `ask`\n * returns never settles. `ToastAndroid` is the mirror image on iOS. Presence is not capability\n * here; only the platform name is.\n */\nexport function dialogSource(\n native: Pick<ReactNative, 'Platform' | 'Alert' | 'ActionSheetIOS' | 'ToastAndroid'> | null,\n): NativeDialogs | null {\n if (!native) return null;\n\n const ios = native.Platform.OS === 'ios';\n const android = native.Platform.OS === 'android';\n\n return {\n platform: native.Platform.OS,\n alert: (title, message, buttons) => native.Alert.alert(title, message, [...buttons]),\n // Buttons rather than a callback: given a callback, `Alert.prompt` answers OK alone, and the\n // Cancel the native alert adds calls nothing, so a cancelled `ask` never settled.\n ...(ios && native.Alert.prompt\n ? {\n prompt: (title, message, onResult, defaultValue) =>\n native.Alert.prompt!(\n title,\n message,\n [\n { text: 'Cancel', style: 'cancel', onPress: () => onResult(null) },\n { text: 'OK', onPress: (value) => onResult(value ?? '') },\n ],\n undefined,\n defaultValue,\n ),\n }\n : {}),\n ...(ios && native.ActionSheetIOS\n ? {\n actionSheet: (options, onSelect) =>\n native.ActionSheetIOS!.showActionSheetWithOptions(options, onSelect),\n }\n : {}),\n ...(android && native.ToastAndroid\n ? {\n toast: (message, long) =>\n native.ToastAndroid!.show(\n message,\n long ? native.ToastAndroid!.LONG : native.ToastAndroid!.SHORT,\n ),\n }\n : {}),\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"dialogs.js","sourceRoot":"","sources":["../src/dialogs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,WAAW,EAAoB,MAAM,mBAAmB,CAAC;;AAmClE;;;;;GAKG;AAEH,MAAM,OAAO,OAAO;IAClB,uEAAuE;IACvE,MAAM,CAAU,MAAM,GAAG,IAAI,cAAc,CAAuB,6BAA6B,EAAE;QAC/F,OAAO,EAAE,GAAG,EAAE,CAAC,YAAY,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O,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE;iBAC1D,EACD,SAAS,EACT,YAAY,CACb;aACJ;YACH,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,CAAC,GAAG,IAAI,MAAM,CAAC,cAAc;YAC9B,CAAC,CAAC;gBACE,WAAW,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE,CACjC,MAAM,CAAC,cAAe,CAAC,0BAA0B,CAAC,OAAO,EAAE,QAAQ,CAAC;aACvE;YACH,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,CAAC,OAAO,IAAI,MAAM,CAAC,YAAY;YAChC,CAAC,CAAC;gBACE,KAAK,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CACvB,MAAM,CAAC,YAAa,CAAC,IAAI,CACvB,OAAO,EACP,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,YAAa,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,YAAa,CAAC,KAAK,CAC9D;aACJ;YACH,CAAC,CAAC,EAAE,CAAC;KACR,CAAC;AACJ,CAAC","sourcesContent":["/**\n * The platform's own dialogs: an alert, a confirmation, a prompt, an action sheet, a toast.\n *\n * All of these are callback APIs, and the reason to wrap them is that **a dialog is a question**.\n * `Alert.alert` hands its answer to one of several `onPress` callbacks, so asking something and\n * acting on the answer means splitting one thought across three functions. A promise puts it back\n * together, and `await` at the call site reads like what it is.\n *\n * The platform split is the other half. An action sheet is iOS's way of offering a short list of\n * choices and Android's is a dialog; a toast is Android's way of saying something small and iOS\n * has none. `choose` and `notify` pick per platform, so an app writes the intent rather than the\n * platform - and the one thing neither can do is fail silently on the platform it is not for.\n */\n\nimport { InjectionToken, Service, inject } from '@angular/core';\nimport { reactNative, type ReactNative } from './react-native.ts';\n\n/** One choice in a dialog or an action sheet. */\nexport interface Choice {\n readonly label: string;\n /** `cancel` is dismissal; `destructive` is the one the platform paints red. */\n readonly style?: 'default' | 'cancel' | 'destructive';\n}\n\nexport interface NativeDialogs {\n readonly platform: 'ios' | 'android' | string;\n alert(\n title: string,\n message: string | undefined,\n buttons: readonly { text: string; style?: string; onPress?: () => void }[],\n ): void;\n prompt?(\n title: string,\n message: string | undefined,\n onResult: (value: string | null) => void,\n defaultValue?: string,\n ): void;\n actionSheet?(\n options: {\n title?: string;\n message?: string;\n options: string[];\n cancelButtonIndex: number;\n destructiveButtonIndex?: number;\n },\n onSelect: (index: number) => void,\n ): void;\n toast?(message: string, long: boolean): void;\n}\n\n/**\n * `inject(Dialogs).confirm('Delete this?', { destructive: true })`.\n *\n * A dialog is a question, so every method here resolves to the answer rather than handing it to\n * one of several callbacks.\n */\n@Service()\nexport class Dialogs {\n /** Overridden in a test to answer a dialog without one being shown. */\n static readonly SOURCE = new InjectionToken<NativeDialogs | null>('angular-native.dialogSource', {\n factory: () => dialogSource(reactNative()),\n });\n\n private readonly native = inject(Dialogs.SOURCE);\n\n /** Say something, and wait until it has been read. Resolves when the dialog is dismissed. */\n tell(title: string, message?: string, dismiss = 'OK'): Promise<void> {\n return new Promise((resolve) => {\n if (!this.native) return resolve();\n this.native.alert(title, message, [{ text: dismiss, onPress: () => resolve() }]);\n });\n }\n\n /**\n * Ask something with two answers. Resolves to whether they agreed.\n *\n * `destructive` paints the confirm button as the platform paints a delete, and puts cancel where\n * the platform puts it - which on iOS is the *right*, so a confirmation dialog does not train\n * people to tap the wrong thing.\n */\n confirm(\n title: string,\n options: { message?: string; confirm?: string; cancel?: string; destructive?: boolean } = {},\n ): Promise<boolean> {\n const { message, confirm = 'OK', cancel = 'Cancel', destructive = false } = options;\n return new Promise((resolve) => {\n if (!this.native) return resolve(false);\n this.native.alert(title, message, [\n { text: cancel, style: 'cancel', onPress: () => resolve(false) },\n {\n text: confirm,\n style: destructive ? 'destructive' : 'default',\n onPress: () => resolve(true),\n },\n ]);\n });\n }\n\n /**\n * Ask for a line of text. Resolves to null if they cancelled.\n *\n * iOS only: `Alert.prompt` has no Android equivalent, and inventing one out of a modal and a\n * text input would be a dialog that looks nothing like the platform's. On Android this resolves\n * to null so a caller can fall back to a screen of its own.\n */\n ask(title: string, options: { message?: string; value?: string } = {}): Promise<string | null> {\n return new Promise((resolve) => {\n if (!this.native?.prompt) return resolve(null);\n this.native.prompt(title, options.message, resolve, options.value);\n });\n }\n\n /**\n * Offer a short list of choices. Resolves to the index chosen, or null if dismissed.\n *\n * An action sheet on iOS and a dialog on Android, because that is what each platform means by\n * this. A `cancel` choice is where the platform puts cancel rather than in the list.\n *\n * `message` is the smaller line under the title, the one that says what a destructive choice\n * does: the action sheet's message on iOS and the dialog's message on Android.\n */\n choose(\n title: string,\n choices: readonly Choice[],\n options: { message?: string } = {},\n ): Promise<number | null> {\n const { message } = options;\n const cancelAt = choices.findIndex((choice) => choice.style === 'cancel');\n const destructiveAt = choices.findIndex((choice) => choice.style === 'destructive');\n\n return new Promise((resolve) => {\n if (!this.native) return resolve(null);\n\n if (this.native.actionSheet) {\n // iOS wants cancel last and named by index; a list with none gets one, because an action\n // sheet with no way out is one the user has to guess at.\n const labels = choices.map((choice) => choice.label);\n const cancelIndex = cancelAt >= 0 ? cancelAt : labels.push('Cancel') - 1;\n this.native.actionSheet(\n {\n title,\n ...(message !== undefined ? { message } : {}),\n options: labels,\n cancelButtonIndex: cancelIndex,\n ...(destructiveAt >= 0 ? { destructiveButtonIndex: destructiveAt } : {}),\n },\n (index) => resolve(index === cancelIndex ? null : index),\n );\n return;\n }\n\n /*\n * Android's alert is put up `cancelable: false` by React Native, so a press outside does\n * nothing and neither does the back button. Without a cancel among the choices there is no\n * way at all to decline - the user has to pick something - so one is appended, exactly as\n * the iOS branch above does for the same reason.\n *\n * Android's dialog holds three buttons: a negative, a neutral and a positive. Anything past\n * that is dropped by the platform without a word, and a choice the user cannot see is worse\n * than a list that refused to open, so it says so.\n */\n const buttons = choices.map((choice, index) => ({\n text: choice.label,\n style: choice.style,\n onPress: () => resolve(choice.style === 'cancel' ? null : index),\n }));\n if (cancelAt < 0) {\n buttons.push({ text: 'Cancel', style: 'cancel', onPress: () => resolve(null) });\n }\n if (buttons.length > 3) {\n console.error(\n `[angular-native] Dialogs.choose was given ${choices.length} choices and Android shows ` +\n 'at most three buttons, counting the cancel. The rest will not appear. Use a ' +\n '`ui-select` or an `action-sheet`-shaped list for anything longer.',\n );\n }\n this.native.alert(title, message, buttons);\n });\n }\n\n /**\n * Say something small and transient.\n *\n * A toast on Android. iOS has no such thing and never has, so this does nothing there rather\n * than putting up a modal alert for something that did not warrant interrupting anyone - and an\n * app that must be seen should use `tell`.\n */\n notify(message: string, options: { long?: boolean } = {}): void {\n this.native?.toast?.(message, options.long ?? false);\n }\n}\n\n/**\n * The platform's dialogs, from React Native's own modules.\n *\n * `Alert.prompt` and `ActionSheetIOS` are iOS-only and `ToastAndroid` is Android-only; each is\n * left absent rather than shimmed, which is what lets `ask`, `choose` and `notify` above decide\n * what to do about it.\n *\n * Which platform it is has to be asked outright, because React Native's own modules do not answer\n * it. `react-native` exports `ActionSheetIOS` on Android too - the object is there and so is\n * `showActionSheetWithOptions`; only the TurboModule underneath is null, and the invariant that\n * catches that throws out of the promise `choose` returns, so a press did nothing at all and said\n * nothing about it. `Alert.prompt` is worse: it exists on Android and its body is one\n * `Platform.OS === 'ios'` check, so it returns having called no callback and the promise `ask`\n * returns never settles. `ToastAndroid` is the mirror image on iOS. Presence is not capability\n * here; only the platform name is.\n */\nexport function dialogSource(\n native: Pick<ReactNative, 'Platform' | 'Alert' | 'ActionSheetIOS' | 'ToastAndroid'> | null,\n): NativeDialogs | null {\n if (!native) return null;\n\n const ios = native.Platform.OS === 'ios';\n const android = native.Platform.OS === 'android';\n\n return {\n platform: native.Platform.OS,\n alert: (title, message, buttons) => native.Alert.alert(title, message, [...buttons]),\n // Buttons rather than a callback: given a callback, `Alert.prompt` answers OK alone, and the\n // Cancel the native alert adds calls nothing, so a cancelled `ask` never settled.\n ...(ios && native.Alert.prompt\n ? {\n prompt: (title, message, onResult, defaultValue) =>\n native.Alert.prompt!(\n title,\n message,\n [\n { text: 'Cancel', style: 'cancel', onPress: () => onResult(null) },\n { text: 'OK', onPress: (value) => onResult(value ?? '') },\n ],\n undefined,\n defaultValue,\n ),\n }\n : {}),\n ...(ios && native.ActionSheetIOS\n ? {\n actionSheet: (options, onSelect) =>\n native.ActionSheetIOS!.showActionSheetWithOptions(options, onSelect),\n }\n : {}),\n ...(android && native.ToastAndroid\n ? {\n toast: (message, long) =>\n native.ToastAndroid!.show(\n message,\n long ? native.ToastAndroid!.LONG : native.ToastAndroid!.SHORT,\n ),\n }\n : {}),\n };\n}\n"]}
|
package/dist/hardware-back.d.ts
CHANGED
|
@@ -19,7 +19,9 @@ export declare class HardwareBack {
|
|
|
19
19
|
private readonly source;
|
|
20
20
|
/**
|
|
21
21
|
* Handle the back press. React Native runs the most recently added handler first, so a screen
|
|
22
|
-
* that subscribes on mount outranks the one below it.
|
|
22
|
+
* that subscribes on mount outranks the one below it. Called in a screen's injection context, as
|
|
23
|
+
* from its constructor, the handler is asked only while that screen is in front: a screen pushed
|
|
24
|
+
* or presented over it gets the press. Returns an unsubscribe.
|
|
23
25
|
*/
|
|
24
26
|
handle(handler: () => boolean): () => void;
|
|
25
27
|
static ɵfac: i0.ɵɵFactoryDeclaration<HardwareBack, never>;
|
package/dist/hardware-back.js
CHANGED
|
@@ -9,7 +9,10 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { InjectionToken, Service, inject } from '@angular/core';
|
|
11
11
|
import { reactNative } from "./react-native.js";
|
|
12
|
+
import { SCREEN_IN_FRONT } from "./screen-in-front.js";
|
|
12
13
|
import * as i0 from "@angular/core";
|
|
14
|
+
/** Angular's NG0203, `inject()` called outside an injection context. */
|
|
15
|
+
const NO_INJECTION_CONTEXT = -203;
|
|
13
16
|
export function hardwareBackSource() {
|
|
14
17
|
const native = reactNative();
|
|
15
18
|
if (!native)
|
|
@@ -27,10 +30,13 @@ export class HardwareBack {
|
|
|
27
30
|
source = inject(HardwareBack.SOURCE);
|
|
28
31
|
/**
|
|
29
32
|
* Handle the back press. React Native runs the most recently added handler first, so a screen
|
|
30
|
-
* that subscribes on mount outranks the one below it.
|
|
33
|
+
* that subscribes on mount outranks the one below it. Called in a screen's injection context, as
|
|
34
|
+
* from its constructor, the handler is asked only while that screen is in front: a screen pushed
|
|
35
|
+
* or presented over it gets the press. Returns an unsubscribe.
|
|
31
36
|
*/
|
|
32
37
|
handle(handler) {
|
|
33
|
-
|
|
38
|
+
const inFront = callerInFront();
|
|
39
|
+
return this.source.subscribe(() => (inFront?.() ?? true) && handler());
|
|
34
40
|
}
|
|
35
41
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: HardwareBack, deps: [], target: i0.ɵɵFactoryTarget.Service });
|
|
36
42
|
static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.2.0", ngImport: i0, type: HardwareBack });
|
|
@@ -38,4 +44,15 @@ export class HardwareBack {
|
|
|
38
44
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: HardwareBack, decorators: [{
|
|
39
45
|
type: Service
|
|
40
46
|
}] });
|
|
47
|
+
/** Whether the screen the caller is on is in front, or null where nothing says: outside an injection context, or one with no screen. */
|
|
48
|
+
function callerInFront() {
|
|
49
|
+
try {
|
|
50
|
+
return inject(SCREEN_IN_FRONT, { optional: true });
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
if (error.code !== NO_INJECTION_CONTEXT)
|
|
54
|
+
throw error;
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
41
58
|
//# sourceMappingURL=hardware-back.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hardware-back.js","sourceRoot":"","sources":["../src/hardware-back.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,cAAc,EAA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AY;wGAAZ,YAAY;;2FAAZ,YAAY;kBADxB,OAAO;;AAsBR,wIAAwI;AACxI,SAAS,aAAa;IACpB,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,eAAe,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IACrD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAK,KAA2B,CAAC,IAAI,KAAK,oBAAoB;YAAE,MAAM,KAAK,CAAC;QAC5E,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["/**\n * Android's hardware back button.\n *\n * Not a signal, because a press is a question rather than a state: the platform asks whether\n * anybody wants it, and the answer decides what happens next. A handler returns whether it\n * consumed the press, and returning false lets the platform do what it would have done - at the\n * bottom of a navigation stack that means backgrounding the app rather than closing it, so a user\n * who backs out of the first screen finds the app where they left it.\n */\nimport { InjectionToken, Service, inject, type Signal } from '@angular/core';\nimport { reactNative } from './react-native.ts';\nimport { SCREEN_IN_FRONT } from './screen-in-front.ts';\n\n/** Angular's NG0203, `inject()` called outside an injection context. */\nconst NO_INJECTION_CONTEXT = -203;\n\nexport interface HardwareBackSource {\n subscribe(listener: () => boolean): () => void;\n}\n\nexport function hardwareBackSource(): HardwareBackSource {\n const native = reactNative();\n if (!native) return { subscribe: () => () => {} };\n\n return {\n subscribe: (listener) => {\n const subscription = native.BackHandler.addEventListener('hardwareBackPress', listener);\n return () => subscription.remove();\n },\n };\n}\n\n@Service()\nexport class HardwareBack {\n /** Overridden in a test to press the button without a device. */\n static readonly SOURCE = new InjectionToken<HardwareBackSource>(\n 'angular-native.hardwareBackSource',\n { factory: hardwareBackSource },\n );\n\n private readonly source = inject(HardwareBack.SOURCE);\n\n /**\n * Handle the back press. React Native runs the most recently added handler first, so a screen\n * that subscribes on mount outranks the one below it. Called in a screen's injection context, as\n * from its constructor, the handler is asked only while that screen is in front: a screen pushed\n * or presented over it gets the press. Returns an unsubscribe.\n */\n handle(handler: () => boolean): () => void {\n const inFront = callerInFront();\n return this.source.subscribe(() => (inFront?.() ?? true) && handler());\n }\n}\n\n/** Whether the screen the caller is on is in front, or null where nothing says: outside an injection context, or one with no screen. */\nfunction callerInFront(): Signal<boolean> | null {\n try {\n return inject(SCREEN_IN_FRONT, { optional: true });\n } catch (error) {\n if ((error as { code?: number }).code !== NO_INJECTION_CONTEXT) throw error;\n return null;\n }\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -27,4 +27,5 @@ export { TopClaim, WindowClaims, onWindowFront, sharedBySource, type Claim, } fr
|
|
|
27
27
|
export { NavigationBar, navigationBarSource, type NavigationBarSource, type NavigationBarState, type NavigationBarStyle, } from './navigation-bar.ts';
|
|
28
28
|
export { SCREEN_IN_FRONT } from './screen-in-front.ts';
|
|
29
29
|
export { NATIVE_HISTORY } from './native-history.ts';
|
|
30
|
+
export { OS } from './os.ts';
|
|
30
31
|
export { OS_VERSION } from './os-version.ts';
|
package/dist/index.js
CHANGED
|
@@ -26,5 +26,6 @@ export { TopClaim, WindowClaims, onWindowFront, sharedBySource, } from "./window
|
|
|
26
26
|
export { NavigationBar, navigationBarSource, } from "./navigation-bar.js";
|
|
27
27
|
export { SCREEN_IN_FRONT } from "./screen-in-front.js";
|
|
28
28
|
export { NATIVE_HISTORY } from "./native-history.js";
|
|
29
|
+
export { OS } from "./os.js";
|
|
29
30
|
export { OS_VERSION } from "./os-version.js";
|
|
30
31
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EACL,aAAa,GAGd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAuC,MAAM,gBAAgB,CAAC;AAC/E,OAAO,EAAE,WAAW,EAAuC,MAAM,mBAAmB,CAAC;AACrF,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,eAAe,GAEhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,EAAuB,MAAM,iBAAiB,CAAC;AACzF,OAAO,EACL,SAAS,GAIV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,iBAAiB,GAGlB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,OAAO,EAA0C,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,OAAO,EAAmC,MAAM,cAAc,CAAC;AACxE,OAAO,EACL,eAAe,GAIhB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,OAAO,EAAyC,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAwB,MAAM,gBAAgB,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAA2B,MAAM,oBAAoB,CAAC;AAC/F,OAAO,EACL,eAAe,EACf,QAAQ,EACR,cAAc,GAIf,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,QAAQ,EAA2B,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,EAA4C,MAAM,aAAa,CAAC;AAC9F,OAAO,EACL,SAAS,EACT,eAAe,GAKhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,cAAc,GAEf,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,aAAa,EACb,mBAAmB,GAIpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC","sourcesContent":["/**\n * The host: the device, the operating system, and the user's settings.\n *\n * Every capability here is a service with its own factory, so injecting one is the whole setup\n * and one nobody injects is never constructed. Off a device each falls back to doing nothing,\n * which is what makes the whole package importable by the test suite.\n */\nexport {\n Accessibility,\n type AccessibilitySettings,\n type AccessibilitySource,\n} from './accessibility.ts';\nexport { AppState, type AppStateSource, type AppStatus } from './app-state.ts';\nexport { ColorScheme, type ColorSchemeSource, type Scheme } from './color-scheme.ts';\nexport {\n currentConditions,\n deviceTokens,\n watchConditions,\n type WatchOptions,\n} from './conditions.ts';\nexport { DeepLinks, deepLinkSource, pathOf, type DeepLinkSource } from './deep-links.ts';\nexport {\n Direction,\n type DirectionContext,\n type DirectionSource,\n type LayoutDirection,\n} from './direction.ts';\nexport {\n androidPermission,\n type AndroidPermissions,\n type PermissionAnswer,\n} from './android-permissions.ts';\nexport { DevMenu, type DevMenuSource, type NativeDevMenu } from './dev-menu.ts';\nexport { Dialogs, type Choice, type NativeDialogs } from './dialogs.ts';\nexport {\n LayoutAnimation,\n type LayoutChange,\n type LayoutEasing,\n type NativeLayoutAnimation,\n} from './layout-animation.ts';\nexport { Sharing, type NativeSharing, type ShareRequest } from './sharing.ts';\nexport { Vibration, type NativeVibration } from './vibration.ts';\nexport { HardwareBack, hardwareBackSource, type HardwareBackSource } from './hardware-back.ts';\nexport {\n KEYBOARD_MOTION,\n Keyboard,\n keyboardSource,\n type KeyboardMetrics,\n type KeyboardMotion,\n type KeyboardSource,\n} from './keyboard.ts';\nexport type { NativeKeyboardEvent } from './react-native.ts';\nexport { SafeArea, type Frame, type Insets } from './safe-area.ts';\nexport { COMPACT_WIDTH, Screen, type ScreenSource, type Size, type Sizes } from './screen.ts';\nexport {\n StatusBar,\n statusBarSource,\n type PlatformStatusBarStyle,\n type StatusBarSource,\n type StatusBarState,\n type StatusBarStyle,\n} from './status-bar.ts';\nexport {\n TopClaim,\n WindowClaims,\n onWindowFront,\n sharedBySource,\n type Claim,\n} from './window-claims.ts';\nexport {\n NavigationBar,\n navigationBarSource,\n type NavigationBarSource,\n type NavigationBarState,\n type NavigationBarStyle,\n} from './navigation-bar.ts';\nexport { SCREEN_IN_FRONT } from './screen-in-front.ts';\nexport { NATIVE_HISTORY } from './native-history.ts';\n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BAAqB,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC","sourcesContent":["/**\n * The host: the device, the operating system, and the user's settings.\n *\n * Every capability here is a service with its own factory, so injecting one is the whole setup\n * and one nobody injects is never constructed. Off a device each falls back to doing nothing,\n * which is what makes the whole package importable by the test suite.\n */\nexport {\n Accessibility,\n type AccessibilitySettings,\n type AccessibilitySource,\n} from './accessibility.ts';\nexport { AppState, type AppStateSource, type AppStatus } from './app-state.ts';\nexport { ColorScheme, type ColorSchemeSource, type Scheme } from './color-scheme.ts';\nexport {\n currentConditions,\n deviceTokens,\n watchConditions,\n type WatchOptions,\n} from './conditions.ts';\nexport { DeepLinks, deepLinkSource, pathOf, type DeepLinkSource } from './deep-links.ts';\nexport {\n Direction,\n type DirectionContext,\n type DirectionSource,\n type LayoutDirection,\n} from './direction.ts';\nexport {\n androidPermission,\n type AndroidPermissions,\n type PermissionAnswer,\n} from './android-permissions.ts';\nexport { DevMenu, type DevMenuSource, type NativeDevMenu } from './dev-menu.ts';\nexport { Dialogs, type Choice, type NativeDialogs } from './dialogs.ts';\nexport {\n LayoutAnimation,\n type LayoutChange,\n type LayoutEasing,\n type NativeLayoutAnimation,\n} from './layout-animation.ts';\nexport { Sharing, type NativeSharing, type ShareRequest } from './sharing.ts';\nexport { Vibration, type NativeVibration } from './vibration.ts';\nexport { HardwareBack, hardwareBackSource, type HardwareBackSource } from './hardware-back.ts';\nexport {\n KEYBOARD_MOTION,\n Keyboard,\n keyboardSource,\n type KeyboardMetrics,\n type KeyboardMotion,\n type KeyboardSource,\n} from './keyboard.ts';\nexport type { NativeKeyboardEvent } from './react-native.ts';\nexport { SafeArea, type Frame, type Insets } from './safe-area.ts';\nexport { COMPACT_WIDTH, Screen, type ScreenSource, type Size, type Sizes } from './screen.ts';\nexport {\n StatusBar,\n statusBarSource,\n type PlatformStatusBarStyle,\n type StatusBarSource,\n type StatusBarState,\n type StatusBarStyle,\n} from './status-bar.ts';\nexport {\n TopClaim,\n WindowClaims,\n onWindowFront,\n sharedBySource,\n type Claim,\n} from './window-claims.ts';\nexport {\n NavigationBar,\n navigationBarSource,\n type NavigationBarSource,\n type NavigationBarState,\n type NavigationBarStyle,\n} from './navigation-bar.ts';\nexport { SCREEN_IN_FRONT } from './screen-in-front.ts';\nexport { NATIVE_HISTORY } from './native-history.ts';\nexport { OS } from './os.ts';\nexport { OS_VERSION } from './os-version.ts';\n"]}
|
package/dist/keyboard.d.ts
CHANGED
|
@@ -12,7 +12,10 @@ import * as i0 from "@angular/core";
|
|
|
12
12
|
export interface KeyboardMetrics {
|
|
13
13
|
/** Height in dp; zero when the keyboard is hidden. */
|
|
14
14
|
readonly height: number;
|
|
15
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* Where its top edge is, from the top of the screen. Absent when hidden. A view measured in the
|
|
17
|
+
* window is compared with it less `Keyboard.windowTop`.
|
|
18
|
+
*/
|
|
16
19
|
readonly screenY?: number;
|
|
17
20
|
/** How long its own animation takes, in ms, for anything moving with it. */
|
|
18
21
|
readonly duration?: number;
|
|
@@ -34,13 +37,20 @@ export interface KeyboardSource {
|
|
|
34
37
|
*/
|
|
35
38
|
subscribeMotion?(listener: (frame: KeyboardMetrics | null) => void): () => void;
|
|
36
39
|
dismiss(): void;
|
|
40
|
+
/**
|
|
41
|
+
* How far below the top of the screen the window a view is measured in starts, in points, for
|
|
42
|
+
* a source that knows it is not zero. Read when it is compared, as it changes with the status
|
|
43
|
+
* bar. See `keyboardSource`.
|
|
44
|
+
*/
|
|
45
|
+
readonly windowTop?: number;
|
|
37
46
|
}
|
|
38
47
|
/**
|
|
39
48
|
* The events RN's own KeyboardAvoidingView listens for, which differ by platform.
|
|
40
49
|
*
|
|
41
50
|
* On iOS the Will events: they arrive as the keyboard starts to move, carrying its duration and
|
|
42
51
|
* curve, so a layout configured from them moves with the keyboard. The Did events arrive once it
|
|
43
|
-
* has landed, and a layout that waits for them moves after it
|
|
52
|
+
* has landed, and a layout that waits for them moves after it, so they are heard only until the
|
|
53
|
+
first Will event, for a keyboard already moving when listening starts. `keyboardWillChangeFrame` covers a
|
|
44
54
|
* keyboard that changes size while it is up - the predictive bar, another language's layout - and
|
|
45
55
|
* is ignored while it is down: UIKit posts one beside every show and hide as well, and the one
|
|
46
56
|
* beside a hide is the frame the keyboard leaves by, off the bottom of the screen.
|
|
@@ -48,8 +58,22 @@ export interface KeyboardSource {
|
|
|
48
58
|
* Android sends no Will events at all, so there it is the Did events. They arrive once the
|
|
49
59
|
* window's insets have changed, which is as the keyboard starts to move rather than once it has
|
|
50
60
|
* stopped, with a duration of zero: they say nothing of the motion.
|
|
61
|
+
*
|
|
62
|
+
* Both platforms report the keyboard's `screenY` from the top of the screen. iOS measures a view
|
|
63
|
+
* from there too. Android measures it from below the status bar when React Native's edge-to-edge
|
|
64
|
+
* flag is off, even in an app drawn under the bar, such as Expo Go, which leaves the flag off: its
|
|
65
|
+
* `measureInWindow` leaves out the bar's inset then. `windowTop` is that inset, zero when the flag
|
|
66
|
+
* is on, which a layout takes off `screenY` to compare the keyboard with a view it measured.
|
|
51
67
|
*/
|
|
52
68
|
export declare function keyboardSource(): KeyboardSource;
|
|
69
|
+
/**
|
|
70
|
+
* Require React Native's `Keyboard.js` now, so it records each show and hide from here on.
|
|
71
|
+
*
|
|
72
|
+
* It keeps the last one it heard, which `keyboardSource` starts from, but only from when it is
|
|
73
|
+
* first required. Left to the `Keyboard` service, that is when the first `text-input` appears, and
|
|
74
|
+
* a keyboard the native header's search bar opened before then reads as down until it next moves.
|
|
75
|
+
*/
|
|
76
|
+
export declare function recordKeyboard(): void;
|
|
53
77
|
/**
|
|
54
78
|
* A native view that reports the keyboard's motion frame by frame, for a view to follow it on the
|
|
55
79
|
* native side: a `<keyboard-dock>` on Android, where React Native says only where the keyboard
|
|
@@ -76,6 +100,8 @@ export declare class Keyboard {
|
|
|
76
100
|
*/
|
|
77
101
|
static readonly SOURCE: InjectionToken<KeyboardSource>;
|
|
78
102
|
private readonly source;
|
|
103
|
+
private readonly engine;
|
|
104
|
+
private readonly app;
|
|
79
105
|
private readonly current;
|
|
80
106
|
private readonly frame;
|
|
81
107
|
/**
|
|
@@ -91,10 +117,29 @@ export declare class Keyboard {
|
|
|
91
117
|
* move with it instead. Elsewhere it is `metrics`, and a layout animates to where that says.
|
|
92
118
|
*/
|
|
93
119
|
readonly followsMotion: boolean;
|
|
120
|
+
/**
|
|
121
|
+
* How far below the top of the screen the window `measureInWindow` reports in starts: the status
|
|
122
|
+
* bar's height on Android unless React Native's edge-to-edge flag is on, and zero otherwise. The
|
|
123
|
+
* keyboard's top edge in that window is `screenY` less this. It changes with a rotation, so read
|
|
124
|
+
* it when comparing rather than keeping it.
|
|
125
|
+
*
|
|
126
|
+
* On Android, read from where React Native measures the app's root, which is drawn from the top
|
|
127
|
+
* of the screen: React Native takes the bar off its measurements as it lays the root out, and keeps
|
|
128
|
+
* doing so when the bar is hidden or shown later, until the root is laid out again. The bar's
|
|
129
|
+
* own height stands in where the root has not been measured.
|
|
130
|
+
*/
|
|
131
|
+
get windowTop(): number;
|
|
94
132
|
/** Where the keyboard is now: at every frame of its motion where `followsMotion`. */
|
|
95
133
|
readonly position: Signal<KeyboardMetrics>;
|
|
96
134
|
constructor();
|
|
97
|
-
/**
|
|
135
|
+
/**
|
|
136
|
+
* Put the keyboard away, as tapping outside a field would: the focused text field is sent
|
|
137
|
+
* `blur`, as a scroll view does at such a tap. A focused view or button is left as it is.
|
|
138
|
+
*
|
|
139
|
+
* React Native's own `Keyboard.dismiss()`, which the source calls too, blurs only a field its
|
|
140
|
+
* `TextInput` component recorded in `TextInputState`. A `text-input` here is the native component
|
|
141
|
+
* with no `TextInput.js` around it, so nothing is recorded and that call alone blurs nothing.
|
|
142
|
+
*/
|
|
98
143
|
dismiss(): void;
|
|
99
144
|
static ɵfac: i0.ɵɵFactoryDeclaration<Keyboard, never>;
|
|
100
145
|
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|