@ng-native/device 0.8.0 → 0.10.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/dialogs.js +1 -1
- package/dist/dialogs.js.map +1 -1
- package/dist/status-bar.d.ts +8 -3
- package/dist/status-bar.js +21 -9
- package/dist/status-bar.js.map +1 -1
- package/package.json +2 -2
package/dist/dialogs.js
CHANGED
|
@@ -92,7 +92,7 @@ export class Dialogs {
|
|
|
92
92
|
options: labels,
|
|
93
93
|
cancelButtonIndex: cancelIndex,
|
|
94
94
|
...(destructiveAt >= 0 ? { destructiveButtonIndex: destructiveAt } : {}),
|
|
95
|
-
}, (index) => resolve(index === cancelIndex
|
|
95
|
+
}, (index) => resolve(index === cancelIndex ? null : index));
|
|
96
96
|
return;
|
|
97
97
|
}
|
|
98
98
|
/*
|
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,CAA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AAC,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 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"]}
|
|
1
|
+
{"version":3,"file":"dialogs.js","sourceRoot":"","sources":["../src/dialogs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,cAAc,EAAE,OA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AE,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;oBAClE,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,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 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"]}
|
package/dist/status-bar.d.ts
CHANGED
|
@@ -65,14 +65,19 @@ export declare class StatusBar {
|
|
|
65
65
|
set(state: StatusBarState): void;
|
|
66
66
|
/** A claim on top of whatever is there. Call the returned function to drop it. */
|
|
67
67
|
push(state: StatusBarState): () => void;
|
|
68
|
+
/** The properties a claim has had the platform change, which no claim names any more. */
|
|
69
|
+
private readonly changed;
|
|
68
70
|
/**
|
|
69
71
|
* Push the merged state at the platform.
|
|
70
72
|
*
|
|
71
|
-
* Written whole rather than diffed: the platform's own setters are the cheap part
|
|
72
|
-
*
|
|
73
|
-
*
|
|
73
|
+
* Written whole rather than diffed: the platform's own setters are the cheap part. A property
|
|
74
|
+
* the last claim to name it has dropped goes back to the platform's own, once. Not the
|
|
75
|
+
* background color, whose own the theme decides. Read untracked, so an effect that sets the bar
|
|
76
|
+
* does not also subscribe to it and run again on every later claim.
|
|
74
77
|
*/
|
|
75
78
|
private apply;
|
|
79
|
+
/** Whether to tell the platform: a claim names `property`, or the last one to has dropped. */
|
|
80
|
+
private changes;
|
|
76
81
|
static ɵfac: i0.ɵɵFactoryDeclaration<StatusBar, never>;
|
|
77
82
|
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
78
83
|
}
|
package/dist/status-bar.js
CHANGED
|
@@ -88,24 +88,36 @@ export class StatusBar {
|
|
|
88
88
|
this.apply();
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
|
+
/** The properties a claim has had the platform change, which no claim names any more. */
|
|
92
|
+
changed = new Set();
|
|
91
93
|
/**
|
|
92
94
|
* Push the merged state at the platform.
|
|
93
95
|
*
|
|
94
|
-
* Written whole rather than diffed: the platform's own setters are the cheap part
|
|
95
|
-
*
|
|
96
|
-
*
|
|
96
|
+
* Written whole rather than diffed: the platform's own setters are the cheap part. A property
|
|
97
|
+
* the last claim to name it has dropped goes back to the platform's own, once. Not the
|
|
98
|
+
* background color, whose own the theme decides. Read untracked, so an effect that sets the bar
|
|
99
|
+
* does not also subscribe to it and run again on every later claim.
|
|
97
100
|
*/
|
|
98
101
|
apply() {
|
|
99
102
|
const { style, hidden, animated, backgroundColor, translucent } = untracked(this.state);
|
|
100
|
-
if (style
|
|
101
|
-
this.source.setStyle(resolve(style, untracked(this.scheme.current)), animated);
|
|
103
|
+
if (this.changes('style', style)) {
|
|
104
|
+
this.source.setStyle(resolve(style ?? 'default', untracked(this.scheme.current)), animated);
|
|
105
|
+
}
|
|
106
|
+
if (this.changes('hidden', hidden)) {
|
|
107
|
+
this.source.setHidden(hidden ?? false, animated ? 'fade' : undefined);
|
|
102
108
|
}
|
|
103
|
-
if (hidden !== undefined)
|
|
104
|
-
this.source.setHidden(hidden, animated ? 'fade' : undefined);
|
|
105
109
|
if (backgroundColor !== undefined)
|
|
106
110
|
this.source.setBackgroundColor(backgroundColor, animated);
|
|
107
|
-
if (translucent
|
|
108
|
-
this.source.setTranslucent(translucent);
|
|
111
|
+
if (this.changes('translucent', translucent)) {
|
|
112
|
+
this.source.setTranslucent(translucent ?? false);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/** Whether to tell the platform: a claim names `property`, or the last one to has dropped. */
|
|
116
|
+
changes(property, value) {
|
|
117
|
+
if (value === undefined)
|
|
118
|
+
return this.changed.delete(property);
|
|
119
|
+
this.changed.add(property);
|
|
120
|
+
return true;
|
|
109
121
|
}
|
|
110
122
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: StatusBar, deps: [], target: i0.ɵɵFactoryTarget.Service });
|
|
111
123
|
static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.2.0", ngImport: i0, type: StatusBar });
|
package/dist/status-bar.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"status-bar.js","sourceRoot":"","sources":["../src/status-bar.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EACL,UAAU,EACV,cAAc,EACd,OAAO,EACP,QAAQ,EACR,MAAM,EACN,MAAM,EACN,SAAS,GAEV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,WAAW,EAAe,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;;AAiChD,+FAA+F;AAC/F,MAAM,UAAU,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,cAAc,EAAW,CAAC;AAEjG,MAAM,UAAU,eAAe;IAC7B,MAAM,MAAM,GAAG,WAAW,EAAE,CAAC;IAC7B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO;YACL,QAAQ,EAAE,GAAG,EAAE,GAAE,CAAC;YAClB,SAAS,EAAE,GAAG,EAAE,GAAE,CAAC;YACnB,kBAAkB,EAAE,GAAG,EAAE,GAAE,CAAC;YAC5B,cAAc,EAAE,GAAG,EAAE,GAAE,CAAC;YACxB,MAAM,EAAE,SAAS;SAClB,CAAC;IACJ,CAAC;IAED,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;IAC7B,OAAO;QACL,QAAQ,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,CAAC,SAAS,CAAC,WAAW,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC;QACjF,SAAS,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC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,CAAC,OAAO,CAAC,KAAK,EAAE,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;QACjF,CAAC;QACD,IAAI,MAAM,KAAK,SAAS;YAAE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QACvF,IAAI,eAAe,KAAK,SAAS;YAAE,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC;QAC7F,IAAI,WAAW,KAAK,SAAS;YAAE,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;IACzE,CAAC;uGAjEU,SAAS;wGAAT,SAAS;;2FAAT,SAAS;kBADrB,OAAO;;AAqER,sFAAsF;AACtF,SAAS,OAAO,CAAC,KAAqB,EAAE,MAAc;IACpD,IAAI,KAAK,KAAK,MAAM;QAAE,OAAO,KAAK,CAAC;IACnC,OAAO,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;AAC9C,CAAC","sourcesContent":["/**\n * The status bar: what colour its text is, whether it is there at all, and how tall it is.\n *\n * React Native only offers this as a component. `<StatusBar />` applies its style by *rendering*,\n * and does it through a stack of entries so that a screen pushed on top can change the bar and\n * the screen underneath gets its own back when that one leaves. None of the rendering survives\n * without React - but the statics underneath do, and the stack is exactly what a navigation-driven\n * app needs, so it is the part worth keeping.\n *\n * `expo-status-bar` is the same statics with a React component around them, so nothing here needs\n * that package installed.\n */\nimport {\n DestroyRef,\n InjectionToken,\n Service,\n computed,\n inject,\n signal,\n untracked,\n type Signal,\n} from '@angular/core';\nimport { ColorScheme, type Scheme } from './color-scheme.ts';\nimport { reactNative } from './react-native.ts';\n\n/**\n * Dark text for a light bar, light text for a dark one. `default` is whatever the OS picks, which on\n * Android is light text whatever the scheme. `auto` is dark text in the light color scheme and\n * light text in the dark one, and follows `ColorScheme`, an in-app theme switch included.\n */\nexport type StatusBarStyle = 'default' | 'light' | 'dark' | 'auto';\n\n/** A style the platform takes: `auto` is resolved against the color scheme before it gets there. */\nexport type PlatformStatusBarStyle = Exclude<StatusBarStyle, 'auto'>;\n\n/** What a claim asks for. Anything absent is left as whatever the claim underneath said. */\nexport interface StatusBarState {\n readonly style?: StatusBarStyle;\n readonly hidden?: boolean;\n readonly animated?: boolean;\n /** Android only: the bar's own background. iOS has no such thing. */\n readonly backgroundColor?: string;\n /** Android only: whether content draws underneath the bar. */\n readonly translucent?: boolean;\n}\n\n/** Where the bar actually is. A fake stands in for the platform in tests. */\nexport interface StatusBarSource {\n setStyle(style: PlatformStatusBarStyle, animated?: boolean): void;\n setHidden(hidden: boolean, animation?: 'none' | 'fade' | 'slide'): void;\n setBackgroundColor(color: string, animated?: boolean): void;\n setTranslucent(translucent: boolean): void;\n /** Android reports one; iOS does not, where the safe-area inset is the number that matters. */\n readonly height: number | undefined;\n}\n\n/** RN spells the styles for its own platforms; `light` means light *content*, as CSS would. */\nconst BAR_STYLES = { default: 'default', light: 'light-content', dark: 'dark-content' } as const;\n\nexport function statusBarSource(): StatusBarSource {\n const native = reactNative();\n if (!native) {\n return {\n setStyle: () => {},\n setHidden: () => {},\n setBackgroundColor: () => {},\n setTranslucent: () => {},\n height: undefined,\n };\n }\n\n const { StatusBar } = native;\n return {\n setStyle: (style, animated) => StatusBar.setBarStyle(BAR_STYLES[style], animated),\n setHidden: (hidden, animation) => StatusBar.setHidden(hidden, animation),\n setBackgroundColor: (color, animated) => StatusBar.setBackgroundColor(color, animated),\n setTranslucent: (translucent) => StatusBar.setTranslucent(translucent),\n get height() {\n return StatusBar.currentHeight;\n },\n };\n}\n\n/**\n * A stack, not a setter.\n *\n * A modal that makes the bar light has to put back whatever the screen behind it asked for when\n * it is dismissed, and nothing else in an app remembers what that was. `push` returns the\n * function that drops the claim, so a screen can hand it straight to `DestroyRef.onDestroy`.\n */\n@Service()\nexport class StatusBar {\n /** Overridden in a test to watch the bar without one on screen. */\n static readonly SOURCE = new InjectionToken<StatusBarSource>('angular-native.statusBarSource', {\n factory: statusBarSource,\n });\n\n private readonly source = inject(StatusBar.SOURCE);\n private readonly scheme = inject(ColorScheme);\n private readonly stack = signal<readonly StatusBarState[]>([{}]);\n\n /** What is actually showing: every claim in order, later ones winning per property. */\n readonly state: Signal<StatusBarState> = computed(() =>\n this.stack().reduce((merged, entry) => ({ ...merged, ...entry }), {}),\n );\n\n /**\n * How tall it is, in points. Android reports it; iOS does not, and on iOS the number a layout\n * wants is the safe-area top inset, which `SafeArea` has.\n */\n readonly height: Signal<number> = signal(this.source.height ?? 0).asReadonly();\n\n constructor() {\n // Straight from the source rather than through an effect, so an `auto` bar changes in the same\n // turn as the scheme. The scheme is the listener's own: `ColorScheme.current` may not have\n // heard yet.\n const stop = inject(ColorScheme.SOURCE).subscribe((scheme) => {\n const { style, animated } = untracked(this.state);\n if (style === 'auto') this.source.setStyle(resolve(style, scheme), animated);\n });\n inject(DestroyRef).onDestroy(stop);\n }\n\n /** The base claim, for an app that sets the bar once at startup. */\n set(state: StatusBarState): void {\n this.stack.update((entries) => [state, ...entries.slice(1)]);\n this.apply();\n }\n\n /** A claim on top of whatever is there. Call the returned function to drop it. */\n push(state: StatusBarState): () => void {\n const entry = { ...state };\n this.stack.update((entries) => [...entries, entry]);\n this.apply();\n\n return () => {\n this.stack.update((entries) => entries.filter((one) => one !== entry));\n this.apply();\n };\n }\n\n /**\n * Push the merged state at the platform.\n *\n * Written whole rather than diffed: the platform's own setters are the cheap part, and a diff\n * would have to know which properties a *dropped* claim had been holding. Read untracked, so an\n * effect that sets the bar does not also subscribe to it and run again on every later claim.\n */\n private apply(): void {\n const { style, hidden, animated, backgroundColor, translucent } = untracked(this.state);\n if (style !== undefined) {\n this.source.setStyle(resolve(style, untracked(this.scheme.current)), animated);\n }\n if (hidden !== undefined) this.source.setHidden(hidden, animated ? 'fade' : undefined);\n if (backgroundColor !== undefined) this.source.setBackgroundColor(backgroundColor, animated);\n if (translucent !== undefined) this.source.setTranslucent(translucent);\n }\n}\n\n/** Dark text on the light scheme's light background, light text on the dark one's. */\nfunction resolve(style: StatusBarStyle, scheme: Scheme): PlatformStatusBarStyle {\n if (style !== 'auto') return style;\n return scheme === 'dark' ? 'light' : 'dark';\n}\n"]}
|
|
1
|
+
{"version":3,"file":"status-bar.js","sourceRoot":"","sources":["../src/status-bar.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EACL,UAAU,EACV,cAAc,EACd,OAAO,EACP,QAAQ,EACR,MAAM,EACN,MAAM,EACN,SAAS,GAEV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,WAAW,EAAe,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;;AAiChD,+FAA+F;AAC/F,MAAM,UAAU,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,cAAc,EAAW,CAAC;AAEjG,MAAM,UAAU,eAAe;IAC7B,MAAM,MAAM,GAAG,WAAW,EAAE,CAAC;IAC7B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO;YACL,QAAQ,EAAE,GAAG,EAAE,GAAE,CAAC;YAClB,SAAS,EAAE,GAAG,EAAE,GAAE,CAAC;YACnB,kBAAkB,EAAE,GAAG,EAAE,GAAE,CAAC;YAC5B,cAAc,EAAE,GAAG,EAAE,GAAE,CAAC;YACxB,MAAM,EAAE,SAAS;SAClB,CAAC;IACJ,CAAC;IAED,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;IAC7B,OAAO;QACL,QAAQ,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,CAAC,SAAS,CAAC,WAAW,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC;QACjF,SAAS,EAAE,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AAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;AAC9C,CAAC","sourcesContent":["/**\n * The status bar: what colour its text is, whether it is there at all, and how tall it is.\n *\n * React Native only offers this as a component. `<StatusBar />` applies its style by *rendering*,\n * and does it through a stack of entries so that a screen pushed on top can change the bar and\n * the screen underneath gets its own back when that one leaves. None of the rendering survives\n * without React - but the statics underneath do, and the stack is exactly what a navigation-driven\n * app needs, so it is the part worth keeping.\n *\n * `expo-status-bar` is the same statics with a React component around them, so nothing here needs\n * that package installed.\n */\nimport {\n DestroyRef,\n InjectionToken,\n Service,\n computed,\n inject,\n signal,\n untracked,\n type Signal,\n} from '@angular/core';\nimport { ColorScheme, type Scheme } from './color-scheme.ts';\nimport { reactNative } from './react-native.ts';\n\n/**\n * Dark text for a light bar, light text for a dark one. `default` is whatever the OS picks, which on\n * Android is light text whatever the scheme. `auto` is dark text in the light color scheme and\n * light text in the dark one, and follows `ColorScheme`, an in-app theme switch included.\n */\nexport type StatusBarStyle = 'default' | 'light' | 'dark' | 'auto';\n\n/** A style the platform takes: `auto` is resolved against the color scheme before it gets there. */\nexport type PlatformStatusBarStyle = Exclude<StatusBarStyle, 'auto'>;\n\n/** What a claim asks for. Anything absent is left as whatever the claim underneath said. */\nexport interface StatusBarState {\n readonly style?: StatusBarStyle;\n readonly hidden?: boolean;\n readonly animated?: boolean;\n /** Android only: the bar's own background. iOS has no such thing. */\n readonly backgroundColor?: string;\n /** Android only: whether content draws underneath the bar. */\n readonly translucent?: boolean;\n}\n\n/** Where the bar actually is. A fake stands in for the platform in tests. */\nexport interface StatusBarSource {\n setStyle(style: PlatformStatusBarStyle, animated?: boolean): void;\n setHidden(hidden: boolean, animation?: 'none' | 'fade' | 'slide'): void;\n setBackgroundColor(color: string, animated?: boolean): void;\n setTranslucent(translucent: boolean): void;\n /** Android reports one; iOS does not, where the safe-area inset is the number that matters. */\n readonly height: number | undefined;\n}\n\n/** RN spells the styles for its own platforms; `light` means light *content*, as CSS would. */\nconst BAR_STYLES = { default: 'default', light: 'light-content', dark: 'dark-content' } as const;\n\nexport function statusBarSource(): StatusBarSource {\n const native = reactNative();\n if (!native) {\n return {\n setStyle: () => {},\n setHidden: () => {},\n setBackgroundColor: () => {},\n setTranslucent: () => {},\n height: undefined,\n };\n }\n\n const { StatusBar } = native;\n return {\n setStyle: (style, animated) => StatusBar.setBarStyle(BAR_STYLES[style], animated),\n setHidden: (hidden, animation) => StatusBar.setHidden(hidden, animation),\n setBackgroundColor: (color, animated) => StatusBar.setBackgroundColor(color, animated),\n setTranslucent: (translucent) => StatusBar.setTranslucent(translucent),\n get height() {\n return StatusBar.currentHeight;\n },\n };\n}\n\n/**\n * A stack, not a setter.\n *\n * A modal that makes the bar light has to put back whatever the screen behind it asked for when\n * it is dismissed, and nothing else in an app remembers what that was. `push` returns the\n * function that drops the claim, so a screen can hand it straight to `DestroyRef.onDestroy`.\n */\n@Service()\nexport class StatusBar {\n /** Overridden in a test to watch the bar without one on screen. */\n static readonly SOURCE = new InjectionToken<StatusBarSource>('angular-native.statusBarSource', {\n factory: statusBarSource,\n });\n\n private readonly source = inject(StatusBar.SOURCE);\n private readonly scheme = inject(ColorScheme);\n private readonly stack = signal<readonly StatusBarState[]>([{}]);\n\n /** What is actually showing: every claim in order, later ones winning per property. */\n readonly state: Signal<StatusBarState> = computed(() =>\n this.stack().reduce((merged, entry) => ({ ...merged, ...entry }), {}),\n );\n\n /**\n * How tall it is, in points. Android reports it; iOS does not, and on iOS the number a layout\n * wants is the safe-area top inset, which `SafeArea` has.\n */\n readonly height: Signal<number> = signal(this.source.height ?? 0).asReadonly();\n\n constructor() {\n // Straight from the source rather than through an effect, so an `auto` bar changes in the same\n // turn as the scheme. The scheme is the listener's own: `ColorScheme.current` may not have\n // heard yet.\n const stop = inject(ColorScheme.SOURCE).subscribe((scheme) => {\n const { style, animated } = untracked(this.state);\n if (style === 'auto') this.source.setStyle(resolve(style, scheme), animated);\n });\n inject(DestroyRef).onDestroy(stop);\n }\n\n /** The base claim, for an app that sets the bar once at startup. */\n set(state: StatusBarState): void {\n this.stack.update((entries) => [state, ...entries.slice(1)]);\n this.apply();\n }\n\n /** A claim on top of whatever is there. Call the returned function to drop it. */\n push(state: StatusBarState): () => void {\n const entry = { ...state };\n this.stack.update((entries) => [...entries, entry]);\n this.apply();\n\n return () => {\n this.stack.update((entries) => entries.filter((one) => one !== entry));\n this.apply();\n };\n }\n\n /** The properties a claim has had the platform change, which no claim names any more. */\n private readonly changed = new Set<'style' | 'hidden' | 'translucent'>();\n\n /**\n * Push the merged state at the platform.\n *\n * Written whole rather than diffed: the platform's own setters are the cheap part. A property\n * the last claim to name it has dropped goes back to the platform's own, once. Not the\n * background color, whose own the theme decides. Read untracked, so an effect that sets the bar\n * does not also subscribe to it and run again on every later claim.\n */\n private apply(): void {\n const { style, hidden, animated, backgroundColor, translucent } = untracked(this.state);\n if (this.changes('style', style)) {\n this.source.setStyle(resolve(style ?? 'default', untracked(this.scheme.current)), animated);\n }\n if (this.changes('hidden', hidden)) {\n this.source.setHidden(hidden ?? false, animated ? 'fade' : undefined);\n }\n if (backgroundColor !== undefined) this.source.setBackgroundColor(backgroundColor, animated);\n if (this.changes('translucent', translucent)) {\n this.source.setTranslucent(translucent ?? false);\n }\n }\n\n /** Whether to tell the platform: a claim names `property`, or the last one to has dropped. */\n private changes(property: 'style' | 'hidden' | 'translucent', value: unknown): boolean {\n if (value === undefined) return this.changed.delete(property);\n this.changed.add(property);\n return true;\n }\n}\n\n/** Dark text on the light scheme's light background, light text on the dark one's. */\nfunction resolve(style: StatusBarStyle, scheme: Scheme): PlatformStatusBarStyle {\n if (style !== 'auto') return style;\n return scheme === 'dark' ? 'light' : 'dark';\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ng-native/device",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Angular Native device services: keyboard, screen, color scheme, app state, accessibility, hardware back and deep links.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"angular",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"type": "module",
|
|
18
18
|
"main": "dist/index.js",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@ng-native/fabric": "0.
|
|
20
|
+
"@ng-native/fabric": "0.10.0"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"@angular/core": "^22.0.0",
|