@ng-native/device 0.23.0 → 0.24.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.
@@ -27,6 +27,9 @@ export declare class ColorScheme {
27
27
  * Put the whole app in `scheme`, whatever the system says, or back in the system's with null:
28
28
  * an in-app theme switch. The native chrome follows as well as the CSS, since it is the window's
29
29
  * own appearance that changes, and `current` and `prefers-color-scheme` follow the change.
30
+ * In an Android 12+ build with `@ng-native/components`' native module, the system keeps the
31
+ * scheme across launches until it is set again or handed back with null. On iOS, on earlier
32
+ * Android and in Expo Go each launch starts in the system's.
30
33
  */
31
34
  set(scheme: Scheme | null): void;
32
35
  constructor();
@@ -15,6 +15,16 @@ import * as i0 from "@angular/core";
15
15
  * report, when it comes, repeats the same scheme.
16
16
  */
17
17
  const setListeners = new Set();
18
+ /**
19
+ * Android's `NgNativeColorScheme`, from `@ng-native/components`: on Android 12 and later it sets the
20
+ * per-app night mode. React Native sets only AppCompat's default night mode, which an activity
21
+ * that handles `uiMode` itself (Expo's does) loses to the system's scheme shortly after launch,
22
+ * and native views would draw in the system's scheme under the app's CSS.
23
+ */
24
+ function nightModeModule() {
25
+ const modules = globalThis.expo?.modules;
26
+ return modules?.['NgNativeColorScheme'];
27
+ }
18
28
  export function colorSchemeSource() {
19
29
  const native = reactNative();
20
30
  if (!native)
@@ -43,6 +53,7 @@ export function colorSchemeSource() {
43
53
  },
44
54
  set: (scheme) => {
45
55
  native.Appearance.setColorScheme?.(scheme ?? 'unspecified');
56
+ nightModeModule()?.setColorScheme?.(scheme ?? 'unspecified');
46
57
  // Back to the system's waits for the platform's report: React Native resolves it from a
47
58
  // native cache that a full-screen modal on iOS can leave stale.
48
59
  if (scheme !== null)
@@ -64,6 +75,9 @@ export class ColorScheme {
64
75
  * Put the whole app in `scheme`, whatever the system says, or back in the system's with null:
65
76
  * an in-app theme switch. The native chrome follows as well as the CSS, since it is the window's
66
77
  * own appearance that changes, and `current` and `prefers-color-scheme` follow the change.
78
+ * In an Android 12+ build with `@ng-native/components`' native module, the system keeps the
79
+ * scheme across launches until it is set again or handed back with null. On iOS, on earlier
80
+ * Android and in Expo Go each launch starts in the system's.
67
81
  */
68
82
  set(scheme) {
69
83
  this.source.set?.(scheme);
@@ -1 +1 @@
1
- {"version":3,"file":"color-scheme.js","sourceRoot":"","sources":["../src/color-scheme.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAe,MAAM,eAAe,CAAC;AACjG,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;;AAWhD;;;;;GAKG;AACH,MAAM,YAAY,GAAG,IAAI,GAAG,EAAc,CAAC;AAE3C,MAAM,UAAU,iBAAiB;IAC/B,MAAM,MAAM,GAAG,WAAW,EAAE,CAAC;IAC7B,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,GAAE,CAAC,EAAE,CAAC;IAE1E,+DAA+D;IAC/D,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,cAAc,EAAE,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IACtF,OAAO;QACL,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,CAAC,QAAQ,EAAE,EAAE;YACtB,uFAAuF;YACvF,8CAA8C;YAC9C,IAAI,IAAI,GAAG,IAAI,EAAE,CAAC;YAClB,MAAM,QAAQ,GAAG,GAAG,EAAE;gBACpB,MAAM,MAAM,GAAG,IAAI,EAAE,CAAC;gBACtB,IAAI,MAAM,KAAK,IAAI;oBAAE,OAAO;gBAC5B,IAAI,GAAG,MAAM,CAAC;gBACd,QAAQ,CAAC,MAAM,CAAC,CAAC;YACnB,CAA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AAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC3F,CAAC;uGA1BU,WAAW;wGAAX,WAAW;;2FAAX,WAAW;kBADvB,OAAO","sourcesContent":["/**\n * Light or dark, as the user set it, or as the app sets it over them.\n *\n * Styling should use `@media (prefers-color-scheme: dark)`, which the engine resolves without\n * anything being injected. This is for the decisions CSS cannot make: which asset to load, which\n * status bar style to ask for, which of two native components to render.\n */\nimport { DestroyRef, InjectionToken, Service, inject, signal, type Signal } from '@angular/core';\nimport { reactNative } from './react-native.ts';\n\nexport type Scheme = 'light' | 'dark';\n\nexport interface ColorSchemeSource {\n current(): Scheme;\n subscribe(listener: (scheme: Scheme) => void): () => void;\n /** Put the whole app in one scheme, or back in the system's with null. */\n set?(scheme: Scheme | null): void;\n}\n\n/**\n * Every source's listeners, told of a scheme the app sets. React Native takes it at once but\n * reports it only when its root view next changes appearance, and on iOS a full-screen modal takes\n * that view out of the window, so the change arrived when the modal closed. The platform's own\n * report, when it comes, repeats the same scheme.\n */\nconst setListeners = new Set<() => void>();\n\nexport function colorSchemeSource(): ColorSchemeSource {\n const native = reactNative();\n if (!native) return { current: () => 'light', subscribe: () => () => {} };\n\n // `null` means the platform has no preference, which is light.\n const read = () => (native.Appearance.getColorScheme() === 'dark' ? 'dark' : 'light');\n return {\n current: read,\n subscribe: (listener) => {\n // Each scheme once: the platform's report repeats one the app set, and it also reports\n // appearance changes that are not the scheme.\n let last = read();\n const onChange = () => {\n const scheme = read();\n if (scheme === last) return;\n last = scheme;\n listener(scheme);\n };\n const subscription = native.Appearance.addChangeListener(onChange);\n setListeners.add(onChange);\n return () => {\n subscription.remove();\n setListeners.delete(onChange);\n };\n },\n set: (scheme) => {\n native.Appearance.setColorScheme?.(scheme ?? 'unspecified');\n // Back to the system's waits for the platform's report: React Native resolves it from a\n // native cache that a full-screen modal on iOS can leave stale.\n if (scheme !== null) for (const listener of [...setListeners]) listener();\n },\n };\n}\n\n@Service()\nexport class ColorScheme {\n /** Overridden in a test to switch the theme. */\n static readonly SOURCE = new InjectionToken<ColorSchemeSource>(\n 'angular-native.colorSchemeSource',\n { factory: colorSchemeSource },\n );\n\n private readonly source = inject(ColorScheme.SOURCE);\n\n /** Whether the service is here: on every OS, where it answers what the OS reports. */\n readonly available: Signal<boolean> = signal(true).asReadonly();\n private readonly scheme = signal<Scheme>(this.source.current());\n\n readonly current: Signal<Scheme> = this.scheme.asReadonly();\n\n /**\n * Put the whole app in `scheme`, whatever the system says, or back in the system's with null:\n * an in-app theme switch. The native chrome follows as well as the CSS, since it is the window's\n * own appearance that changes, and `current` and `prefers-color-scheme` follow the change.\n */\n set(scheme: Scheme | null): void {\n this.source.set?.(scheme);\n }\n\n constructor() {\n inject(DestroyRef).onDestroy(this.source.subscribe((scheme) => this.scheme.set(scheme)));\n }\n}\n"]}
1
+ {"version":3,"file":"color-scheme.js","sourceRoot":"","sources":["../src/color-scheme.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAe,MAAM,eAAe,CAAC;AACjG,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;;AAWhD;;;;;GAKG;AACH,MAAM,YAAY,GAAG,IAAI,GAAG,EAAc,CAAC;AAE3C;;;;;GAKG;AACH,SAAS,eAAe;IACtB,MAAM,OAAO,GAAI,UAA+D,CAAC,IAAI,EAAE,OAAO,CAAC;IAC/F,OAAO,OAAO,EAAE,CAAC,qBAAqB,CAA0D,CAAC;AACnG,CAAC;AAED,MAAM,UAAU,iBAAiB;IAC/B,MAAM,MAAM,GAAG,WAAW,EAAE,CAAC;IAC7B,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,GAAE,CAAC,EAAE,CAAC;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U,MAAM,GAAG,IAAI,cAAc,CACzC,kCAAkC,EAClC,EAAE,OAAO,EAAE,iBAAiB,EAAE,CAC/B,CAAC;IAEe,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAErD,sFAAsF;IAC7E,SAAS,GAAoB,MAAM,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,CAAC;IAC/C,MAAM,GAAG,MAAM,CAAS,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE;+EAAC,CAAC;IAEvD,OAAO,GAAmB,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;IAE5D;;;;;;;OAOG;IACH,GAAG,CAAC,MAAqB;QACvB,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC;IAC5B,CAAC;IAED;QACE,MAAM,CAAC,UAAU,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC3F,CAAC;uGA7BU,WAAW;wGAAX,WAAW;;2FAAX,WAAW;kBADvB,OAAO","sourcesContent":["/**\n * Light or dark, as the user set it, or as the app sets it over them.\n *\n * Styling should use `@media (prefers-color-scheme: dark)`, which the engine resolves without\n * anything being injected. This is for the decisions CSS cannot make: which asset to load, which\n * status bar style to ask for, which of two native components to render.\n */\nimport { DestroyRef, InjectionToken, Service, inject, signal, type Signal } from '@angular/core';\nimport { reactNative } from './react-native.ts';\n\nexport type Scheme = 'light' | 'dark';\n\nexport interface ColorSchemeSource {\n current(): Scheme;\n subscribe(listener: (scheme: Scheme) => void): () => void;\n /** Put the whole app in one scheme, or back in the system's with null. */\n set?(scheme: Scheme | null): void;\n}\n\n/**\n * Every source's listeners, told of a scheme the app sets. React Native takes it at once but\n * reports it only when its root view next changes appearance, and on iOS a full-screen modal takes\n * that view out of the window, so the change arrived when the modal closed. The platform's own\n * report, when it comes, repeats the same scheme.\n */\nconst setListeners = new Set<() => void>();\n\n/**\n * Android's `NgNativeColorScheme`, from `@ng-native/components`: on Android 12 and later it sets the\n * per-app night mode. React Native sets only AppCompat's default night mode, which an activity\n * that handles `uiMode` itself (Expo's does) loses to the system's scheme shortly after launch,\n * and native views would draw in the system's scheme under the app's CSS.\n */\nfunction nightModeModule(): { setColorScheme?(scheme: string): void } | undefined {\n const modules = (globalThis as { expo?: { modules?: Record<string, unknown> } }).expo?.modules;\n return modules?.['NgNativeColorScheme'] as { setColorScheme?(scheme: string): void } | undefined;\n}\n\nexport function colorSchemeSource(): ColorSchemeSource {\n const native = reactNative();\n if (!native) return { current: () => 'light', subscribe: () => () => {} };\n\n // `null` means the platform has no preference, which is light.\n const read = () => (native.Appearance.getColorScheme() === 'dark' ? 'dark' : 'light');\n return {\n current: read,\n subscribe: (listener) => {\n // Each scheme once: the platform's report repeats one the app set, and it also reports\n // appearance changes that are not the scheme.\n let last = read();\n const onChange = () => {\n const scheme = read();\n if (scheme === last) return;\n last = scheme;\n listener(scheme);\n };\n const subscription = native.Appearance.addChangeListener(onChange);\n setListeners.add(onChange);\n return () => {\n subscription.remove();\n setListeners.delete(onChange);\n };\n },\n set: (scheme) => {\n native.Appearance.setColorScheme?.(scheme ?? 'unspecified');\n nightModeModule()?.setColorScheme?.(scheme ?? 'unspecified');\n // Back to the system's waits for the platform's report: React Native resolves it from a\n // native cache that a full-screen modal on iOS can leave stale.\n if (scheme !== null) for (const listener of [...setListeners]) listener();\n },\n };\n}\n\n@Service()\nexport class ColorScheme {\n /** Overridden in a test to switch the theme. */\n static readonly SOURCE = new InjectionToken<ColorSchemeSource>(\n 'angular-native.colorSchemeSource',\n { factory: colorSchemeSource },\n );\n\n private readonly source = inject(ColorScheme.SOURCE);\n\n /** Whether the service is here: on every OS, where it answers what the OS reports. */\n readonly available: Signal<boolean> = signal(true).asReadonly();\n private readonly scheme = signal<Scheme>(this.source.current());\n\n readonly current: Signal<Scheme> = this.scheme.asReadonly();\n\n /**\n * Put the whole app in `scheme`, whatever the system says, or back in the system's with null:\n * an in-app theme switch. The native chrome follows as well as the CSS, since it is the window's\n * own appearance that changes, and `current` and `prefers-color-scheme` follow the change.\n * In an Android 12+ build with `@ng-native/components`' native module, the system keeps the\n * scheme across launches until it is set again or handed back with null. On iOS, on earlier\n * Android and in Expo Go each launch starts in the system's.\n */\n set(scheme: Scheme | null): void {\n this.source.set?.(scheme);\n }\n\n constructor() {\n inject(DestroyRef).onDestroy(this.source.subscribe((scheme) => this.scheme.set(scheme)));\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ng-native/device",
3
- "version": "0.23.0",
3
+ "version": "0.24.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.23.0"
20
+ "@ng-native/fabric": "0.24.0"
21
21
  },
22
22
  "peerDependencies": {
23
23
  "@angular/core": "^22.0.0",