@ng-native/device 0.12.0 → 0.14.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/deep-links.js +12 -3
- package/dist/deep-links.js.map +1 -1
- package/dist/react-native.d.ts +4 -0
- package/dist/react-native.js.map +1 -1
- package/dist/status-bar.d.ts +27 -2
- package/dist/status-bar.js +48 -2
- package/dist/status-bar.js.map +1 -1
- package/package.json +2 -2
package/dist/deep-links.js
CHANGED
|
@@ -49,14 +49,23 @@ function isLauncher(rest) {
|
|
|
49
49
|
}
|
|
50
50
|
/** Schemes that carry a host to skip before the path starts. */
|
|
51
51
|
const HAS_HOST = new Set(['http', 'https', 'exp', 'exps']);
|
|
52
|
+
/**
|
|
53
|
+
* The app's path after Expo Go's `/--/`, or null for a url with none in its path. In a query or a
|
|
54
|
+
* fragment, `/--/` is the app's own: a search for it is not a launch prefix.
|
|
55
|
+
*/
|
|
56
|
+
function expoGoPath(rest) {
|
|
57
|
+
const end = rest.search(/[?#]/);
|
|
58
|
+
const marker = (end === -1 ? rest : rest.slice(0, end)).indexOf('/--/');
|
|
59
|
+
return marker === -1 ? null : rest.slice(marker + 3);
|
|
60
|
+
}
|
|
52
61
|
export function pathOf(url) {
|
|
53
62
|
if (!url)
|
|
54
63
|
return null;
|
|
55
64
|
const scheme = /^([a-z][a-z0-9+.-]*):\/\//i.exec(url);
|
|
56
65
|
const rest = scheme ? url.slice(scheme[0].length) : url;
|
|
57
|
-
const expoGo = rest
|
|
58
|
-
if (expoGo !==
|
|
59
|
-
return
|
|
66
|
+
const expoGo = expoGoPath(rest);
|
|
67
|
+
if (expoGo !== null)
|
|
68
|
+
return expoGo;
|
|
60
69
|
if (isLauncher(rest))
|
|
61
70
|
return null;
|
|
62
71
|
// A url with a host has one to skip. A custom scheme does not: `canary://settings` names a
|
package/dist/deep-links.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deep-links.js","sourceRoot":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IAED;;;OAGG;IACH,YAAY;QACV,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,EAAE,CAAC;IAC/B,CAAC;uGAxEU,SAAS;wGAAT,SAAS;;2FAAT,SAAS;kBADrB,OAAO","sourcesContent":["/**\n * Links that arrive from outside the app: a `canary://` url, a universal link, a notification.\n */\nimport { ErrorHandler, InjectionToken, Injector, Service, inject } from '@angular/core';\nimport { reactNative } from './react-native.ts';\n\nexport interface DeepLinkSource {\n /** The url the app was launched with. A promise, and nothing says it settles before mount. */\n launchUrl(): Promise<string | null>;\n subscribe(listener: (url: string) => void): () => void;\n open(url: string): void;\n /** Optional, so a source written before there was one is still a source. */\n openSettings?(): void;\n}\n\nexport function deepLinkSource(): DeepLinkSource {\n const native = reactNative();\n if (!native) {\n return {\n launchUrl: () => Promise.resolve(null),\n subscribe: () => () => {},\n open: () => {},\n openSettings: () => {},\n };\n }\n\n return {\n launchUrl: () => native.Linking.getInitialURL(),\n subscribe: (listener) => {\n const subscription = native.Linking.addEventListener('url', ({ url }) => listener(url));\n return () => subscription.remove();\n },\n open: (url) => void native.Linking.openURL(url).catch(() => {}),\n openSettings: () => void native.Linking.openSettings().catch(() => {}),\n };\n}\n\n/**\n * The path a url means to this app: everything after the scheme and host.\n *\n * Prefixes are app configuration and every app's are different, but stripping one is not: what a\n * router can navigate to is a path. `canary://primitives` and `https://example.com/primitives`\n * both mean `/primitives` - which takes noticing that only the second one has a host.\n *\n * Expo Go is the exception worth handling here rather than in every app: it serves every project\n * from one development url, puts the app's own path after `/--`, and has a host like a web url\n * rather than a path like an app's own scheme.\n *\n * The development client is the other. `expo run:ios` launches the app through\n * `<scheme>://expo-development-client/?url=...`, which is Expo telling its own launcher which\n * bundle to load and means nothing to the app. Left alone it reaches the router as a path, matches\n * no route, and the app shows a blank screen on every launch during development - which looks\n * exactly like a bug in the app.\n */\n\n/** Expo's own launch hosts. Not paths: instructions to the launcher, which the app never routes. */\nconst EXPO_INTERNAL = new Set(['expo-development-client']);\n\n/** Whether the first segment names one of Expo's launchers rather than something in the app. */\nfunction isLauncher(rest: string): boolean {\n return EXPO_INTERNAL.has(rest.split(/[/?#]/, 1)[0] ?? '');\n}\n\n/** Schemes that carry a host to skip before the path starts. */\nconst HAS_HOST = new Set(['http', 'https', 'exp', 'exps']);\n\nexport function pathOf(url: string | null): string | null {\n if (!url) return null;\n const scheme = /^([a-z][a-z0-9+.-]*):\\/\\//i.exec(url);\n const rest = scheme ? url.slice(scheme[0].length) : url;\n\n const expoGo = rest.indexOf('/--/');\n if (expoGo !== -1) return rest.slice(expoGo + 3);\n if (isLauncher(rest)) return null;\n\n // A url with a host has one to skip. A custom scheme does not: `canary://settings` names a\n // path, not a machine, and treating the two alike is how it quietly becomes `/`.\n if (HAS_HOST.has(scheme?.[1]?.toLowerCase() ?? '')) {\n // The host ends at the path, or at a query or fragment when there is no path.\n const end = rest.search(/[/?#]/);\n if (end === -1) return '/';\n return rest[end] === '/' ? rest.slice(end) : `/${rest.slice(end)}`;\n }\n return rest.startsWith('/') ? rest : `/${rest}`;\n}\n\n/**\n * The launch url is delivered whichever way is true at the time: as the initial url if it is\n * known before anything asks, and as an ordinary link if the app is already up. Both happen -\n * the promise races the first navigation and neither order is guaranteed - and a link that\n * arrives late is still a link, so nothing is dropped either way.\n */\n@Service()\nexport class DeepLinks {\n /** Overridden in a test to deliver a link with no platform under it. */\n static readonly SOURCE = new InjectionToken<DeepLinkSource>('angular-native.deepLinkSource', {\n factory: deepLinkSource,\n });\n\n private readonly source = inject(DeepLinks.SOURCE);\n private readonly injector = inject(Injector);\n private launch: string | null = null;\n private readonly listeners = new Set<(path: string) => void>();\n\n constructor() {\n void this.source.launchUrl().then((url) => {\n const path = pathOf(url);\n if (!path || path === '/') return;\n if (this.listeners.size) this.listeners.forEach((listener) => this.deliver(listener, path));\n else this.launch = path;\n });\n }\n\n /** The path the app was launched with, if it is known yet. */\n initialUrl(): string | null {\n return this.launch;\n }\n\n /** Links that arrive while the app is running, as paths. Returns an unsubscribe. */\n subscribe(listener: (path: string) => void): () => void {\n // Each subscription is its own entry, so the same function subscribed twice stops once.\n const subscription = (path: string) => listener(path);\n this.listeners.add(subscription);\n const unsubscribe = this.source.subscribe((url) => {\n const path = pathOf(url);\n if (path) listener(path);\n });\n return () => {\n this.listeners.delete(subscription);\n unsubscribe();\n };\n }\n\n /**\n * One listener throwing is reported, and does not keep the launch url from the rest. The\n * `ErrorHandler` is looked up when that happens rather than when this is made: an app's handler\n * that injects the router reaches `DeepLinks` through the location, and would be a cycle at boot.\n */\n private deliver(listener: (path: string) => void, path: string): void {\n try {\n listener(path);\n } catch (error) {\n // A handler that rethrows, as some apps' do, would otherwise stop the listeners after this.\n try {\n const errors = this.injector.get(ErrorHandler, null);\n if (errors) errors.handleError(error);\n else console.error(error);\n } catch (reporting) {\n if (reporting === error) console.error(error);\n else console.error(error, reporting);\n }\n }\n }\n\n /** Hand a url to whatever else on the device handles it: a browser, Maps, another app. */\n open(url: string): void {\n this.source.open(url);\n }\n\n /**\n * Open the app's own page in the system settings, where a person turns on a permission the\n * platform no longer asks for. Android has no url for that page, so `open()` cannot reach it.\n */\n openSettings(): void {\n this.source.openSettings?.();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"deep-links.js","sourceRoot":"","sources":["../src/deep-links.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACxF,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;;AAWhD,MAAM,UAAU,cAAc;IAC5B,MAAM,MAAM,GAAG,WAAW,EAAE,CAAC;IAC7B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO;YACL,SAAS,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC;YACtC,SAAS,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,GAAE,CAAC;YACz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E,CAAC;IAC/B,CAAC;uGAxEU,SAAS;wGAAT,SAAS;;2FAAT,SAAS;kBADrB,OAAO","sourcesContent":["/**\n * Links that arrive from outside the app: a `canary://` url, a universal link, a notification.\n */\nimport { ErrorHandler, InjectionToken, Injector, Service, inject } from '@angular/core';\nimport { reactNative } from './react-native.ts';\n\nexport interface DeepLinkSource {\n /** The url the app was launched with. A promise, and nothing says it settles before mount. */\n launchUrl(): Promise<string | null>;\n subscribe(listener: (url: string) => void): () => void;\n open(url: string): void;\n /** Optional, so a source written before there was one is still a source. */\n openSettings?(): void;\n}\n\nexport function deepLinkSource(): DeepLinkSource {\n const native = reactNative();\n if (!native) {\n return {\n launchUrl: () => Promise.resolve(null),\n subscribe: () => () => {},\n open: () => {},\n openSettings: () => {},\n };\n }\n\n return {\n launchUrl: () => native.Linking.getInitialURL(),\n subscribe: (listener) => {\n const subscription = native.Linking.addEventListener('url', ({ url }) => listener(url));\n return () => subscription.remove();\n },\n open: (url) => void native.Linking.openURL(url).catch(() => {}),\n openSettings: () => void native.Linking.openSettings().catch(() => {}),\n };\n}\n\n/**\n * The path a url means to this app: everything after the scheme and host.\n *\n * Prefixes are app configuration and every app's are different, but stripping one is not: what a\n * router can navigate to is a path. `canary://primitives` and `https://example.com/primitives`\n * both mean `/primitives` - which takes noticing that only the second one has a host.\n *\n * Expo Go is the exception worth handling here rather than in every app: it serves every project\n * from one development url, puts the app's own path after `/--`, and has a host like a web url\n * rather than a path like an app's own scheme.\n *\n * The development client is the other. `expo run:ios` launches the app through\n * `<scheme>://expo-development-client/?url=...`, which is Expo telling its own launcher which\n * bundle to load and means nothing to the app. Left alone it reaches the router as a path, matches\n * no route, and the app shows a blank screen on every launch during development - which looks\n * exactly like a bug in the app.\n */\n\n/** Expo's own launch hosts. Not paths: instructions to the launcher, which the app never routes. */\nconst EXPO_INTERNAL = new Set(['expo-development-client']);\n\n/** Whether the first segment names one of Expo's launchers rather than something in the app. */\nfunction isLauncher(rest: string): boolean {\n return EXPO_INTERNAL.has(rest.split(/[/?#]/, 1)[0] ?? '');\n}\n\n/** Schemes that carry a host to skip before the path starts. */\nconst HAS_HOST = new Set(['http', 'https', 'exp', 'exps']);\n\n/**\n * The app's path after Expo Go's `/--/`, or null for a url with none in its path. In a query or a\n * fragment, `/--/` is the app's own: a search for it is not a launch prefix.\n */\nfunction expoGoPath(rest: string): string | null {\n const end = rest.search(/[?#]/);\n const marker = (end === -1 ? rest : rest.slice(0, end)).indexOf('/--/');\n return marker === -1 ? null : rest.slice(marker + 3);\n}\n\nexport function pathOf(url: string | null): string | null {\n if (!url) return null;\n const scheme = /^([a-z][a-z0-9+.-]*):\\/\\//i.exec(url);\n const rest = scheme ? url.slice(scheme[0].length) : url;\n\n const expoGo = expoGoPath(rest);\n if (expoGo !== null) return expoGo;\n if (isLauncher(rest)) return null;\n\n // A url with a host has one to skip. A custom scheme does not: `canary://settings` names a\n // path, not a machine, and treating the two alike is how it quietly becomes `/`.\n if (HAS_HOST.has(scheme?.[1]?.toLowerCase() ?? '')) {\n // The host ends at the path, or at a query or fragment when there is no path.\n const end = rest.search(/[/?#]/);\n if (end === -1) return '/';\n return rest[end] === '/' ? rest.slice(end) : `/${rest.slice(end)}`;\n }\n return rest.startsWith('/') ? rest : `/${rest}`;\n}\n\n/**\n * The launch url is delivered whichever way is true at the time: as the initial url if it is\n * known before anything asks, and as an ordinary link if the app is already up. Both happen -\n * the promise races the first navigation and neither order is guaranteed - and a link that\n * arrives late is still a link, so nothing is dropped either way.\n */\n@Service()\nexport class DeepLinks {\n /** Overridden in a test to deliver a link with no platform under it. */\n static readonly SOURCE = new InjectionToken<DeepLinkSource>('angular-native.deepLinkSource', {\n factory: deepLinkSource,\n });\n\n private readonly source = inject(DeepLinks.SOURCE);\n private readonly injector = inject(Injector);\n private launch: string | null = null;\n private readonly listeners = new Set<(path: string) => void>();\n\n constructor() {\n void this.source.launchUrl().then((url) => {\n const path = pathOf(url);\n if (!path || path === '/') return;\n if (this.listeners.size) this.listeners.forEach((listener) => this.deliver(listener, path));\n else this.launch = path;\n });\n }\n\n /** The path the app was launched with, if it is known yet. */\n initialUrl(): string | null {\n return this.launch;\n }\n\n /** Links that arrive while the app is running, as paths. Returns an unsubscribe. */\n subscribe(listener: (path: string) => void): () => void {\n // Each subscription is its own entry, so the same function subscribed twice stops once.\n const subscription = (path: string) => listener(path);\n this.listeners.add(subscription);\n const unsubscribe = this.source.subscribe((url) => {\n const path = pathOf(url);\n if (path) listener(path);\n });\n return () => {\n this.listeners.delete(subscription);\n unsubscribe();\n };\n }\n\n /**\n * One listener throwing is reported, and does not keep the launch url from the rest. The\n * `ErrorHandler` is looked up when that happens rather than when this is made: an app's handler\n * that injects the router reaches `DeepLinks` through the location, and would be a cycle at boot.\n */\n private deliver(listener: (path: string) => void, path: string): void {\n try {\n listener(path);\n } catch (error) {\n // A handler that rethrows, as some apps' do, would otherwise stop the listeners after this.\n try {\n const errors = this.injector.get(ErrorHandler, null);\n if (errors) errors.handleError(error);\n else console.error(error);\n } catch (reporting) {\n if (reporting === error) console.error(error);\n else console.error(error, reporting);\n }\n }\n }\n\n /** Hand a url to whatever else on the device handles it: a browser, Maps, another app. */\n open(url: string): void {\n this.source.open(url);\n }\n\n /**\n * Open the app's own page in the system settings, where a person turns on a permission the\n * platform no longer asks for. Android has no url for that page, so `open()` cannot reach it.\n */\n openSettings(): void {\n this.source.openSettings?.();\n }\n}\n"]}
|
package/dist/react-native.d.ts
CHANGED
|
@@ -108,6 +108,10 @@ export interface ReactNative {
|
|
|
108
108
|
OS: string;
|
|
109
109
|
Version?: string | number;
|
|
110
110
|
};
|
|
111
|
+
/** Optional: only the status bar reads it, for `DeviceInfo`'s `isEdgeToEdge` on Android. */
|
|
112
|
+
TurboModuleRegistry?: {
|
|
113
|
+
get(name: string): unknown;
|
|
114
|
+
};
|
|
111
115
|
Share: {
|
|
112
116
|
share(content: {
|
|
113
117
|
message?: string;
|
package/dist/react-native.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-native.js","sourceRoot":"","sources":["../src/react-native.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;
|
|
1
|
+
{"version":3,"file":"react-native.js","sourceRoot":"","sources":["../src/react-native.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAkJH;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,WAAW;IACzB,IAAK,UAAkD,CAAC,qBAAqB,KAAK,SAAS,EAAE,CAAC;QAC5F,OAAO,IAAI,CAAC;IACd,CAAC;IACD,+FAA+F;IAC/F,8EAA8E;IAC9E,aAAa;IACb,IAAI,OAAO,OAAO,KAAK,UAAU;QAAE,OAAO,OAAO,CAAC,cAAc,CAAgB,CAAC;IACjF,OAAO,CAAC,KAAK,CACX,uFAAuF;QACrF,+DAA+D,CAClE,CAAC;IACF,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["/**\n * React Native's own modules, fetched when a service is first constructed rather than when this\n * file is loaded.\n *\n * The distinction matters more than it looks. React Native ships its JavaScript as Flow, which\n * Node cannot parse, so a static `import ... from 'react-native'` anywhere in this package would\n * make the package unimportable by the test suite - and by `@ng-native/components`, which\n * the suite imports constantly. A call inside a factory is only ever executed on a device, where\n * `react-native` is the most ordinary import there is.\n *\n * ponytail: a `require` in a codebase that otherwise has none. The alternative is the shape\n * `@ng-native/expo` uses - a file per service outside `src`, importing the module and\n * declaring the service - which is right there because Expo's packages are optional peer\n * dependencies an app may not have installed. React Native is not optional, so the seam buys\n * nothing but files.\n */\n\n/** The subset of React Native this package reaches for, described so `require` has a type. */\nexport interface ReactNative {\n AccessibilityInfo: {\n isScreenReaderEnabled(): Promise<boolean>;\n isReduceMotionEnabled(): Promise<boolean>;\n isBoldTextEnabled(): Promise<boolean>;\n announceForAccessibility(announcement: string): void;\n addEventListener(\n event: 'screenReaderChanged' | 'reduceMotionChanged' | 'boldTextChanged',\n handler: (value: boolean) => void,\n ): { remove(): void };\n };\n AppState: {\n currentState: string | null;\n addEventListener(event: 'change', handler: (state: string) => void): { remove(): void };\n };\n Appearance: {\n getColorScheme(): 'light' | 'dark' | null | undefined;\n addChangeListener(handler: (preferences: { colorScheme?: string | null }) => void): {\n remove(): void;\n };\n setColorScheme?(scheme: 'light' | 'dark' | 'unspecified'): void;\n };\n BackHandler: {\n addEventListener(event: 'hardwareBackPress', handler: () => boolean): { remove(): void };\n };\n Dimensions: {\n get(dimension: 'window' | 'screen'): { width: number; height: number };\n addEventListener(\n event: 'change',\n handler: (sizes: {\n window: { width: number; height: number };\n screen: { width: number; height: number };\n }) => void,\n ): { remove(): void };\n };\n I18nManager: {\n /** Whether the app is laid out right to left. Fixed for the lifetime of the process. */\n isRTL: boolean;\n };\n Keyboard: {\n dismiss(): void;\n addListener(\n event:\n | 'keyboardDidShow'\n | 'keyboardDidHide'\n | 'keyboardWillShow'\n | 'keyboardWillHide'\n | 'keyboardWillChangeFrame',\n handler: (event: NativeKeyboardEvent) => void,\n ): { remove(): void };\n };\n StyleSheet: {\n /** The thinnest line the screen can draw, in points. `1 / PixelRatio.get()`, near enough. */\n hairlineWidth: number;\n };\n ActionSheetIOS?: {\n showActionSheetWithOptions(\n options: {\n title?: string;\n options: string[];\n cancelButtonIndex: number;\n destructiveButtonIndex?: number;\n },\n callback: (index: number) => void,\n ): void;\n };\n Alert: {\n alert(\n title: string,\n message?: string,\n buttons?: { text?: string; style?: string; onPress?: () => void }[],\n options?: object,\n ): void;\n /** iOS only. Absent on Android, where there is no such dialog. */\n prompt?(\n title: string,\n message?: string,\n callbackOrButtons?:\n | ((value: string) => void)\n | { text?: string; style?: string; onPress?: (value?: string) => void }[],\n type?: string,\n defaultValue?: string,\n ): void;\n };\n PixelRatio: {\n get(): number;\n /** The user's text size setting, as a multiplier. One is the default. */\n getFontScale(): number;\n };\n /** `Version` is a string on iOS, `'26.5'`, and the API level, a number, on Android. */\n Platform: { OS: string; Version?: string | number };\n /** Optional: only the status bar reads it, for `DeviceInfo`'s `isEdgeToEdge` on Android. */\n TurboModuleRegistry?: { get(name: string): unknown };\n Share: {\n share(\n content: { message?: string; url?: string; title?: string },\n options?: object,\n ): Promise<{ action: string; activityType?: string | null }>;\n };\n ToastAndroid?: {\n show(message: string, duration: number): void;\n SHORT: number;\n LONG: number;\n };\n Vibration: {\n vibrate(pattern?: number | number[], repeat?: boolean): void;\n cancel(): void;\n };\n DevSettings?: {\n addMenuItem(title: string, handler: () => unknown): void;\n reload(reason?: string): void;\n };\n LayoutAnimation: {\n configureNext(config: object, onDone?: () => void, onFail?: () => void): void;\n };\n PermissionsAndroid?: {\n check(permission: string): Promise<boolean>;\n request(permission: string, rationale?: object): Promise<string>;\n };\n StatusBar: {\n /** Android reports the bar's height in dp; iOS leaves it undefined. */\n currentHeight?: number;\n setBarStyle(style: string, animated?: boolean): void;\n setHidden(hidden: boolean, animation?: string): void;\n setBackgroundColor(color: string, animated?: boolean): void;\n setTranslucent(translucent: boolean): void;\n };\n Linking: {\n getInitialURL(): Promise<string | null>;\n openURL(url: string): Promise<unknown>;\n openSettings(): Promise<void>;\n addEventListener(event: 'url', handler: (event: { url: string }) => void): { remove(): void };\n };\n}\n\n/** What RN hands a keyboard listener. */\nexport interface NativeKeyboardEvent {\n readonly endCoordinates: { readonly height: number; readonly screenY: number };\n readonly duration?: number;\n /** One of `LayoutEasing`'s names; usually `'keyboard'` on iOS, and always on Android, with a zero duration. */\n readonly easing?: string;\n}\n\n/**\n * `null` off a device, where each capability falls back to doing nothing - the same as an\n * optional injection token nobody provided.\n *\n * The engine's presence is what tells the two apart. In Node and in a browser there is no\n * `nativeFabricUIManager`; on a device there is one, and a missing `require` would mean the bundler\n * stopped emitting CommonJS under us. That is worth saying out loud rather than quietly rendering\n * an app whose keyboard never moves.\n *\n * `require` alone cannot tell them apart: a browser bundle can have one. Rolldown gives a `vite\n * build` its own `require` for an external module, which passes `typeof require === 'function'`\n * and throws when called.\n */\nexport function reactNative(): ReactNative | null {\n if ((globalThis as { nativeFabricUIManager?: unknown }).nativeFabricUIManager === undefined) {\n return null;\n }\n // `require` has a type only where the app's tsconfig loads Node's or React Native's types, and\n // a browser app's loads neither. `@ts-expect-error` would fail where it does.\n // @ts-ignore\n if (typeof require === 'function') return require('react-native') as ReactNative;\n console.error(\n '[angular-native] react-native could not be required, so every platform capability is ' +\n 'inert. The bundle is not CommonJS; check the Metro transform.',\n );\n return null;\n}\n"]}
|
package/dist/status-bar.d.ts
CHANGED
|
@@ -25,9 +25,20 @@ export interface StatusBarState {
|
|
|
25
25
|
readonly style?: StatusBarStyle;
|
|
26
26
|
readonly hidden?: boolean;
|
|
27
27
|
readonly animated?: boolean;
|
|
28
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* Android only: the bar's own background. iOS has no such thing.
|
|
30
|
+
*
|
|
31
|
+
* @deprecated Has no effect. Android apps on Expo SDK 57 draw edge-to-edge, where the status bar
|
|
32
|
+
* has no background of its own and React Native ignores the change. Draw a view behind the bar
|
|
33
|
+
* instead. Never sent on iOS.
|
|
34
|
+
*/
|
|
29
35
|
readonly backgroundColor?: string;
|
|
30
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* Android only: whether content draws underneath the bar.
|
|
38
|
+
*
|
|
39
|
+
* @deprecated Has no effect. Android apps on Expo SDK 57 draw edge-to-edge, so content is always
|
|
40
|
+
* underneath the bar and React Native ignores the change. Never sent on iOS.
|
|
41
|
+
*/
|
|
31
42
|
readonly translucent?: boolean;
|
|
32
43
|
}
|
|
33
44
|
/** Where the bar actually is. A fake stands in for the platform in tests. */
|
|
@@ -38,6 +49,11 @@ export interface StatusBarSource {
|
|
|
38
49
|
setTranslucent(translucent: boolean): void;
|
|
39
50
|
/** Android reports one; iOS does not, where the safe-area inset is the number that matters. */
|
|
40
51
|
readonly height: number | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Android: react-native-screens sets the bar again each time a screen appears, from that screen's
|
|
54
|
+
* own props or, with none, to light text and shown. So a claim has to ride on every screen too.
|
|
55
|
+
*/
|
|
56
|
+
readonly screensSetBar?: boolean;
|
|
41
57
|
}
|
|
42
58
|
export declare function statusBarSource(): StatusBarSource;
|
|
43
59
|
/**
|
|
@@ -60,6 +76,15 @@ export declare class StatusBar {
|
|
|
60
76
|
* wants is the safe-area top inset, which `SafeArea` has.
|
|
61
77
|
*/
|
|
62
78
|
readonly height: Signal<number>;
|
|
79
|
+
/**
|
|
80
|
+
* What a screen with no style or visibility of its own carries, so the claim is still what shows
|
|
81
|
+
* when it appears. Empty but on Android, where a screen appearing sets the bar from its own props
|
|
82
|
+
* and falls back to light text otherwise. The router passes it on.
|
|
83
|
+
*/
|
|
84
|
+
readonly forScreens: Signal<{
|
|
85
|
+
readonly style?: PlatformStatusBarStyle;
|
|
86
|
+
readonly hidden?: boolean;
|
|
87
|
+
}>;
|
|
63
88
|
constructor();
|
|
64
89
|
/** The base claim, for an app that sets the bar once at startup. */
|
|
65
90
|
set(state: StatusBarState): void;
|
package/dist/status-bar.js
CHANGED
|
@@ -28,16 +28,50 @@ export function statusBarSource() {
|
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
const { StatusBar } = native;
|
|
31
|
+
const android = native.Platform?.OS === 'android';
|
|
32
|
+
// Android 16 draws an app targeting SDK 35 or later edge-to-edge whatever its theme says. Before
|
|
33
|
+
// it, a theme can opt out, and React Native's own answer is the flag its status bar module
|
|
34
|
+
// checks. That answer is not enough on its own: Expo Go on Android 16 reports false.
|
|
35
|
+
const info = native.TurboModuleRegistry?.get('DeviceInfo');
|
|
36
|
+
const edgeToEdge = android &&
|
|
37
|
+
(Number(native.Platform.Version) >= 36 || info?.getConstants?.().isEdgeToEdge === true);
|
|
38
|
+
const warned = new Set();
|
|
31
39
|
return {
|
|
32
40
|
setStyle: (style, animated) => StatusBar.setBarStyle(BAR_STYLES[style], animated),
|
|
33
41
|
setHidden: (hidden, animation) => StatusBar.setHidden(hidden, animation),
|
|
34
|
-
setBackgroundColor: (color, animated) =>
|
|
35
|
-
|
|
42
|
+
setBackgroundColor: (color, animated) => {
|
|
43
|
+
if (!android)
|
|
44
|
+
return;
|
|
45
|
+
if (edgeToEdge)
|
|
46
|
+
warnNoEffect('backgroundColor', warned);
|
|
47
|
+
StatusBar.setBackgroundColor(color, animated);
|
|
48
|
+
},
|
|
49
|
+
setTranslucent: (translucent) => {
|
|
50
|
+
if (!android)
|
|
51
|
+
return;
|
|
52
|
+
if (edgeToEdge)
|
|
53
|
+
warnNoEffect('translucent', warned);
|
|
54
|
+
StatusBar.setTranslucent(translucent);
|
|
55
|
+
},
|
|
36
56
|
get height() {
|
|
37
57
|
return StatusBar.currentHeight;
|
|
38
58
|
},
|
|
59
|
+
screensSetBar: android,
|
|
39
60
|
};
|
|
40
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Says, once per option and in development only, that Android ignores it. React Native's own
|
|
64
|
+
* module returns early with "current activity is edge-to-edge", which only shows in logcat.
|
|
65
|
+
*/
|
|
66
|
+
function warnNoEffect(option, warned) {
|
|
67
|
+
if (typeof ngDevMode !== 'undefined' && !ngDevMode)
|
|
68
|
+
return;
|
|
69
|
+
if (warned.has(option))
|
|
70
|
+
return;
|
|
71
|
+
warned.add(option);
|
|
72
|
+
console.warn(`[angular-native] StatusBar ${option} has no effect: Android draws the app edge-to-edge, ` +
|
|
73
|
+
'so content is always under the status bar. See https://ng-native.com/guide/android-edge-to-edge');
|
|
74
|
+
}
|
|
41
75
|
/**
|
|
42
76
|
* A stack, not a setter.
|
|
43
77
|
*
|
|
@@ -62,6 +96,18 @@ export class StatusBar {
|
|
|
62
96
|
* wants is the safe-area top inset, which `SafeArea` has.
|
|
63
97
|
*/
|
|
64
98
|
height = signal(this.source.height ?? 0).asReadonly();
|
|
99
|
+
/**
|
|
100
|
+
* What a screen with no style or visibility of its own carries, so the claim is still what shows
|
|
101
|
+
* when it appears. Empty but on Android, where a screen appearing sets the bar from its own props
|
|
102
|
+
* and falls back to light text otherwise. The router passes it on.
|
|
103
|
+
*/
|
|
104
|
+
forScreens = computed(() => {
|
|
105
|
+
if (!this.source.screensSetBar)
|
|
106
|
+
return {};
|
|
107
|
+
const { style, hidden } = this.state();
|
|
108
|
+
return { style: style && resolve(style, this.scheme.current()), hidden };
|
|
109
|
+
}, /* @ts-ignore */
|
|
110
|
+
...(ngDevMode ? [{ debugName: "forScreens" }] : /* istanbul ignore next */ []));
|
|
65
111
|
constructor() {
|
|
66
112
|
// Straight from the source rather than through an effect, so an `auto` bar changes in the same
|
|
67
113
|
// turn as the scheme. The scheme is the listener's own: `ColorScheme.current` may not have
|
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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,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 /** 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"]}
|
|
1
|
+
{"version":3,"file":"status-bar.js","source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CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,IAAI,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;QAC9F,CAAC;QACD,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE,CAAC;YACnC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,IAAI,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QACxE,CAAC;QACD,IAAI,eAAe,KAAK,SAAS;YAAE,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC;QAC7F,IAAI,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,WAAW,CAAC,EAAE,CAAC;YAC7C,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,WAAW,IAAI,KAAK,CAAC,CAAC;QACnD,CAAC;IACH,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;uGA9FU,SAAS;wGAAT,SAAS;;2FAAT,SAAS;kBADrB,OAAO;;AAkGR,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 /**\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}\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 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 };\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 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 /**\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 && resolve(style, this.scheme.current()), 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 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.14.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.14.0"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"@angular/core": "^22.0.0",
|