@ng-native/device 0.17.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,7 +13,7 @@
13
13
  import { DestroyRef, InjectionToken, Service, computed, inject, signal, untracked, } from '@angular/core';
14
14
  import { ColorScheme } from "./color-scheme.js";
15
15
  import { mergeClaims } from "./merge-claims.js";
16
- import { reactNative } from "./react-native.js";
16
+ import { edgeToEdgeFlag, reactNative } from "./react-native.js";
17
17
  import { WindowClaims, onWindowFront, sharedBySource } from "./window-claims.js";
18
18
  import * as i0 from "@angular/core";
19
19
  /** RN spells the styles for its own platforms; `light` means light *content*, as CSS would. */
@@ -28,9 +28,10 @@ const NONE = {
28
28
  /** One per React Native, so every app the runtime mounts claims the same bar. */
29
29
  export function statusBarSource() {
30
30
  const native = reactNative();
31
+ // A copy: with no bar to share, each app claims its own.
31
32
  if (!native)
32
- return NONE;
33
- return sharedBySource(native, () => nativeSource(native));
33
+ return { ...NONE };
34
+ return sharedBySource(statusBarSource, native, () => nativeSource(native));
34
35
  }
35
36
  function nativeSource(native) {
36
37
  const { StatusBar } = native;
@@ -38,9 +39,9 @@ function nativeSource(native) {
38
39
  // Android 16 draws an app targeting SDK 35 or later edge-to-edge whatever its theme says. Before
39
40
  // it, a theme can opt out, and React Native's own answer is the flag its status bar module
40
41
  // checks. That answer is not enough on its own: Expo Go on Android 16 reports false.
41
- const info = native.TurboModuleRegistry?.get('DeviceInfo');
42
- const edgeToEdge = android &&
43
- (Number(native.Platform.Version) >= 36 || info?.getConstants?.().isEdgeToEdge === true);
42
+ // React Native 0.88 draws every Android app edge-to-edge, and removed both setters with it.
43
+ const settable = typeof StatusBar.setBackgroundColor === 'function';
44
+ const edgeToEdge = android && (!settable || Number(native.Platform.Version) >= 36 || edgeToEdgeFlag(native));
44
45
  const warned = new Set();
45
46
  return {
46
47
  setStyle: (style, animated) => StatusBar.setBarStyle(BAR_STYLES[style], animated),
@@ -50,14 +51,14 @@ function nativeSource(native) {
50
51
  return;
51
52
  if (edgeToEdge)
52
53
  warnNoEffect('backgroundColor', warned);
53
- StatusBar.setBackgroundColor(color, animated);
54
+ StatusBar.setBackgroundColor?.(color, animated);
54
55
  },
55
56
  setTranslucent: (translucent) => {
56
57
  if (!android)
57
58
  return;
58
59
  if (edgeToEdge)
59
60
  warnNoEffect('translucent', warned);
60
- StatusBar.setTranslucent(translucent);
61
+ StatusBar.setTranslucent?.(translucent);
61
62
  },
62
63
  get height() {
63
64
  return StatusBar.currentHeight;
@@ -95,7 +96,7 @@ export class StatusBar {
95
96
  /** This app, among the apps claiming the bar: its scheme is what an `auto` style it claims follows. */
96
97
  owner = { scheme: inject(ColorScheme) };
97
98
  /** Every app's claims on this bar: the window is the runtime's, not an app's. */
98
- window = sharedBySource(this.source, () => new StatusBarWindow(this.source));
99
+ window = sharedBySource(StatusBarWindow, this.source, () => new StatusBarWindow(this.source));
99
100
  /** What is actually showing: every claim in order, later ones winning per property. */
100
101
  state = this.window.state;
101
102
  /**
@@ -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;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;;AAmDjF,+FAA+F;AAC/F,MAAM,UAAU,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,cAAc,EAAW,CAAC;AAEjG,MAAM,IAA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AE,WAAW,CAAC,EAAE,CAAC;YAC7C,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,WAAW,IAAI,KAAK,CAAC,CAAC;QACnD,CAAC;IACH,CAAC;IAED,yDAAyD;IACjD,UAAU;QAChB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC,EAAE,KAAK,CAAC;IACvE,CAAC;IAED,8FAA8F;IACtF,OAAO,CAAC,QAA4C,EAAE,KAAc;QAC1E,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC9D,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED,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 { mergeClaims } from './merge-claims.ts';\nimport { reactNative } from './react-native.ts';\nimport { WindowClaims, onWindowFront, sharedBySource } from './window-claims.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 /**\n * Android only: the bar's own background. iOS has no such thing.\n *\n * @deprecated Has no effect. Android apps on Expo SDK 57 draw edge-to-edge, where the status bar\n * has no background of its own and React Native ignores the change. Draw a view behind the bar\n * instead. Never sent on iOS.\n */\n readonly backgroundColor?: string;\n /**\n * Android only: whether content draws underneath the bar.\n *\n * @deprecated Has no effect. Android apps on Expo SDK 57 draw edge-to-edge, so content is always\n * underneath the bar and React Native ignores the change. Never sent on iOS.\n */\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 * Android: react-native-screens sets the bar again each time a screen appears, from that screen's\n * own props or, with none, to light text and shown. So a claim has to ride on every screen too.\n */\n readonly screensSetBar?: boolean;\n /** Calls `listener` when a window comes to the front, to be given the whole bar again. */\n onWindowFront?(listener: () => void): () => void;\n}\n\n/** 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\nconst NONE: StatusBarSource = {\n setStyle: () => {},\n setHidden: () => {},\n setBackgroundColor: () => {},\n setTranslucent: () => {},\n height: undefined,\n};\n\n/** One per React Native, so every app the runtime mounts claims the same bar. */\nexport function statusBarSource(): StatusBarSource {\n const native = reactNative();\n if (!native) return NONE;\n return sharedBySource(native, () => nativeSource(native));\n}\n\nfunction nativeSource(native: NonNullable<ReturnType<typeof reactNative>>): StatusBarSource {\n const { StatusBar } = native;\n const android = native.Platform?.OS === 'android';\n // Android 16 draws an app targeting SDK 35 or later edge-to-edge whatever its theme says. Before\n // it, a theme can opt out, and React Native's own answer is the flag its status bar module\n // checks. That answer is not enough on its own: Expo Go on Android 16 reports false.\n const info = native.TurboModuleRegistry?.get('DeviceInfo') as\n { getConstants?(): { isEdgeToEdge?: boolean } } | null | undefined;\n const edgeToEdge =\n android &&\n (Number(native.Platform.Version) >= 36 || info?.getConstants?.().isEdgeToEdge === true);\n const warned = new Set<string>();\n return {\n setStyle: (style, animated) => StatusBar.setBarStyle(BAR_STYLES[style], animated),\n setHidden: (hidden, animation) => StatusBar.setHidden(hidden, animation),\n setBackgroundColor: (color, animated) => {\n if (!android) return;\n if (edgeToEdge) warnNoEffect('backgroundColor', warned);\n StatusBar.setBackgroundColor(color, animated);\n },\n setTranslucent: (translucent) => {\n if (!android) return;\n if (edgeToEdge) warnNoEffect('translucent', warned);\n StatusBar.setTranslucent(translucent);\n },\n get height() {\n return StatusBar.currentHeight;\n },\n screensSetBar: android,\n onWindowFront,\n };\n}\n\ndeclare const ngDevMode: unknown;\n\n/**\n * Says, once per option and in development only, that Android ignores it. React Native's own\n * module returns early with \"current activity is edge-to-edge\", which only shows in logcat.\n */\nfunction warnNoEffect(option: 'backgroundColor' | 'translucent', warned: Set<string>): void {\n if (typeof ngDevMode !== 'undefined' && !ngDevMode) return;\n if (warned.has(option)) return;\n warned.add(option);\n console.warn(\n `[angular-native] StatusBar ${option} has no effect: Android draws the app edge-to-edge, ` +\n 'so content is always under the status bar. See https://ng-native.com/guide/android-edge-to-edge',\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 /** This app, among the apps claiming the bar: its scheme is what an `auto` style it claims follows. */\n private readonly owner: Owner = { scheme: inject(ColorScheme) };\n /** Every app's claims on this bar: the window is the runtime's, not an app's. */\n private readonly window = sharedBySource(this.source, () => new StatusBarWindow(this.source));\n\n /** What is actually showing: every claim in order, later ones winning per property. */\n readonly state: Signal<StatusBarState> = this.window.state;\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 /**\n * What a screen with no style or visibility of its own carries, so the claim is still what shows\n * when it appears. Empty but on Android, where a screen appearing sets the bar from its own props\n * and falls back to light text otherwise. The router passes it on.\n */\n readonly forScreens: Signal<{\n readonly style?: PlatformStatusBarStyle;\n readonly hidden?: boolean;\n }> = computed(() => {\n if (!this.source.screensSetBar) return {};\n const { style, hidden } = this.state();\n return { style: style && this.window.resolve(style), hidden };\n });\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 this.window.schemeChanged(this.owner, scheme),\n );\n inject(DestroyRef).onDestroy(() => {\n stop();\n // An app that goes takes its claims with it, and leaves the bar to the apps still here.\n this.window.claims.drop(this.owner);\n this.window.apply();\n });\n }\n\n /** The base claim, for an app that sets the bar once at startup. */\n set(state: StatusBarState): void {\n this.window.claims.setBase(this.owner, state);\n this.window.apply();\n }\n\n /** A claim on top of whatever is there. Call the returned function to drop it. */\n push(state: StatusBarState): () => void {\n const drop = this.window.claims.push(this.owner, { ...state });\n this.window.apply();\n return () => {\n drop();\n this.window.apply();\n };\n }\n}\n\ninterface Owner {\n readonly scheme: ColorScheme;\n}\n\n/** The bar, as every app on one source claims it. */\nclass StatusBarWindow {\n readonly claims = new WindowClaims<StatusBarState, Owner>();\n readonly state: Signal<StatusBarState> = computed(() =>\n mergeClaims(this.claims.all().map((claim) => claim.value)),\n );\n\n /** The properties a claim has had the platform change, which no claim names any more. */\n private readonly changed = new Set<'style' | 'hidden' | 'translucent'>();\n\n private readonly source: StatusBarSource;\n\n constructor(source: StatusBarSource) {\n this.source = source;\n // Lives as long as the source, which is the runtime's.\n source.onWindowFront?.(() => this.apply(true));\n }\n\n /** `style` for the platform, `auto` by the scheme of the app whose claim the style is. */\n resolve(style: StatusBarStyle, scheme?: Scheme): PlatformStatusBarStyle {\n return resolve(style, scheme ?? this.styleOwner()?.scheme.current() ?? 'light');\n }\n\n schemeChanged(owner: Owner, scheme: Scheme): void {\n const { style, animated } = untracked(this.state);\n if (style !== 'auto' || untracked(() => this.styleOwner()) !== owner) return;\n this.source.setStyle(this.resolve(style, scheme), animated);\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. 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. A window come to the front\n * is given what is claimed, with nothing animated and nothing put back.\n */\n apply(front = false): void {\n const { style, hidden, animated, backgroundColor, translucent } = untracked(this.state);\n const animate = front ? undefined : animated;\n if (this.changes('style', style)) {\n this.source.setStyle(\n untracked(() => this.resolve(style ?? 'default')),\n animate,\n );\n }\n if (this.changes('hidden', hidden)) {\n this.source.setHidden(hidden ?? false, animate ? 'fade' : undefined);\n }\n if (backgroundColor !== undefined) this.source.setBackgroundColor(backgroundColor, animate);\n if (this.changes('translucent', translucent)) {\n this.source.setTranslucent(translucent ?? false);\n }\n }\n\n /** The app whose claim the style in force comes from. */\n private styleOwner(): Owner | undefined {\n return this.claims.last((state) => state.style !== undefined)?.owner;\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"]}
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;AAChD,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;;AAmDjF,+FAA+F;AAC/F,MAAM,UAAU,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,cAAc,EAAW,CAAC;AAEjG,MAAM,IAAI,GAAoB;IAC5B,QAAQ,EAAE,GAAG,EAAE,GAAE,CAAC;IAClB,SAAS,EAAE,GAAG,EAAE,GAAE,CAAC;IACnB,kBAAkB,EAAE,GAAG,EAAE,GAAE,CAAC;IAC5B,cAAc,EAAE,GAAG,EAAE,GAAE,CAAC;IACxB,MAAM,EAAE,SAAS;CAClB,C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B,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC,EAAE,KAAK,CAAC;IACvE,CAAC;IAED,8FAA8F;IACtF,OAAO,CAAC,QAA4C,EAAE,KAAc;QAC1E,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC9D,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED,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 { mergeClaims } from './merge-claims.ts';\nimport { edgeToEdgeFlag, reactNative } from './react-native.ts';\nimport { WindowClaims, onWindowFront, sharedBySource } from './window-claims.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 /**\n * Android only: the bar's own background. iOS has no such thing.\n *\n * @deprecated Has no effect. Android apps on Expo SDK 57 draw edge-to-edge, where the status bar\n * has no background of its own and React Native ignores the change. Draw a view behind the bar\n * instead. Never sent on iOS.\n */\n readonly backgroundColor?: string;\n /**\n * Android only: whether content draws underneath the bar.\n *\n * @deprecated Has no effect. Android apps on Expo SDK 57 draw edge-to-edge, so content is always\n * underneath the bar and React Native ignores the change. Never sent on iOS.\n */\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 * Android: react-native-screens sets the bar again each time a screen appears, from that screen's\n * own props or, with none, to light text and shown. So a claim has to ride on every screen too.\n */\n readonly screensSetBar?: boolean;\n /** Calls `listener` when a window comes to the front, to be given the whole bar again. */\n onWindowFront?(listener: () => void): () => void;\n}\n\n/** 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\nconst NONE: StatusBarSource = {\n setStyle: () => {},\n setHidden: () => {},\n setBackgroundColor: () => {},\n setTranslucent: () => {},\n height: undefined,\n};\n\n/** One per React Native, so every app the runtime mounts claims the same bar. */\nexport function statusBarSource(): StatusBarSource {\n const native = reactNative();\n // A copy: with no bar to share, each app claims its own.\n if (!native) return { ...NONE };\n return sharedBySource(statusBarSource, native, () => nativeSource(native));\n}\n\nfunction nativeSource(native: NonNullable<ReturnType<typeof reactNative>>): StatusBarSource {\n const { StatusBar } = native;\n const android = native.Platform?.OS === 'android';\n // Android 16 draws an app targeting SDK 35 or later edge-to-edge whatever its theme says. Before\n // it, a theme can opt out, and React Native's own answer is the flag its status bar module\n // checks. That answer is not enough on its own: Expo Go on Android 16 reports false.\n // React Native 0.88 draws every Android app edge-to-edge, and removed both setters with it.\n const settable = typeof StatusBar.setBackgroundColor === 'function';\n const edgeToEdge =\n android && (!settable || Number(native.Platform.Version) >= 36 || edgeToEdgeFlag(native));\n const warned = new Set<string>();\n return {\n setStyle: (style, animated) => StatusBar.setBarStyle(BAR_STYLES[style], animated),\n setHidden: (hidden, animation) => StatusBar.setHidden(hidden, animation),\n setBackgroundColor: (color, animated) => {\n if (!android) return;\n if (edgeToEdge) warnNoEffect('backgroundColor', warned);\n StatusBar.setBackgroundColor?.(color, animated);\n },\n setTranslucent: (translucent) => {\n if (!android) return;\n if (edgeToEdge) warnNoEffect('translucent', warned);\n StatusBar.setTranslucent?.(translucent);\n },\n get height() {\n return StatusBar.currentHeight;\n },\n screensSetBar: android,\n onWindowFront,\n };\n}\n\ndeclare const ngDevMode: unknown;\n\n/**\n * Says, once per option and in development only, that Android ignores it. React Native's own\n * module returns early with \"current activity is edge-to-edge\", which only shows in logcat.\n */\nfunction warnNoEffect(option: 'backgroundColor' | 'translucent', warned: Set<string>): void {\n if (typeof ngDevMode !== 'undefined' && !ngDevMode) return;\n if (warned.has(option)) return;\n warned.add(option);\n console.warn(\n `[angular-native] StatusBar ${option} has no effect: Android draws the app edge-to-edge, ` +\n 'so content is always under the status bar. See https://ng-native.com/guide/android-edge-to-edge',\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 /** This app, among the apps claiming the bar: its scheme is what an `auto` style it claims follows. */\n private readonly owner: Owner = { scheme: inject(ColorScheme) };\n /** Every app's claims on this bar: the window is the runtime's, not an app's. */\n private readonly window = sharedBySource(\n StatusBarWindow,\n this.source,\n () => new StatusBarWindow(this.source),\n );\n\n /** What is actually showing: every claim in order, later ones winning per property. */\n readonly state: Signal<StatusBarState> = this.window.state;\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 /**\n * What a screen with no style or visibility of its own carries, so the claim is still what shows\n * when it appears. Empty but on Android, where a screen appearing sets the bar from its own props\n * and falls back to light text otherwise. The router passes it on.\n */\n readonly forScreens: Signal<{\n readonly style?: PlatformStatusBarStyle;\n readonly hidden?: boolean;\n }> = computed(() => {\n if (!this.source.screensSetBar) return {};\n const { style, hidden } = this.state();\n return { style: style && this.window.resolve(style), hidden };\n });\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 this.window.schemeChanged(this.owner, scheme),\n );\n inject(DestroyRef).onDestroy(() => {\n stop();\n // An app that goes takes its claims with it, and leaves the bar to the apps still here.\n this.window.claims.drop(this.owner);\n this.window.apply();\n });\n }\n\n /** The base claim, for an app that sets the bar once at startup. */\n set(state: StatusBarState): void {\n this.window.claims.setBase(this.owner, state);\n this.window.apply();\n }\n\n /** A claim on top of whatever is there. Call the returned function to drop it. */\n push(state: StatusBarState): () => void {\n const drop = this.window.claims.push(this.owner, { ...state });\n this.window.apply();\n return () => {\n drop();\n this.window.apply();\n };\n }\n}\n\ninterface Owner {\n readonly scheme: ColorScheme;\n}\n\n/** The bar, as every app on one source claims it. */\nclass StatusBarWindow {\n readonly claims = new WindowClaims<StatusBarState, Owner>();\n readonly state: Signal<StatusBarState> = computed(() =>\n mergeClaims(this.claims.all().map((claim) => claim.value)),\n );\n\n /** The properties a claim has had the platform change, which no claim names any more. */\n private readonly changed = new Set<'style' | 'hidden' | 'translucent'>();\n\n private readonly source: StatusBarSource;\n\n constructor(source: StatusBarSource) {\n this.source = source;\n // Lives as long as the source, which is the runtime's.\n source.onWindowFront?.(() => this.apply(true));\n }\n\n /** `style` for the platform, `auto` by the scheme of the app whose claim the style is. */\n resolve(style: StatusBarStyle, scheme?: Scheme): PlatformStatusBarStyle {\n return resolve(style, scheme ?? this.styleOwner()?.scheme.current() ?? 'light');\n }\n\n schemeChanged(owner: Owner, scheme: Scheme): void {\n const { style, animated } = untracked(this.state);\n if (style !== 'auto' || untracked(() => this.styleOwner()) !== owner) return;\n this.source.setStyle(this.resolve(style, scheme), animated);\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. 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. A window come to the front\n * is given what is claimed, with nothing animated and nothing put back.\n */\n apply(front = false): void {\n const { style, hidden, animated, backgroundColor, translucent } = untracked(this.state);\n const animate = front ? undefined : animated;\n if (this.changes('style', style)) {\n this.source.setStyle(\n untracked(() => this.resolve(style ?? 'default')),\n animate,\n );\n }\n if (this.changes('hidden', hidden)) {\n this.source.setHidden(hidden ?? false, animate ? 'fade' : undefined);\n }\n if (backgroundColor !== undefined) this.source.setBackgroundColor(backgroundColor, animate);\n if (this.changes('translucent', translucent)) {\n this.source.setTranslucent(translucent ?? false);\n }\n }\n\n /** The app whose claim the style in force comes from. */\n private styleOwner(): Owner | undefined {\n return this.claims.last((state) => state.style !== undefined)?.owner;\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"]}
@@ -42,10 +42,13 @@ export declare class WindowClaims<T, O extends object = object> {
42
42
  private update;
43
43
  }
44
44
  /**
45
- * What every app on `source` shares, made the first time one asks. `source` is the native module
46
- * the app writes through, or null for one that is not there.
45
+ * What every app on `source` shares for `purpose`, made the first time one asks. `source` is the
46
+ * native module the app writes through, or null for one that is not there: with no window to
47
+ * share, each app gets its own, so no claim outlives its app. `purpose` is what the value is for,
48
+ * such as the class `create` makes, so two services never share one, not even when one object
49
+ * stands in for two modules.
47
50
  */
48
- export declare function sharedBySource<W>(source: object | null, create: () => W): W;
51
+ export declare function sharedBySource<W>(purpose: object, source: object | null, create: () => W): W;
49
52
  /**
50
53
  * Android: calls `listener` each time an activity comes to the front, a recreated one included,
51
54
  * which starts with the platform's own window. Answers the function that stops listening. Nothing
@@ -65,18 +65,24 @@ export class WindowClaims {
65
65
  });
66
66
  }
67
67
  }
68
- /** The one stack, or whatever a module keeps for its window, for each native module. */
68
+ /** For each purpose, the one stack, or whatever a module keeps for its window, per native module. */
69
69
  const shared = new WeakMap();
70
- const ABSENT = {};
71
70
  /**
72
- * What every app on `source` shares, made the first time one asks. `source` is the native module
73
- * the app writes through, or null for one that is not there.
71
+ * What every app on `source` shares for `purpose`, made the first time one asks. `source` is the
72
+ * native module the app writes through, or null for one that is not there: with no window to
73
+ * share, each app gets its own, so no claim outlives its app. `purpose` is what the value is for,
74
+ * such as the class `create` makes, so two services never share one, not even when one object
75
+ * stands in for two modules.
74
76
  */
75
- export function sharedBySource(source, create) {
76
- const key = source ?? ABSENT;
77
- if (!shared.has(key))
78
- shared.set(key, create());
79
- return shared.get(key);
77
+ export function sharedBySource(purpose, source, create) {
78
+ if (!source)
79
+ return create();
80
+ let bySource = shared.get(purpose);
81
+ if (!bySource)
82
+ shared.set(purpose, (bySource = new WeakMap()));
83
+ if (!bySource.has(source))
84
+ bySource.set(source, create());
85
+ return bySource.get(source);
80
86
  }
81
87
  /**
82
88
  * Android: calls `listener` each time an activity comes to the front, a recreated one included,
@@ -1 +1 @@
1
- {"version":3,"file":"window-claims.js","sourceRoot":"","sources":["../src/window-claims.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAe,MAAM,eAAe,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAchD;;;GAGG;AACH,MAAM,OAAO,YAAY;IACN,MAAM,GAAG,MAAM,CAAyB,EAAE;+EAAC,CAAC;IAE7D,0CAA0C;IACjC,GAAG,GAAmC,QAAQ,CAAC,GAAG,EAAE,CAC3D,IAAI,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;4EAC9F,CAAC;IAEF,kDAAkD;IAClD,IAAI,CAAC,IAA2B;QAC9B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,KAAK,IAAI,EAAE,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,EAAE;YAAE,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,CAAE,CAAC,KAAK,CAAC;gBAA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AG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;;YACxB,IAAI,CAAC,OAAO,EAAE,CAAC;IACtB,CAAC;IAED,uDAAuD;IACvD,KAAK;QACH,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QACpB,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;IACxB,CAAC;CACF","sourcesContent":["/**\n * What an app claims of the window: the status bar, the navigation bar, keep-awake, the orientation\n * lock, the brightness, screen capture.\n *\n * The window is the runtime's, not an app's. Android recreates an activity after a configuration\n * change it does not handle, a font size change among them: it mounts the new app on a new surface\n * and only then stops the old one. Claims kept per app would let the old app, going after the new\n * one has claimed, put the window back to the platform's own under the new app. So every app's\n * claims for one native module are kept together, in one stack per module, as React Native keeps\n * its own status bar's, and an app's claims leave with it.\n *\n * The window an app writes to can also be a new one: the recreated activity starts at the\n * platform's own, and a call that comes while no activity is current is dropped. So a source tells\n * its stack when a window comes to the front, and the stack writes the whole of it again.\n */\nimport { computed, signal, untracked, type Signal } from '@angular/core';\nimport { reactNative } from './react-native.ts';\n\n/** One claim, and the app it came from. */\nexport interface Claim<T, O = unknown> {\n readonly value: T;\n readonly owner: O;\n}\n\ninterface Group<T, O> {\n readonly owner: O;\n readonly base: Claim<T, O> | undefined;\n readonly pushed: readonly Claim<T, O>[];\n}\n\n/**\n * Every app's claims on one native module. An app's base claim is under its own pushed ones, and\n * an app's claims are under those of an app that claimed after it first did.\n */\nexport class WindowClaims<T, O extends object = object> {\n private readonly groups = signal<readonly Group<T, O>[]>([]);\n\n /** Every claim, the one in force last. */\n readonly all: Signal<readonly Claim<T, O>[]> = computed(() =>\n this.groups().flatMap((group) => (group.base ? [group.base, ...group.pushed] : group.pushed)),\n );\n\n /** The claim in force last that passes `test`. */\n last(test: (value: T) => boolean): Claim<T, O> | undefined {\n const all = this.all();\n for (let at = all.length - 1; at >= 0; at--) if (test(all[at]!.value)) return all[at];\n return undefined;\n }\n\n /** The apps with claims, the one that claimed first first. */\n readonly owners: Signal<readonly O[]> = computed(() => this.groups().map((group) => group.owner));\n\n /** `owner`'s base claim, replacing the one it had. */\n setBase(owner: O, value: T): void {\n this.update(owner, (group) => ({ ...group, base: { value, owner } }));\n }\n\n /** A claim of `owner`'s on top of its others. Call the returned function to drop it. */\n push(owner: O, value: T): () => void {\n const claim: Claim<T, O> = { value, owner };\n this.update(owner, (group) => ({ ...group, pushed: [...group.pushed, claim] }));\n return () =>\n this.groups.update((groups) =>\n groups.map((group) =>\n group.owner === owner\n ? { ...group, pushed: group.pushed.filter((one) => one !== claim) }\n : group,\n ),\n );\n }\n\n /** Every app's claims. */\n clear(): void {\n this.groups.set([]);\n }\n\n /** Every claim of `owner`'s, for an app that goes. */\n drop(owner: O): void {\n this.groups.update((groups) => groups.filter((group) => group.owner !== owner));\n }\n\n private update(owner: O, change: (group: Group<T, O>) => Group<T, O>): void {\n this.groups.update((groups) => {\n const at = groups.findIndex((group) => group.owner === owner);\n if (at === -1) return [...groups, change({ owner, base: undefined, pushed: [] })];\n return groups.map((group, index) => (index === at ? change(group) : group));\n });\n }\n}\n\n/** The one stack, or whatever a module keeps for its window, for each native module. */\nconst shared = new WeakMap<object, unknown>();\nconst ABSENT = {};\n\n/**\n * What every app on `source` shares, made the first time one asks. `source` is the native module\n * the app writes through, or null for one that is not there.\n */\nexport function sharedBySource<W>(source: object | null, create: () => W): W {\n const key = source ?? ABSENT;\n if (!shared.has(key)) shared.set(key, create());\n return shared.get(key) as W;\n}\n\n/**\n * Android: calls `listener` each time an activity comes to the front, a recreated one included,\n * which starts with the platform's own window. Answers the function that stops listening. Nothing\n * on iOS, where a window keeps what it was given.\n */\nexport function onWindowFront(listener: () => void): () => void {\n const native = reactNative();\n if (native?.Platform?.OS !== 'android') return () => {};\n const subscription = native.AppState.addEventListener('change', (state) => {\n if (state === 'active') listener();\n });\n return () => subscription.remove();\n}\n\n/**\n * A window setting only the top claim decides, such as the orientation lock: every app's claims,\n * the one claimed last in force, and the platform's own when none is left.\n */\nexport class TopClaim<T> {\n readonly claims = new WindowClaims<T>();\n /** The claim the platform was last given, so a claim under it changes nothing. */\n private sent: Claim<T> | undefined;\n private readonly put: (value: T) => void;\n private readonly putBack: () => void;\n\n constructor(\n put: (value: T) => void,\n putBack: () => void,\n onFront?: (listener: () => void) => () => void,\n ) {\n this.put = put;\n this.putBack = putBack;\n // Lives as long as the module, which is the runtime's.\n onFront?.(() => {\n if (this.sent) this.put(this.sent.value);\n });\n }\n\n /** Tell the platform, if the claim in force is not the one it was last given. */\n apply(): void {\n const top = untracked(this.claims.all).at(-1);\n if (top === this.sent) return;\n this.sent = top;\n if (top) this.put(top.value);\n else this.putBack();\n }\n\n /** Every app's claims, and the platform's own back. */\n clear(): void {\n this.claims.clear();\n this.sent = undefined;\n }\n}\n"]}
1
+ {"version":3,"file":"window-claims.js","sourceRoot":"","sources":["../src/window-claims.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAe,MAAM,eAAe,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAchD;;;GAGG;AACH,MAAM,OAAO,YAAY;IACN,MAAM,GAAG,MAAM,CAAyB,EAAE;+EAAC,CAAC;IAE7D,0CAA0C;IACjC,GAAG,GAAmC,QAAQ,CAAC,GAAG,EAAE,CAC3D,IAAI,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;4EAC9F,CAAC;IAEF,kDAAkD;IAClD,IAAI,CAAC,IAA2B;QAC9B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,KAAK,IAAI,EAAE,GAAG,GAAG,CAA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C;QAC3C,CAAC,CAAC,CAAC;IACL,CAAC;IAED,iFAAiF;IACjF,KAAK;QACH,MAAM,GAAG,GAAG,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QAC9C,IAAI,GAAG,KAAK,IAAI,CAAC,IAAI;YAAE,OAAO;QAC9B,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,IAAI,GAAG;YAAE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;;YACxB,IAAI,CAAC,OAAO,EAAE,CAAC;IACtB,CAAC;IAED,uDAAuD;IACvD,KAAK;QACH,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QACpB,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;IACxB,CAAC;CACF","sourcesContent":["/**\n * What an app claims of the window: the status bar, the navigation bar, keep-awake, the orientation\n * lock, the brightness, screen capture.\n *\n * The window is the runtime's, not an app's. Android recreates an activity after a configuration\n * change it does not handle, a font size change among them: it mounts the new app on a new surface\n * and only then stops the old one. Claims kept per app would let the old app, going after the new\n * one has claimed, put the window back to the platform's own under the new app. So every app's\n * claims for one native module are kept together, in one stack per module, as React Native keeps\n * its own status bar's, and an app's claims leave with it.\n *\n * The window an app writes to can also be a new one: the recreated activity starts at the\n * platform's own, and a call that comes while no activity is current is dropped. So a source tells\n * its stack when a window comes to the front, and the stack writes the whole of it again.\n */\nimport { computed, signal, untracked, type Signal } from '@angular/core';\nimport { reactNative } from './react-native.ts';\n\n/** One claim, and the app it came from. */\nexport interface Claim<T, O = unknown> {\n readonly value: T;\n readonly owner: O;\n}\n\ninterface Group<T, O> {\n readonly owner: O;\n readonly base: Claim<T, O> | undefined;\n readonly pushed: readonly Claim<T, O>[];\n}\n\n/**\n * Every app's claims on one native module. An app's base claim is under its own pushed ones, and\n * an app's claims are under those of an app that claimed after it first did.\n */\nexport class WindowClaims<T, O extends object = object> {\n private readonly groups = signal<readonly Group<T, O>[]>([]);\n\n /** Every claim, the one in force last. */\n readonly all: Signal<readonly Claim<T, O>[]> = computed(() =>\n this.groups().flatMap((group) => (group.base ? [group.base, ...group.pushed] : group.pushed)),\n );\n\n /** The claim in force last that passes `test`. */\n last(test: (value: T) => boolean): Claim<T, O> | undefined {\n const all = this.all();\n for (let at = all.length - 1; at >= 0; at--) if (test(all[at]!.value)) return all[at];\n return undefined;\n }\n\n /** The apps with claims, the one that claimed first first. */\n readonly owners: Signal<readonly O[]> = computed(() => this.groups().map((group) => group.owner));\n\n /** `owner`'s base claim, replacing the one it had. */\n setBase(owner: O, value: T): void {\n this.update(owner, (group) => ({ ...group, base: { value, owner } }));\n }\n\n /** A claim of `owner`'s on top of its others. Call the returned function to drop it. */\n push(owner: O, value: T): () => void {\n const claim: Claim<T, O> = { value, owner };\n this.update(owner, (group) => ({ ...group, pushed: [...group.pushed, claim] }));\n return () =>\n this.groups.update((groups) =>\n groups.map((group) =>\n group.owner === owner\n ? { ...group, pushed: group.pushed.filter((one) => one !== claim) }\n : group,\n ),\n );\n }\n\n /** Every app's claims. */\n clear(): void {\n this.groups.set([]);\n }\n\n /** Every claim of `owner`'s, for an app that goes. */\n drop(owner: O): void {\n this.groups.update((groups) => groups.filter((group) => group.owner !== owner));\n }\n\n private update(owner: O, change: (group: Group<T, O>) => Group<T, O>): void {\n this.groups.update((groups) => {\n const at = groups.findIndex((group) => group.owner === owner);\n if (at === -1) return [...groups, change({ owner, base: undefined, pushed: [] })];\n return groups.map((group, index) => (index === at ? change(group) : group));\n });\n }\n}\n\n/** For each purpose, the one stack, or whatever a module keeps for its window, per native module. */\nconst shared = new WeakMap<object, WeakMap<object, unknown>>();\n\n/**\n * What every app on `source` shares for `purpose`, made the first time one asks. `source` is the\n * native module the app writes through, or null for one that is not there: with no window to\n * share, each app gets its own, so no claim outlives its app. `purpose` is what the value is for,\n * such as the class `create` makes, so two services never share one, not even when one object\n * stands in for two modules.\n */\nexport function sharedBySource<W>(purpose: object, source: object | null, create: () => W): W {\n if (!source) return create();\n let bySource = shared.get(purpose);\n if (!bySource) shared.set(purpose, (bySource = new WeakMap()));\n if (!bySource.has(source)) bySource.set(source, create());\n return bySource.get(source) as W;\n}\n\n/**\n * Android: calls `listener` each time an activity comes to the front, a recreated one included,\n * which starts with the platform's own window. Answers the function that stops listening. Nothing\n * on iOS, where a window keeps what it was given.\n */\nexport function onWindowFront(listener: () => void): () => void {\n const native = reactNative();\n if (native?.Platform?.OS !== 'android') return () => {};\n const subscription = native.AppState.addEventListener('change', (state) => {\n if (state === 'active') listener();\n });\n return () => subscription.remove();\n}\n\n/**\n * A window setting only the top claim decides, such as the orientation lock: every app's claims,\n * the one claimed last in force, and the platform's own when none is left.\n */\nexport class TopClaim<T> {\n readonly claims = new WindowClaims<T>();\n /** The claim the platform was last given, so a claim under it changes nothing. */\n private sent: Claim<T> | undefined;\n private readonly put: (value: T) => void;\n private readonly putBack: () => void;\n\n constructor(\n put: (value: T) => void,\n putBack: () => void,\n onFront?: (listener: () => void) => () => void,\n ) {\n this.put = put;\n this.putBack = putBack;\n // Lives as long as the module, which is the runtime's.\n onFront?.(() => {\n if (this.sent) this.put(this.sent.value);\n });\n }\n\n /** Tell the platform, if the claim in force is not the one it was last given. */\n apply(): void {\n const top = untracked(this.claims.all).at(-1);\n if (top === this.sent) return;\n this.sent = top;\n if (top) this.put(top.value);\n else this.putBack();\n }\n\n /** Every app's claims, and the platform's own back. */\n clear(): void {\n this.claims.clear();\n this.sent = undefined;\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ng-native/device",
3
- "version": "0.17.0",
3
+ "version": "0.18.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.17.0"
20
+ "@ng-native/fabric": "0.18.0"
21
21
  },
22
22
  "peerDependencies": {
23
23
  "@angular/core": "^22.0.0",