@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.
Files changed (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +72 -1
  3. package/dist/accessibility.d.ts +60 -0
  4. package/dist/accessibility.js +101 -0
  5. package/dist/accessibility.js.map +1 -0
  6. package/dist/android-permissions.d.ts +31 -0
  7. package/dist/android-permissions.js +51 -0
  8. package/dist/android-permissions.js.map +1 -0
  9. package/dist/app-state.d.ts +27 -0
  10. package/dist/app-state.js +45 -0
  11. package/dist/app-state.js.map +1 -0
  12. package/dist/color-scheme.d.ts +33 -0
  13. package/dist/color-scheme.js +50 -0
  14. package/dist/color-scheme.js.map +1 -0
  15. package/dist/conditions.d.ts +48 -0
  16. package/dist/conditions.js +91 -0
  17. package/dist/conditions.js.map +1 -0
  18. package/dist/deep-links.d.ts +35 -0
  19. package/dist/deep-links.js +119 -0
  20. package/dist/deep-links.js.map +1 -0
  21. package/dist/dev-menu.d.ts +48 -0
  22. package/dist/dev-menu.js +52 -0
  23. package/dist/dev-menu.js.map +1 -0
  24. package/dist/dialogs.d.ts +111 -0
  25. package/dist/dialogs.js +186 -0
  26. package/dist/dialogs.js.map +1 -0
  27. package/dist/direction.d.ts +49 -0
  28. package/dist/direction.js +57 -0
  29. package/dist/direction.js.map +1 -0
  30. package/dist/hardware-back.d.ts +27 -0
  31. package/dist/hardware-back.js +41 -0
  32. package/dist/hardware-back.js.map +1 -0
  33. package/dist/index.d.ts +26 -0
  34. package/dist/index.js +27 -0
  35. package/dist/index.js.map +1 -0
  36. package/dist/keyboard.d.ts +67 -0
  37. package/dist/keyboard.js +103 -0
  38. package/dist/keyboard.js.map +1 -0
  39. package/dist/layout-animation.d.ts +54 -0
  40. package/dist/layout-animation.js +75 -0
  41. package/dist/layout-animation.js.map +1 -0
  42. package/dist/react-native.d.ts +176 -0
  43. package/dist/react-native.js +38 -0
  44. package/dist/react-native.js.map +1 -0
  45. package/dist/safe-area.d.ts +52 -0
  46. package/dist/safe-area.js +51 -0
  47. package/dist/safe-area.js.map +1 -0
  48. package/dist/screen-in-front.d.ts +10 -0
  49. package/dist/screen-in-front.js +14 -0
  50. package/dist/screen-in-front.js.map +1 -0
  51. package/dist/screen.d.ts +78 -0
  52. package/dist/screen.js +90 -0
  53. package/dist/screen.js.map +1 -0
  54. package/dist/sharing.d.ts +37 -0
  55. package/dist/sharing.js +61 -0
  56. package/dist/sharing.js.map +1 -0
  57. package/dist/status-bar.d.ts +69 -0
  58. package/dist/status-bar.js +101 -0
  59. package/dist/status-bar.js.map +1 -0
  60. package/dist/vibration.d.ts +38 -0
  61. package/dist/vibration.js +43 -0
  62. package/dist/vibration.js.map +1 -0
  63. package/package.json +59 -3
@@ -0,0 +1,186 @@
1
+ /**
2
+ * The platform's own dialogs: an alert, a confirmation, a prompt, an action sheet, a toast.
3
+ *
4
+ * All of these are callback APIs, and the reason to wrap them is that **a dialog is a question**.
5
+ * `Alert.alert` hands its answer to one of several `onPress` callbacks, so asking something and
6
+ * acting on the answer means splitting one thought across three functions. A promise puts it back
7
+ * together, and `await` at the call site reads like what it is.
8
+ *
9
+ * The platform split is the other half. An action sheet is iOS's way of offering a short list of
10
+ * choices and Android's is a dialog; a toast is Android's way of saying something small and iOS
11
+ * has none. `choose` and `notify` pick per platform, so an app writes the intent rather than the
12
+ * platform - and the one thing neither can do is fail silently on the platform it is not for.
13
+ */
14
+ import { InjectionToken, Service, inject } from '@angular/core';
15
+ import { reactNative } from "./react-native.js";
16
+ import * as i0 from "@angular/core";
17
+ /**
18
+ * `inject(Dialogs).confirm('Delete this?', { destructive: true })`.
19
+ *
20
+ * A dialog is a question, so every method here resolves to the answer rather than handing it to
21
+ * one of several callbacks.
22
+ */
23
+ export class Dialogs {
24
+ /** Overridden in a test to answer a dialog without one being shown. */
25
+ static SOURCE = new InjectionToken('angular-native.dialogSource', {
26
+ factory: () => dialogSource(reactNative()),
27
+ });
28
+ native = inject(Dialogs.SOURCE);
29
+ /** Say something, and wait until it has been read. Resolves when the dialog is dismissed. */
30
+ tell(title, message, dismiss = 'OK') {
31
+ return new Promise((resolve) => {
32
+ if (!this.native)
33
+ return resolve();
34
+ this.native.alert(title, message, [{ text: dismiss, onPress: () => resolve() }]);
35
+ });
36
+ }
37
+ /**
38
+ * Ask something with two answers. Resolves to whether they agreed.
39
+ *
40
+ * `destructive` paints the confirm button as the platform paints a delete, and puts cancel where
41
+ * the platform puts it - which on iOS is the *right*, so a confirmation dialog does not train
42
+ * people to tap the wrong thing.
43
+ */
44
+ confirm(title, options = {}) {
45
+ const { message, confirm = 'OK', cancel = 'Cancel', destructive = false } = options;
46
+ return new Promise((resolve) => {
47
+ if (!this.native)
48
+ return resolve(false);
49
+ this.native.alert(title, message, [
50
+ { text: cancel, style: 'cancel', onPress: () => resolve(false) },
51
+ {
52
+ text: confirm,
53
+ style: destructive ? 'destructive' : 'default',
54
+ onPress: () => resolve(true),
55
+ },
56
+ ]);
57
+ });
58
+ }
59
+ /**
60
+ * Ask for a line of text. Resolves to null if they cancelled.
61
+ *
62
+ * iOS only: `Alert.prompt` has no Android equivalent, and inventing one out of a modal and a
63
+ * text input would be a dialog that looks nothing like the platform's. On Android this resolves
64
+ * to null so a caller can fall back to a screen of its own.
65
+ */
66
+ ask(title, options = {}) {
67
+ return new Promise((resolve) => {
68
+ if (!this.native?.prompt)
69
+ return resolve(null);
70
+ this.native.prompt(title, options.message, resolve, options.value);
71
+ });
72
+ }
73
+ /**
74
+ * Offer a short list of choices. Resolves to the index chosen, or null if dismissed.
75
+ *
76
+ * An action sheet on iOS and a dialog on Android, because that is what each platform means by
77
+ * this. A `cancel` choice is where the platform puts cancel rather than in the list.
78
+ */
79
+ choose(title, choices) {
80
+ const cancelAt = choices.findIndex((choice) => choice.style === 'cancel');
81
+ const destructiveAt = choices.findIndex((choice) => choice.style === 'destructive');
82
+ return new Promise((resolve) => {
83
+ if (!this.native)
84
+ return resolve(null);
85
+ if (this.native.actionSheet) {
86
+ // iOS wants cancel last and named by index; a list with none gets one, because an action
87
+ // sheet with no way out is one the user has to guess at.
88
+ const labels = choices.map((choice) => choice.label);
89
+ const cancelIndex = cancelAt >= 0 ? cancelAt : labels.push('Cancel') - 1;
90
+ this.native.actionSheet({
91
+ title,
92
+ options: labels,
93
+ cancelButtonIndex: cancelIndex,
94
+ ...(destructiveAt >= 0 ? { destructiveButtonIndex: destructiveAt } : {}),
95
+ }, (index) => resolve(index === cancelIndex && cancelAt < 0 ? null : index));
96
+ return;
97
+ }
98
+ /*
99
+ * Android's alert is put up `cancelable: false` by React Native, so a press outside does
100
+ * nothing and neither does the back button. Without a cancel among the choices there is no
101
+ * way at all to decline - the user has to pick something - so one is appended, exactly as
102
+ * the iOS branch above does for the same reason.
103
+ *
104
+ * Android's dialog holds three buttons: a negative, a neutral and a positive. Anything past
105
+ * that is dropped by the platform without a word, and a choice the user cannot see is worse
106
+ * than a list that refused to open, so it says so.
107
+ */
108
+ const buttons = choices.map((choice, index) => ({
109
+ text: choice.label,
110
+ style: choice.style,
111
+ onPress: () => resolve(choice.style === 'cancel' ? null : index),
112
+ }));
113
+ if (cancelAt < 0) {
114
+ buttons.push({ text: 'Cancel', style: 'cancel', onPress: () => resolve(null) });
115
+ }
116
+ if (buttons.length > 3) {
117
+ console.error(`[angular-native] Dialogs.choose was given ${choices.length} choices and Android shows ` +
118
+ 'at most three buttons, counting the cancel. The rest will not appear. Use a ' +
119
+ '`ui-select` or an `action-sheet`-shaped list for anything longer.');
120
+ }
121
+ this.native.alert(title, undefined, buttons);
122
+ });
123
+ }
124
+ /**
125
+ * Say something small and transient.
126
+ *
127
+ * A toast on Android. iOS has no such thing and never has, so this does nothing there rather
128
+ * than putting up a modal alert for something that did not warrant interrupting anyone - and an
129
+ * app that must be seen should use `tell`.
130
+ */
131
+ notify(message, options = {}) {
132
+ this.native?.toast?.(message, options.long ?? false);
133
+ }
134
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: Dialogs, deps: [], target: i0.ɵɵFactoryTarget.Service });
135
+ static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.2.0", ngImport: i0, type: Dialogs });
136
+ }
137
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: Dialogs, decorators: [{
138
+ type: Service
139
+ }] });
140
+ /**
141
+ * The platform's dialogs, from React Native's own modules.
142
+ *
143
+ * `Alert.prompt` and `ActionSheetIOS` are iOS-only and `ToastAndroid` is Android-only; each is
144
+ * left absent rather than shimmed, which is what lets `ask`, `choose` and `notify` above decide
145
+ * what to do about it.
146
+ *
147
+ * Which platform it is has to be asked outright, because React Native's own modules do not answer
148
+ * it. `react-native` exports `ActionSheetIOS` on Android too - the object is there and so is
149
+ * `showActionSheetWithOptions`; only the TurboModule underneath is null, and the invariant that
150
+ * catches that throws out of the promise `choose` returns, so a press did nothing at all and said
151
+ * nothing about it. `Alert.prompt` is worse: it exists on Android and its body is one
152
+ * `Platform.OS === 'ios'` check, so it returns having called no callback and the promise `ask`
153
+ * returns never settles. `ToastAndroid` is the mirror image on iOS. Presence is not capability
154
+ * here; only the platform name is.
155
+ */
156
+ export function dialogSource(native) {
157
+ if (!native)
158
+ return null;
159
+ const ios = native.Platform.OS === 'ios';
160
+ const android = native.Platform.OS === 'android';
161
+ return {
162
+ platform: native.Platform.OS,
163
+ alert: (title, message, buttons) => native.Alert.alert(title, message, [...buttons]),
164
+ // Buttons rather than a callback: given a callback, `Alert.prompt` answers OK alone, and the
165
+ // Cancel the native alert adds calls nothing, so a cancelled `ask` never settled.
166
+ ...(ios && native.Alert.prompt
167
+ ? {
168
+ prompt: (title, message, onResult, defaultValue) => native.Alert.prompt(title, message, [
169
+ { text: 'Cancel', style: 'cancel', onPress: () => onResult(null) },
170
+ { text: 'OK', onPress: (value) => onResult(value ?? '') },
171
+ ], undefined, defaultValue),
172
+ }
173
+ : {}),
174
+ ...(ios && native.ActionSheetIOS
175
+ ? {
176
+ actionSheet: (options, onSelect) => native.ActionSheetIOS.showActionSheetWithOptions(options, onSelect),
177
+ }
178
+ : {}),
179
+ ...(android && native.ToastAndroid
180
+ ? {
181
+ toast: (message, long) => native.ToastAndroid.show(message, long ? native.ToastAndroid.LONG : native.ToastAndroid.SHORT),
182
+ }
183
+ : {}),
184
+ };
185
+ }
186
+ //# sourceMappingURL=dialogs.js.map
@@ -0,0 +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,CAAC,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACH,OAAO,CACL,KAA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;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 && cancelAt < 0 ? 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"]}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Which way round the world is: left to right, or right to left.
3
+ *
4
+ * The cascade already mirrors the *paint*. `direction: rtl` flips padding, text alignment and the
5
+ * order boxes are laid out in, and Yoga inherits that down the shadow tree without anyone asking,
6
+ * so a stylesheet needs nothing from this file.
7
+ *
8
+ * What the cascade cannot do is tell TypeScript which way round the world is, and this library
9
+ * computes position in TypeScript in several places: `anchor.ts` resolves an `align` of `start`
10
+ * against an edge, the slider maps a drag's x delta onto a value, and the drawer, the sheet and
11
+ * the sidebar all name an edge. Every one of those is a decision made before a style exists, so
12
+ * every one of them needs an answer here rather than in CSS. It is the same reason Angular's CDK
13
+ * ships `Directionality` rather than leaving direction to the stylesheet.
14
+ *
15
+ * A directive can override it for a subtree the way `[dir]` does, by providing a
16
+ * `DirectionContext` in `Direction`'s place.
17
+ */
18
+ import { InjectionToken, type Signal } from '@angular/core';
19
+ import * as i0 from "@angular/core";
20
+ export type LayoutDirection = 'ltr' | 'rtl';
21
+ export interface DirectionSource {
22
+ current(): LayoutDirection;
23
+ subscribe(listener: (direction: LayoutDirection) => void): () => void;
24
+ }
25
+ export declare function directionSource(): DirectionSource;
26
+ /**
27
+ * The read side of a direction, which is all a consumer ever wants.
28
+ *
29
+ * Named separately from the service because a subtree's direction is not the device's:
30
+ * a directive that overrides it for a subtree provides this in `Direction`'s place, exactly as
31
+ * CDK's `Dir` implements `Directionality`. Everything that injects `Direction` gets whichever is
32
+ * closest, and neither needs to know which it got.
33
+ */
34
+ export interface DirectionContext {
35
+ readonly current: Signal<LayoutDirection>;
36
+ readonly rtl: Signal<boolean>;
37
+ }
38
+ export declare class Direction implements DirectionContext {
39
+ /** Overridden in a test to flip the world, and by `mount` to read the document instead. */
40
+ static readonly SOURCE: InjectionToken<DirectionSource>;
41
+ private readonly source;
42
+ private readonly direction;
43
+ readonly current: Signal<LayoutDirection>;
44
+ /** The same fact as a boolean, because most callers branch on it rather than switch. */
45
+ readonly rtl: Signal<boolean>;
46
+ constructor();
47
+ static ɵfac: i0.ɵɵFactoryDeclaration<Direction, never>;
48
+ static ɵprov: i0.ɵɵInjectableDeclaration<any>;
49
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Which way round the world is: left to right, or right to left.
3
+ *
4
+ * The cascade already mirrors the *paint*. `direction: rtl` flips padding, text alignment and the
5
+ * order boxes are laid out in, and Yoga inherits that down the shadow tree without anyone asking,
6
+ * so a stylesheet needs nothing from this file.
7
+ *
8
+ * What the cascade cannot do is tell TypeScript which way round the world is, and this library
9
+ * computes position in TypeScript in several places: `anchor.ts` resolves an `align` of `start`
10
+ * against an edge, the slider maps a drag's x delta onto a value, and the drawer, the sheet and
11
+ * the sidebar all name an edge. Every one of those is a decision made before a style exists, so
12
+ * every one of them needs an answer here rather than in CSS. It is the same reason Angular's CDK
13
+ * ships `Directionality` rather than leaving direction to the stylesheet.
14
+ *
15
+ * A directive can override it for a subtree the way `[dir]` does, by providing a
16
+ * `DirectionContext` in `Direction`'s place.
17
+ */
18
+ import { DestroyRef, InjectionToken, Service, computed, inject, signal, } from '@angular/core';
19
+ import { reactNative } from "./react-native.js";
20
+ import * as i0 from "@angular/core";
21
+ export function directionSource() {
22
+ const native = reactNative();
23
+ if (!native)
24
+ return { current: () => 'ltr', subscribe: () => () => { } };
25
+ return {
26
+ current: () => (native.I18nManager.isRTL ? 'rtl' : 'ltr'),
27
+ // Nothing to subscribe to, and that is the platform rather than a gap here. React Native
28
+ // settles the direction while the native side starts up, from the device's own locale;
29
+ // `I18nManager.forceRTL` only takes effect after a restart, so `isRTL` cannot change under a
30
+ // running app. The listener stays in the shape because the browser source genuinely does have
31
+ // one - `document.dir` is a mutable attribute - and because a consumer should not have to know
32
+ // which platform it is on to read a signal.
33
+ subscribe: () => () => { },
34
+ };
35
+ }
36
+ export class Direction {
37
+ /** Overridden in a test to flip the world, and by `mount` to read the document instead. */
38
+ static SOURCE = new InjectionToken('angular-native.directionSource', {
39
+ factory: directionSource,
40
+ });
41
+ source = inject(Direction.SOURCE);
42
+ direction = signal(this.source.current(), /* @ts-ignore */
43
+ ...(ngDevMode ? [{ debugName: "direction" }] : /* istanbul ignore next */ []));
44
+ current = this.direction.asReadonly();
45
+ /** The same fact as a boolean, because most callers branch on it rather than switch. */
46
+ rtl = computed(() => this.direction() === 'rtl', /* @ts-ignore */
47
+ ...(ngDevMode ? [{ debugName: "rtl" }] : /* istanbul ignore next */ []));
48
+ constructor() {
49
+ inject(DestroyRef).onDestroy(this.source.subscribe((direction) => this.direction.set(direction)));
50
+ }
51
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: Direction, deps: [], target: i0.ɵɵFactoryTarget.Service });
52
+ static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.2.0", ngImport: i0, type: Direction });
53
+ }
54
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: Direction, decorators: [{
55
+ type: Service
56
+ }], ctorParameters: () => [] });
57
+ //# sourceMappingURL=direction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"direction.js","sourceRoot":"","sources":["../src/direction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;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;;AAShD,MAAM,UAAU,eAAe;IAC7B,MAAM,MAAM,GAAG,WAAW,EAAE,CAAC;IAC7B,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,GAAE,CAAC,EAAE,CAAC;IAExE,OAAO;QACL,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;QACzD,yFAAyF;QACzF,uFAAuF;QACvF,6FAA6F;QAC7F,8FAA8F;QAC9F,+FAA+F;QAC/F,4CAA4C;QAC5C,SAAS,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,GAAE,CAAC;KAC1B,CAAC;AACJ,CAAC;AAgBD,MAAM,OAAO,SAAS;IACpB,2FAA2F;IAC3F,MAAM,CAAU,MAAM,GAAG,IAAI,cAAc,CAAkB,gCAAgC,EAAE;QAC7F,OAAO,EAAE,eAAe;KACzB,CAAC,CAAC;IAEc,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAClC,SAAS,GAAG,MAAM,CAAkB,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE;kFAAC,CAAC;IAEnE,OAAO,GAA4B,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,CAAC;IAExE,wFAAwF;IAC/E,GAAG,GAAoB,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,KAAK;4EAAC,CAAC;IAE3E;QACE,MAAM,CAAC,UAAU,CAAC,CAAC,SAAS,CAC1B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CACpE,CAAC;IACJ,CAAC;uGAlBU,SAAS;wGAAT,SAAS;;2FAAT,SAAS;kBADrB,OAAO","sourcesContent":["/**\n * Which way round the world is: left to right, or right to left.\n *\n * The cascade already mirrors the *paint*. `direction: rtl` flips padding, text alignment and the\n * order boxes are laid out in, and Yoga inherits that down the shadow tree without anyone asking,\n * so a stylesheet needs nothing from this file.\n *\n * What the cascade cannot do is tell TypeScript which way round the world is, and this library\n * computes position in TypeScript in several places: `anchor.ts` resolves an `align` of `start`\n * against an edge, the slider maps a drag's x delta onto a value, and the drawer, the sheet and\n * the sidebar all name an edge. Every one of those is a decision made before a style exists, so\n * every one of them needs an answer here rather than in CSS. It is the same reason Angular's CDK\n * ships `Directionality` rather than leaving direction to the stylesheet.\n *\n * A directive can override it for a subtree the way `[dir]` does, by providing a\n * `DirectionContext` in `Direction`'s place.\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 type LayoutDirection = 'ltr' | 'rtl';\n\nexport interface DirectionSource {\n current(): LayoutDirection;\n subscribe(listener: (direction: LayoutDirection) => void): () => void;\n}\n\nexport function directionSource(): DirectionSource {\n const native = reactNative();\n if (!native) return { current: () => 'ltr', subscribe: () => () => {} };\n\n return {\n current: () => (native.I18nManager.isRTL ? 'rtl' : 'ltr'),\n // Nothing to subscribe to, and that is the platform rather than a gap here. React Native\n // settles the direction while the native side starts up, from the device's own locale;\n // `I18nManager.forceRTL` only takes effect after a restart, so `isRTL` cannot change under a\n // running app. The listener stays in the shape because the browser source genuinely does have\n // one - `document.dir` is a mutable attribute - and because a consumer should not have to know\n // which platform it is on to read a signal.\n subscribe: () => () => {},\n };\n}\n\n/**\n * The read side of a direction, which is all a consumer ever wants.\n *\n * Named separately from the service because a subtree's direction is not the device's:\n * a directive that overrides it for a subtree provides this in `Direction`'s place, exactly as\n * CDK's `Dir` implements `Directionality`. Everything that injects `Direction` gets whichever is\n * closest, and neither needs to know which it got.\n */\nexport interface DirectionContext {\n readonly current: Signal<LayoutDirection>;\n readonly rtl: Signal<boolean>;\n}\n\n@Service()\nexport class Direction implements DirectionContext {\n /** Overridden in a test to flip the world, and by `mount` to read the document instead. */\n static readonly SOURCE = new InjectionToken<DirectionSource>('angular-native.directionSource', {\n factory: directionSource,\n });\n\n private readonly source = inject(Direction.SOURCE);\n private readonly direction = signal<LayoutDirection>(this.source.current());\n\n readonly current: Signal<LayoutDirection> = this.direction.asReadonly();\n\n /** The same fact as a boolean, because most callers branch on it rather than switch. */\n readonly rtl: Signal<boolean> = computed(() => this.direction() === 'rtl');\n\n constructor() {\n inject(DestroyRef).onDestroy(\n this.source.subscribe((direction) => this.direction.set(direction)),\n );\n }\n}\n"]}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Android's hardware back button.
3
+ *
4
+ * Not a signal, because a press is a question rather than a state: the platform asks whether
5
+ * anybody wants it, and the answer decides what happens next. A handler returns whether it
6
+ * consumed the press, and returning false lets the platform do what it would have done - at the
7
+ * bottom of a navigation stack that means backgrounding the app rather than closing it, so a user
8
+ * who backs out of the first screen finds the app where they left it.
9
+ */
10
+ import { InjectionToken } from '@angular/core';
11
+ import * as i0 from "@angular/core";
12
+ export interface HardwareBackSource {
13
+ subscribe(listener: () => boolean): () => void;
14
+ }
15
+ export declare function hardwareBackSource(): HardwareBackSource;
16
+ export declare class HardwareBack {
17
+ /** Overridden in a test to press the button without a device. */
18
+ static readonly SOURCE: InjectionToken<HardwareBackSource>;
19
+ private readonly source;
20
+ /**
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. Returns an unsubscribe.
23
+ */
24
+ handle(handler: () => boolean): () => void;
25
+ static ɵfac: i0.ɵɵFactoryDeclaration<HardwareBack, never>;
26
+ static ɵprov: i0.ɵɵInjectableDeclaration<any>;
27
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Android's hardware back button.
3
+ *
4
+ * Not a signal, because a press is a question rather than a state: the platform asks whether
5
+ * anybody wants it, and the answer decides what happens next. A handler returns whether it
6
+ * consumed the press, and returning false lets the platform do what it would have done - at the
7
+ * bottom of a navigation stack that means backgrounding the app rather than closing it, so a user
8
+ * who backs out of the first screen finds the app where they left it.
9
+ */
10
+ import { InjectionToken, Service, inject } from '@angular/core';
11
+ import { reactNative } from "./react-native.js";
12
+ import * as i0 from "@angular/core";
13
+ export function hardwareBackSource() {
14
+ const native = reactNative();
15
+ if (!native)
16
+ return { subscribe: () => () => { } };
17
+ return {
18
+ subscribe: (listener) => {
19
+ const subscription = native.BackHandler.addEventListener('hardwareBackPress', listener);
20
+ return () => subscription.remove();
21
+ },
22
+ };
23
+ }
24
+ export class HardwareBack {
25
+ /** Overridden in a test to press the button without a device. */
26
+ static SOURCE = new InjectionToken('angular-native.hardwareBackSource', { factory: hardwareBackSource });
27
+ source = inject(HardwareBack.SOURCE);
28
+ /**
29
+ * 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. Returns an unsubscribe.
31
+ */
32
+ handle(handler) {
33
+ return this.source.subscribe(handler);
34
+ }
35
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: HardwareBack, deps: [], target: i0.ɵɵFactoryTarget.Service });
36
+ static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.2.0", ngImport: i0, type: HardwareBack });
37
+ }
38
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: HardwareBack, decorators: [{
39
+ type: Service
40
+ }] });
41
+ //# sourceMappingURL=hardware-back.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hardware-back.js","sourceRoot":"","sources":["../src/hardware-back.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;;AAMhD,MAAM,UAAU,kBAAkB;IAChC,MAAM,MAAM,GAAG,WAAW,EAAE,CAAC;IAC7B,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,GAAE,CAAC,EAAE,CAAC;IAElD,OAAO;QACL,SAAS,EAAE,CAAC,QAAQ,EAAE,EAAE;YACtB,MAAM,YAAY,GAAG,MAAM,CAAC,WAAW,CAAC,gBAAgB,CAAC,mBAAmB,EAAE,QAAQ,CAAC,CAAC;YACxF,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC;QACrC,CAAC;KACF,CAAC;AACJ,CAAC;AAGD,MAAM,OAAO,YAAY;IACvB,iEAAiE;IACjE,MAAM,CAAU,MAAM,GAAG,IAAI,cAAc,CACzC,mCAAmC,EACnC,EAAE,OAAO,EAAE,kBAAkB,EAAE,CAChC,CAAC;IAEe,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IAEtD;;;OAGG;IACH,MAAM,CAAC,OAAsB;QAC3B,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACxC,CAAC;uGAfU,YAAY;wGAAZ,YAAY;;2FAAZ,YAAY;kBADxB,OAAO","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 } from '@angular/core';\nimport { reactNative } from './react-native.ts';\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. Returns an unsubscribe.\n */\n handle(handler: () => boolean): () => void {\n return this.source.subscribe(handler);\n }\n}\n"]}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * The host: the device, the operating system, and the user's settings.
3
+ *
4
+ * Every capability here is a service with its own factory, so injecting one is the whole setup
5
+ * and one nobody injects is never constructed. Off a device each falls back to doing nothing,
6
+ * which is what makes the whole package importable by the test suite.
7
+ */
8
+ export { Accessibility, type AccessibilitySettings, type AccessibilitySource, } from './accessibility.ts';
9
+ export { AppState, type AppStateSource, type AppStatus } from './app-state.ts';
10
+ export { ColorScheme, type ColorSchemeSource, type Scheme } from './color-scheme.ts';
11
+ export { currentConditions, deviceTokens, watchConditions, type WatchOptions, } from './conditions.ts';
12
+ export { DeepLinks, pathOf, type DeepLinkSource } from './deep-links.ts';
13
+ export { Direction, type DirectionContext, type DirectionSource, type LayoutDirection, } from './direction.ts';
14
+ export { androidPermission, type AndroidPermissions, type PermissionAnswer, } from './android-permissions.ts';
15
+ export { DevMenu, type DevMenuSource, type NativeDevMenu } from './dev-menu.ts';
16
+ export { Dialogs, type Choice, type NativeDialogs } from './dialogs.ts';
17
+ export { LayoutAnimation, type LayoutChange, type LayoutEasing, type NativeLayoutAnimation, } from './layout-animation.ts';
18
+ export { Sharing, type NativeSharing, type ShareRequest } from './sharing.ts';
19
+ export { Vibration, type NativeVibration } from './vibration.ts';
20
+ export { HardwareBack, hardwareBackSource, type HardwareBackSource } from './hardware-back.ts';
21
+ export { Keyboard, type KeyboardMetrics, type KeyboardSource } from './keyboard.ts';
22
+ export { reactNative, type NativeKeyboardEvent, type ReactNative } from './react-native.ts';
23
+ export { SafeArea, type Frame, type Insets } from './safe-area.ts';
24
+ export { COMPACT_WIDTH, Screen, type ScreenSource, type Size, type Sizes } from './screen.ts';
25
+ export { StatusBar, statusBarSource, type StatusBarSource, type StatusBarState, type StatusBarStyle, } from './status-bar.ts';
26
+ export { SCREEN_IN_FRONT } from './screen-in-front.ts';
package/dist/index.js ADDED
@@ -0,0 +1,27 @@
1
+ /**
2
+ * The host: the device, the operating system, and the user's settings.
3
+ *
4
+ * Every capability here is a service with its own factory, so injecting one is the whole setup
5
+ * and one nobody injects is never constructed. Off a device each falls back to doing nothing,
6
+ * which is what makes the whole package importable by the test suite.
7
+ */
8
+ export { Accessibility, } from "./accessibility.js";
9
+ export { AppState } from "./app-state.js";
10
+ export { ColorScheme } from "./color-scheme.js";
11
+ export { currentConditions, deviceTokens, watchConditions, } from "./conditions.js";
12
+ export { DeepLinks, pathOf } from "./deep-links.js";
13
+ export { Direction, } from "./direction.js";
14
+ export { androidPermission, } from "./android-permissions.js";
15
+ export { DevMenu } from "./dev-menu.js";
16
+ export { Dialogs } from "./dialogs.js";
17
+ export { LayoutAnimation, } from "./layout-animation.js";
18
+ export { Sharing } from "./sharing.js";
19
+ export { Vibration } from "./vibration.js";
20
+ export { HardwareBack, hardwareBackSource } from "./hardware-back.js";
21
+ export { Keyboard } from "./keyboard.js";
22
+ export { reactNative } from "./react-native.js";
23
+ export { SafeArea } from "./safe-area.js";
24
+ export { COMPACT_WIDTH, Screen } from "./screen.js";
25
+ export { StatusBar, statusBarSource, } from "./status-bar.js";
26
+ export { SCREEN_IN_FRONT } from "./screen-in-front.js";
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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,MAAM,EAAuB,MAAM,iBAAiB,CAAC;AACzE,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,EAAE,QAAQ,EAA6C,MAAM,eAAe,CAAC;AACpF,OAAO,EAAE,WAAW,EAA8C,MAAM,mBAAmB,CAAC;AAC5F,OAAO,EAAE,QAAQ,EAA2B,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,EAA4C,MAAM,aAAa,CAAC;AAC9F,OAAO,EACL,SAAS,EACT,eAAe,GAIhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,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, 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 { Keyboard, type KeyboardMetrics, type KeyboardSource } from './keyboard.ts';\nexport { reactNative, type NativeKeyboardEvent, type ReactNative } 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 StatusBarSource,\n type StatusBarState,\n type StatusBarStyle,\n} from './status-bar.ts';\nexport { SCREEN_IN_FRONT } from './screen-in-front.ts';\n"]}
@@ -0,0 +1,67 @@
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 { InjectionToken, type Signal } from '@angular/core';
8
+ import * as i0 from "@angular/core";
9
+ /** What the platform reports when the keyboard moves. */
10
+ export interface KeyboardMetrics {
11
+ /** Height in dp; zero when the keyboard is hidden. */
12
+ readonly height: number;
13
+ /** Where its top edge is, from the top of the screen. Absent when hidden. */
14
+ readonly screenY?: number;
15
+ /** How long its own animation takes, in ms, for anything moving with it. */
16
+ readonly duration?: number;
17
+ /**
18
+ * The curve its own animation runs on, for anything moving with it to match: one of
19
+ * `LayoutEasing`'s names. On iOS that is usually `'keyboard'`, the keyboard's own curve. On
20
+ * Android it is always `'keyboard'` paired with a duration of zero: the platform animates its
21
+ * own keyboard, the event arrives once it has, and nothing here should try to animate alongside
22
+ * it.
23
+ */
24
+ readonly easing?: string;
25
+ }
26
+ /** Where the metrics come from. A fake stands in for the platform in tests. */
27
+ export interface KeyboardSource {
28
+ subscribe(listener: (metrics: KeyboardMetrics) => void): () => void;
29
+ dismiss(): void;
30
+ }
31
+ /**
32
+ * The events RN's own KeyboardAvoidingView listens for, which differ by platform.
33
+ *
34
+ * On iOS the Will events: they arrive as the keyboard starts to move, carrying its duration and
35
+ * curve, so a layout configured from them moves with the keyboard. The Did events arrive once it
36
+ * has landed, and a layout that waits for them moves after it. `keyboardWillChangeFrame` covers a
37
+ * keyboard that changes size while it is up - the predictive bar, another language's layout - and
38
+ * is ignored while it is down: UIKit posts one beside every show and hide as well, and the one
39
+ * beside a hide is the frame the keyboard leaves by, off the bottom of the screen.
40
+ *
41
+ * Android sends no Will events at all, so there it is the Did events, which arrive with a
42
+ * duration of zero because the platform animates its own keyboard.
43
+ */
44
+ export declare function keyboardSource(): KeyboardSource;
45
+ /**
46
+ * Subscribed for the life of the app, which is the life of the service, and removed when the app
47
+ * is destroyed. A component that mounts mid-gesture wants the height that is already true rather
48
+ * than the next change, which is why the subscription is the service's and not the component's.
49
+ */
50
+ export declare class Keyboard {
51
+ /**
52
+ * Where the metrics actually come from. Overriding this token is how a test drives the keyboard,
53
+ * and it is finer than replacing the service: the code under test stays the real thing.
54
+ */
55
+ static readonly SOURCE: InjectionToken<KeyboardSource>;
56
+ private readonly source;
57
+ private readonly current;
58
+ /** Everything the platform said, for a layout that needs the animation duration too. */
59
+ readonly metrics: Signal<KeyboardMetrics>;
60
+ readonly height: Signal<number>;
61
+ readonly visible: Signal<boolean>;
62
+ constructor();
63
+ /** Put the keyboard away, as tapping outside a field would. */
64
+ dismiss(): void;
65
+ static ɵfac: i0.ɵɵFactoryDeclaration<Keyboard, never>;
66
+ static ɵprov: i0.ɵɵInjectableDeclaration<any>;
67
+ }