@ng-native/device 0.2.0 → 0.3.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/README.md +16 -34
- package/dist/conditions.js +12 -13
- package/dist/conditions.js.map +1 -1
- package/dist/dev-menu.js +32 -4
- package/dist/dev-menu.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/layout-animation.js +7 -1
- package/dist/layout-animation.js.map +1 -1
- package/dist/react-native.d.ts +8 -4
- package/dist/react-native.js +13 -8
- package/dist/react-native.js.map +1 -1
- package/dist/status-bar.d.ts +11 -3
- package/dist/status-bar.js +24 -4
- package/dist/status-bar.js.map +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -33,42 +33,24 @@ export class Composer {
|
|
|
33
33
|
Nothing is provided anywhere. Each service declares its own factory, so injecting it is the whole
|
|
34
34
|
setup, and one nobody injects is never constructed.
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
| --------------- | ---------------------------------------------------------------------- |
|
|
38
|
-
| `Keyboard` | `height`, `visible` and the full `metrics`, plus `dismiss()`. |
|
|
39
|
-
| `Screen` | `window`, `display` and `orientation`, following a rotation. |
|
|
40
|
-
| `ColorScheme` | `current`: light or dark, as the user set it. |
|
|
41
|
-
| `AppState` | `current` and `active`: whether the app is in front of the user. |
|
|
42
|
-
| `Accessibility` | `screenReader`, `reduceMotion`, `boldText`, and `announce()`. |
|
|
43
|
-
| `HardwareBack` | `handle()`: Android's back button, answering whether it was consumed. |
|
|
44
|
-
| `DeepLinks` | `initialUrl()`, `subscribe()` and `open()`, as paths rather than urls. |
|
|
36
|
+
## What's in the package
|
|
45
37
|
|
|
46
|
-
|
|
38
|
+
- `Screen`, `SafeArea` - the window, the physical display, orientation and safe-area insets.
|
|
39
|
+
- `ColorScheme`, `Accessibility`, `Direction` - light or dark, screen reader and reduced-motion
|
|
40
|
+
state, and text direction.
|
|
41
|
+
- `StatusBar`, `Keyboard`, `HardwareBack`, `AppState`, `DeepLinks`, `AndroidPermissions`,
|
|
42
|
+
`LayoutAnimation` - the rest of the system surfaces a screen reads from.
|
|
43
|
+
- `Dialogs`, `Sharing`, `Vibration` - the platform's own alert, share sheet and vibration motor.
|
|
44
|
+
- `DevMenu` - switches in the shake menu, gone in a release build.
|
|
47
45
|
|
|
48
|
-
|
|
49
|
-
`(min-width: …)` and `(prefers-reduced-motion: reduce)` from the same values, so styling should use
|
|
50
|
-
a media query and leave these services for the decisions CSS cannot make - which asset to load,
|
|
51
|
-
which native component to render, whether to announce something. `watchConditions(engine)` is what
|
|
52
|
-
keeps the engine in step; an app calls it once, next to `mount`.
|
|
46
|
+
## Docs
|
|
53
47
|
|
|
54
|
-
|
|
48
|
+
- [Device](https://ng-native.com/packages/device)
|
|
49
|
+
- [Testing with services](https://ng-native.com/packages/testing/testing-services), for
|
|
50
|
+
overriding a service's `SOURCE` token without a device underneath it
|
|
51
|
+
- [Root README](https://github.com/ng-native/ng-native/blob/main/README.md) and
|
|
52
|
+
[ARCHITECTURE.md](https://github.com/ng-native/ng-native/blob/main/docs/ARCHITECTURE.md)
|
|
55
53
|
|
|
56
|
-
|
|
57
|
-
overrides the token rather than the service and the code under test stays real:
|
|
54
|
+
## License
|
|
58
55
|
|
|
59
|
-
|
|
60
|
-
mount(1, App, fabric, {
|
|
61
|
-
providers: [
|
|
62
|
-
{ provide: Keyboard.SOURCE, useValue: { subscribe: fakeKeyboard, dismiss: () => {} } },
|
|
63
|
-
],
|
|
64
|
-
});
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
## Off a device
|
|
68
|
-
|
|
69
|
-
`react-native` is required lazily, inside each source, because React Native ships its JavaScript as
|
|
70
|
-
Flow and a static import would make this package - and `@ng-native/components`, which imports
|
|
71
|
-
it - unloadable in Node. Off a device the require finds nothing and every capability is inert: the
|
|
72
|
-
keyboard is never visible, the screen is zero by zero, a back handler is never called. That is the
|
|
73
|
-
same behavior as not providing the token that used to stand here, and it is what lets the test
|
|
74
|
-
suite import any of this without a simulator.
|
|
56
|
+
MIT
|
package/dist/conditions.js
CHANGED
|
@@ -16,6 +16,7 @@ export function currentConditions() {
|
|
|
16
16
|
// corrects it. Reduced motion is a preference about what happens next, not about the frame
|
|
17
17
|
// already on screen, so nothing is lost by learning it a tick late.
|
|
18
18
|
reducedMotion: false,
|
|
19
|
+
fontScale: fontScale(),
|
|
19
20
|
};
|
|
20
21
|
}
|
|
21
22
|
/**
|
|
@@ -58,24 +59,22 @@ export function watchConditions(engine, options = {}) {
|
|
|
58
59
|
if (options.darkClass !== false && conditions.colorScheme === 'dark')
|
|
59
60
|
push({});
|
|
60
61
|
// The system text size. Every text on screen was measured at the old one, and keeps that box
|
|
61
|
-
// until it is measured again, so a change
|
|
62
|
-
// A change arrives as a `Dimensions` change on both platforms; the app coming back to the
|
|
62
|
+
// until it is measured again, so a change goes into the conditions and then re-measures them
|
|
63
|
+
// all. A change arrives as a `Dimensions` change on both platforms; the app coming back to the
|
|
63
64
|
// foreground is checked as well, and the same change reported by both is re-measured once.
|
|
64
|
-
let scale = fontScale
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
return;
|
|
65
|
+
let scale = conditions.fontScale ?? 1;
|
|
66
|
+
const resize = (change, next) => {
|
|
67
|
+
const rescaled = next !== scale;
|
|
68
68
|
scale = next;
|
|
69
|
-
|
|
69
|
+
push({ ...change, fontScale: next });
|
|
70
|
+
if (rescaled)
|
|
71
|
+
engine.remeasureText?.();
|
|
70
72
|
};
|
|
71
|
-
const sizes = screen.subscribe(({ window }) => {
|
|
72
|
-
rescale(fontScale());
|
|
73
|
-
push({ width: window.width, height: window.height });
|
|
74
|
-
});
|
|
73
|
+
const sizes = screen.subscribe(({ window }) => resize({ width: window.width, height: window.height }, fontScale()));
|
|
75
74
|
const scheme = colors.subscribe((colorScheme) => push({ colorScheme }));
|
|
76
75
|
const settings = accessibility.subscribe((change) => {
|
|
77
|
-
if (change.fontScale !== undefined)
|
|
78
|
-
|
|
76
|
+
if (change.fontScale !== undefined && change.fontScale !== scale)
|
|
77
|
+
resize({}, change.fontScale);
|
|
79
78
|
if (change.reduceMotion !== undefined)
|
|
80
79
|
push({ reducedMotion: change.reduceMotion });
|
|
81
80
|
});
|
package/dist/conditions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conditions.js","sourceRoot":"","sources":["../src/conditions.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAYhD,+DAA+D;AAC/D,SAAS,SAAS;IAChB,OAAO,WAAW,EAAE,EAAE,UAAU,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;AACvD,CAAC;AAWD,MAAM,UAAU,iBAAiB;IAC/B,MAAM,EAAE,MAAM,EAAE,GAAG,YAAY,EAAE,CAAC,OAAO,EAAE,CAAC;IAC5C,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,WAAW,EAAE,iBAAiB,EAAE,CAAC,OAAO,EAAE;QAC1C,8FAA8F;QAC9F,2FAA2F;QAC3F,oEAAoE;QACpE,aAAa,EAAE,KAAK;
|
|
1
|
+
{"version":3,"file":"conditions.js","sourceRoot":"","sources":["../src/conditions.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAYhD,+DAA+D;AAC/D,SAAS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AAC,EAAE,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC;QAC/F,IAAI,MAAM,CAAC,YAAY,KAAK,SAAS;YAAE,IAAI,CAAC,EAAE,aAAa,EAAE,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC;IACtF,CAAC,CAAC,CAAC;IACH,KAAK,aAAa;SACf,OAAO,EAAE;SACT,IAAI,CAAC,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,YAAY,IAAI,IAAI,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAE7E,OAAO,GAAG,EAAE;QACV,KAAK,EAAE,CAAC;QACR,MAAM,EAAE,CAAC;QACT,QAAQ,EAAE,CAAC;IACb,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/**\n * What the engine evaluates media queries against, kept in step with the device.\n *\n * Not a service, because the engine is not injectable and has no reason to be: it is handed to\n * `mount` and handed back, and this connects the two. An app that wants `@media` to keep working\n * after a rotation or a theme change calls `watchConditions` once and never thinks about it again.\n *\n * A rotation changes no component and no binding, so nothing would be dirty and nothing would\n * re-render. The engine re-resolves and commits on its own when the conditions change.\n */\nimport type { Conditions, TokenValue } from '@ng-native/fabric';\nimport { accessibilitySource } from './accessibility.ts';\nimport { colorSchemeSource } from './color-scheme.ts';\nimport { screenSource } from './screen.ts';\nimport { reactNative } from './react-native.ts';\n\n/** Just enough of the engine to be told. */\ninterface Resolves<Node = unknown> {\n readonly root: Node;\n updateConditions(conditions: Conditions): void;\n addClass(node: Node, name: string): void;\n removeClass(node: Node, name: string): void;\n /** Measure every text again, after the system text size changed. */\n remeasureText?(): void;\n}\n\n/** The system text size, as a multiplier. One off a device. */\nfunction fontScale(): number {\n return reactNative()?.PixelRatio.getFontScale() ?? 1;\n}\n\nexport interface WatchOptions {\n /**\n * Keep a `dark` class on the root in step with the system scheme, which is what\n * `@ng-native/tailwind`'s `dark:` variant matches. On by default; an app with its own theme\n * switch turns it off and puts `dark` on its own root view instead.\n */\n readonly darkClass?: boolean;\n}\n\nexport function currentConditions(): Conditions {\n const { window } = screenSource().current();\n return {\n width: window.width,\n height: window.height,\n colorScheme: colorSchemeSource().current(),\n // Asynchronous on both platforms, so the first paint says no preference and `watchConditions`\n // corrects it. Reduced motion is a preference about what happens next, not about the frame\n // already on screen, so nothing is lost by learning it a tick late.\n reducedMotion: false,\n fontScale: fontScale(),\n };\n}\n\n/**\n * Custom properties the device settles before the first frame, for `mount`'s `tokens` option.\n *\n * Only the hairline so far: the thinnest line the screen can draw, which is a third of a point on\n * a 3x phone and half of one on a 2x. `1px` is what a browser would give and is a visibly fat\n * divider on a modern screen, so a native-looking rule has to ask. React Native works the number\n * out from the pixel ratio; off a device there is no answer, and inventing one would be a line of\n * the wrong weight in every test that draws one.\n *\n * Not watched, unlike the conditions: the pixel density of a screen does not change while an app\n * is open. The safe-area insets are the opposite case and arrive through `updateTokens`.\n */\nexport function deviceTokens(): Record<string, TokenValue> {\n const native = reactNative();\n return native ? { '--hairline': { length: native.StyleSheet.hairlineWidth } } : {};\n}\n\n/**\n * Keep the engine's conditions current. Returns an unsubscribe, though an app that calls this at\n * bootstrap will never use it.\n */\nexport function watchConditions<Node>(\n engine: Resolves<Node>,\n options: WatchOptions = {},\n): () => void {\n const screen = screenSource();\n const colors = colorSchemeSource();\n const accessibility = accessibilitySource();\n\n let conditions = currentConditions();\n const push = (change: Partial<Conditions>) => {\n conditions = { ...conditions, ...change };\n if (options.darkClass !== false) {\n if (conditions.colorScheme === 'dark') engine.addClass(engine.root, 'dark');\n else engine.removeClass(engine.root, 'dark');\n }\n engine.updateConditions(conditions);\n };\n // The class for the scheme the app started in, committed at once. Light needs nothing: an app\n // starting light is exactly what it already rendered.\n if (options.darkClass !== false && conditions.colorScheme === 'dark') push({});\n\n // The system text size. Every text on screen was measured at the old one, and keeps that box\n // until it is measured again, so a change goes into the conditions and then re-measures them\n // all. A change arrives as a `Dimensions` change on both platforms; the app coming back to the\n // foreground is checked as well, and the same change reported by both is re-measured once.\n let scale = conditions.fontScale ?? 1;\n const resize = (change: Partial<Conditions>, next: number) => {\n const rescaled = next !== scale;\n scale = next;\n push({ ...change, fontScale: next });\n if (rescaled) engine.remeasureText?.();\n };\n\n const sizes = screen.subscribe(({ window }) =>\n resize({ width: window.width, height: window.height }, fontScale()),\n );\n const scheme = colors.subscribe((colorScheme) => push({ colorScheme }));\n const settings = accessibility.subscribe((change) => {\n if (change.fontScale !== undefined && change.fontScale !== scale) resize({}, change.fontScale);\n if (change.reduceMotion !== undefined) push({ reducedMotion: change.reduceMotion });\n });\n void accessibility\n .current()\n .then(({ reduceMotion }) => reduceMotion && push({ reducedMotion: true }));\n\n return () => {\n sizes();\n scheme();\n settings();\n };\n}\n"]}
|
package/dist/dev-menu.js
CHANGED
|
@@ -12,13 +12,41 @@
|
|
|
12
12
|
import { InjectionToken, Service, inject } from '@angular/core';
|
|
13
13
|
import { reactNative } from "./react-native.js";
|
|
14
14
|
import * as i0 from "@angular/core";
|
|
15
|
+
/**
|
|
16
|
+
* React Native's menu, reloading the way Metro's Fast Refresh runtime does.
|
|
17
|
+
*
|
|
18
|
+
* `DevSettings.reload()` brings an app in Expo Go back without Expo's native modules (`Cannot find
|
|
19
|
+
* native module 'ExpoFontLoader'`) until Expo Go is relaunched. In development `@ng-native/platform`
|
|
20
|
+
* routes the refresh runtime's full reload through Expo's `reloadAppAsync()` in an Expo app, falling
|
|
21
|
+
* back to React Native's, so this reloads through it. Neither this package nor the bundle it is in
|
|
22
|
+
* names `expo` for that: an app on the web, or without Expo, has none to resolve. Outside
|
|
23
|
+
* development, or without the runtime, it is React Native's reload, which does nothing in a release
|
|
24
|
+
* build, where Expo's would restart the app.
|
|
25
|
+
*/
|
|
26
|
+
function throughRefreshRuntime(settings) {
|
|
27
|
+
return {
|
|
28
|
+
addMenuItem: (title, handler) => settings.addMenuItem(title, handler),
|
|
29
|
+
reload: (reason) => {
|
|
30
|
+
const scope = globalThis;
|
|
31
|
+
const refresh = scope[`${scope.__METRO_GLOBAL_PREFIX__ ?? ''}__ReactRefresh`];
|
|
32
|
+
if (scope.__DEV__ === true && refresh?.performFullRefresh) {
|
|
33
|
+
refresh.performFullRefresh(reason ?? 'requested by the app');
|
|
34
|
+
}
|
|
35
|
+
else
|
|
36
|
+
settings.reload(reason);
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
15
40
|
export class DevMenu {
|
|
16
41
|
/** Overridden in a test to register items without a shake menu. */
|
|
17
42
|
static SOURCE = new InjectionToken('angular-native.devMenuSource', {
|
|
18
|
-
factory: () =>
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
43
|
+
factory: () => {
|
|
44
|
+
const settings = reactNative()?.DevSettings;
|
|
45
|
+
return {
|
|
46
|
+
menu: settings ? throughRefreshRuntime(settings) : null,
|
|
47
|
+
development: globalThis.__DEV__ === true,
|
|
48
|
+
};
|
|
49
|
+
},
|
|
22
50
|
});
|
|
23
51
|
source = inject(DevMenu.SOURCE);
|
|
24
52
|
/** Whether anything registered here will appear. False in a release build. */
|
package/dist/dev-menu.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev-menu.js","sourceRoot":"","sources":["../src/dev-menu.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;;
|
|
1
|
+
{"version":3,"file":"dev-menu.js","sourceRoot":"","sources":["../src/dev-menu.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;;AAkBhD;;;;;;;;;;GAUG;AACH,SAAS,qBAAqB,CAAC,QAAuB;IACpD,OAAO;QACL,WAAW,EAAE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,CAAC,IAAK,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAChD,CAAC;IAED,sDAAsD;IACtD,MAAM,CAAC,MAAM,GAAG,sBAAsB;QACpC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACnC,CAAC;uGApCU,OAAO;wGAAP,OAAO;;2FAAP,OAAO;kBADnB,OAAO","sourcesContent":["/**\n * The developer menu, for the switches an app wants while it is being built.\n *\n * A feature flag, a fake slow network, \"log the current state\", \"clear the database\" - the things\n * a team otherwise builds a hidden settings screen for and then has to remember not to ship. These\n * go in the shake menu, which does not exist in a release build, so neither do they.\n *\n * `__DEV__` is checked rather than assumed: `DevSettings` exists in a release bundle and its\n * `addMenuItem` is a no-op there, but an app that registers twenty of them is still doing twenty\n * things at startup for no reason.\n */\n\nimport { InjectionToken, Service, inject } from '@angular/core';\nimport { reactNative } from './react-native.ts';\n\nexport interface NativeDevMenu {\n addMenuItem(title: string, handler: () => unknown): void;\n reload(reason?: string): void;\n}\n\n/**\n * The menu, and whether there is one to add to.\n *\n * `__DEV__` travels with the module rather than being read from the global inside the class, so a\n * test can say \"this is a release build\" without writing to `globalThis` and putting it back.\n */\nexport interface DevMenuSource {\n readonly menu: NativeDevMenu | null;\n readonly development: boolean;\n}\n\n/**\n * React Native's menu, reloading the way Metro's Fast Refresh runtime does.\n *\n * `DevSettings.reload()` brings an app in Expo Go back without Expo's native modules (`Cannot find\n * native module 'ExpoFontLoader'`) until Expo Go is relaunched. In development `@ng-native/platform`\n * routes the refresh runtime's full reload through Expo's `reloadAppAsync()` in an Expo app, falling\n * back to React Native's, so this reloads through it. Neither this package nor the bundle it is in\n * names `expo` for that: an app on the web, or without Expo, has none to resolve. Outside\n * development, or without the runtime, it is React Native's reload, which does nothing in a release\n * build, where Expo's would restart the app.\n */\nfunction throughRefreshRuntime(settings: NativeDevMenu): NativeDevMenu {\n return {\n addMenuItem: (title, handler) => settings.addMenuItem(title, handler),\n reload: (reason) => {\n const scope = globalThis as {\n __METRO_GLOBAL_PREFIX__?: string;\n __DEV__?: boolean;\n } & Record<string, unknown>;\n const refresh = scope[`${scope.__METRO_GLOBAL_PREFIX__ ?? ''}__ReactRefresh`] as\n { performFullRefresh?: (reason: string) => void } | undefined;\n if (scope.__DEV__ === true && refresh?.performFullRefresh) {\n refresh.performFullRefresh(reason ?? 'requested by the app');\n } else settings.reload(reason);\n },\n };\n}\n\n@Service()\nexport class DevMenu {\n /** Overridden in a test to register items without a shake menu. */\n static readonly SOURCE = new InjectionToken<DevMenuSource>('angular-native.devMenuSource', {\n factory: () => {\n const settings = reactNative()?.DevSettings;\n return {\n menu: settings ? throughRefreshRuntime(settings) : null,\n development: (globalThis as { __DEV__?: boolean }).__DEV__ === true,\n };\n },\n });\n\n private readonly source = inject(DevMenu.SOURCE);\n\n /** Whether anything registered here will appear. False in a release build. */\n get available(): boolean {\n return this.source.development && this.source.menu !== null;\n }\n\n /**\n * Add an item to the shake menu.\n *\n * `DevSettings.addMenuItem` already keys on `title` and swaps in the new handler without adding\n * a second native entry - it removes its own previous listener for that title before adding the\n * one just given - so registering the same title again, as a hot reload does when it re-runs the\n * constructor that calls `add()`, is exactly how the fresh handler replaces the stale one rather\n * than being silently dropped.\n */\n add(title: string, handler: () => unknown): void {\n if (!this.available) return;\n this.source.menu!.addMenuItem(title, handler);\n }\n\n /** Reload the bundle, as the menu's own item does. */\n reload(reason = 'requested by the app'): void {\n this.source.menu?.reload(reason);\n }\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -19,8 +19,8 @@ export { Sharing, type NativeSharing, type ShareRequest } from './sharing.ts';
|
|
|
19
19
|
export { Vibration, type NativeVibration } from './vibration.ts';
|
|
20
20
|
export { HardwareBack, hardwareBackSource, type HardwareBackSource } from './hardware-back.ts';
|
|
21
21
|
export { Keyboard, type KeyboardMetrics, type KeyboardSource } from './keyboard.ts';
|
|
22
|
-
export {
|
|
22
|
+
export type { NativeKeyboardEvent } from './react-native.ts';
|
|
23
23
|
export { SafeArea, type Frame, type Insets } from './safe-area.ts';
|
|
24
24
|
export { COMPACT_WIDTH, Screen, type ScreenSource, type Size, type Sizes } from './screen.ts';
|
|
25
|
-
export { StatusBar, statusBarSource, type StatusBarSource, type StatusBarState, type StatusBarStyle, } from './status-bar.ts';
|
|
25
|
+
export { StatusBar, statusBarSource, type PlatformStatusBarStyle, type StatusBarSource, type StatusBarState, type StatusBarStyle, } from './status-bar.ts';
|
|
26
26
|
export { SCREEN_IN_FRONT } from './screen-in-front.ts';
|
package/dist/index.js
CHANGED
|
@@ -19,7 +19,6 @@ export { Sharing } from "./sharing.js";
|
|
|
19
19
|
export { Vibration } from "./vibration.js";
|
|
20
20
|
export { HardwareBack, hardwareBackSource } from "./hardware-back.js";
|
|
21
21
|
export { Keyboard } from "./keyboard.js";
|
|
22
|
-
export { reactNative } from "./react-native.js";
|
|
23
22
|
export { SafeArea } from "./safe-area.js";
|
|
24
23
|
export { COMPACT_WIDTH, Screen } from "./screen.js";
|
|
25
24
|
export { StatusBar, statusBarSource, } from "./status-bar.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EACL,aAAa,GAGd,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAuC,MAAM,gBAAgB,CAAC;AAC/E,OAAO,EAAE,WAAW,EAAuC,MAAM,mBAAmB,CAAC;AACrF,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,eAAe,GAEhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,SAAS,EAAE,MAAM,EAAuB,MAAM,iBAAiB,CAAC;AACzE,OAAO,EACL,SAAS,GAIV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,iBAAiB,GAGlB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE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AQ,EAA2B,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,EAA4C,MAAM,aAAa,CAAC;AAC9F,OAAO,EACL,SAAS,EACT,eAAe,GAKhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC","sourcesContent":["/**\n * The host: the device, the operating system, and the user's settings.\n *\n * Every capability here is a service with its own factory, so injecting one is the whole setup\n * and one nobody injects is never constructed. Off a device each falls back to doing nothing,\n * which is what makes the whole package importable by the test suite.\n */\nexport {\n Accessibility,\n type AccessibilitySettings,\n type AccessibilitySource,\n} from './accessibility.ts';\nexport { AppState, type AppStateSource, type AppStatus } from './app-state.ts';\nexport { ColorScheme, type ColorSchemeSource, type Scheme } from './color-scheme.ts';\nexport {\n currentConditions,\n deviceTokens,\n watchConditions,\n type WatchOptions,\n} from './conditions.ts';\nexport { DeepLinks, pathOf, type DeepLinkSource } from './deep-links.ts';\nexport {\n Direction,\n type DirectionContext,\n type DirectionSource,\n type LayoutDirection,\n} from './direction.ts';\nexport {\n androidPermission,\n type AndroidPermissions,\n type PermissionAnswer,\n} from './android-permissions.ts';\nexport { DevMenu, type DevMenuSource, type NativeDevMenu } from './dev-menu.ts';\nexport { Dialogs, type Choice, type NativeDialogs } from './dialogs.ts';\nexport {\n LayoutAnimation,\n type LayoutChange,\n type LayoutEasing,\n type NativeLayoutAnimation,\n} from './layout-animation.ts';\nexport { Sharing, type NativeSharing, type ShareRequest } from './sharing.ts';\nexport { Vibration, type NativeVibration } from './vibration.ts';\nexport { HardwareBack, hardwareBackSource, type HardwareBackSource } from './hardware-back.ts';\nexport { Keyboard, type KeyboardMetrics, type KeyboardSource } from './keyboard.ts';\nexport type { NativeKeyboardEvent } from './react-native.ts';\nexport { SafeArea, type Frame, type Insets } from './safe-area.ts';\nexport { COMPACT_WIDTH, Screen, type ScreenSource, type Size, type Sizes } from './screen.ts';\nexport {\n StatusBar,\n statusBarSource,\n type PlatformStatusBarStyle,\n type StatusBarSource,\n type StatusBarState,\n type StatusBarStyle,\n} from './status-bar.ts';\nexport { SCREEN_IN_FRONT } from './screen-in-front.ts';\n"]}
|
package/dist/layout-animation.js
CHANGED
|
@@ -16,6 +16,12 @@ import { InjectionToken, Service, inject } from '@angular/core';
|
|
|
16
16
|
import { reactNative } from "./react-native.js";
|
|
17
17
|
import * as i0 from "@angular/core";
|
|
18
18
|
const DEFAULTS = { duration: 300, easing: 'easeInEaseOut' };
|
|
19
|
+
/**
|
|
20
|
+
* How long past its duration an animation is given before `animate` resolves without its
|
|
21
|
+
* completion, which Android never calls: a few frames of slack, so that on iOS its own completion,
|
|
22
|
+
* which lands at the end of the duration, is the one that resolves it.
|
|
23
|
+
*/
|
|
24
|
+
const COMPLETION_GRACE_MS = 50;
|
|
19
25
|
/**
|
|
20
26
|
* `inject(LayoutAnimation).animate(() => this.rows.update(...))`.
|
|
21
27
|
*
|
|
@@ -42,7 +48,7 @@ export class LayoutAnimation {
|
|
|
42
48
|
const done = new Promise((resolve) => {
|
|
43
49
|
this.native.configureNext(config(options), resolve);
|
|
44
50
|
// Android does not call the completion, so nothing should wait on it forever.
|
|
45
|
-
setTimeout(resolve, (options.duration ?? DEFAULTS.duration) +
|
|
51
|
+
setTimeout(resolve, (options.duration ?? DEFAULTS.duration) + COMPLETION_GRACE_MS);
|
|
46
52
|
});
|
|
47
53
|
change();
|
|
48
54
|
await done;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layout-animation.js","sourceRoot":"","sources":["../src/layout-animation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;;AAsBhD,MAAM,QAAQ,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,eAA+B,EAAE,CAAC;AAE5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AG,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,CAAC;QAC5E,GAAG,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,CAAC;KAC3E,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Animating a layout *change*, which CSS cannot express.\n *\n * A transition animates a property from one value to another, and the engine already does that. It\n * cannot animate a layout: when a row is removed and the rows below move up, nothing about those\n * rows changed - their `top` was never set, Yoga computed it, and there is no old value to\n * transition from. The web solves this with FLIP, measuring before and after in JavaScript; native\n * solves it in the shadow tree, which is where the two layouts both exist.\n *\n * So this is not a nicer `LayoutAnimation` - it is the only way to say the thing at all. What it\n * adds is the promise, and the scope: `configureNext` applies to the next commit *whenever that\n * happens*, so a call that is not immediately followed by a change animates whatever change comes\n * next, which may be an unrelated screen appearing.\n */\n\nimport { InjectionToken, Service, inject } from '@angular/core';\nimport { reactNative } from './react-native.ts';\n\n/**\n * How a change is eased. `spring` is the platform's own, and is what a native list uses.\n * `keyboard` is the curve iOS moves its keyboard on, which a keyboard event reports by that name.\n */\nexport type LayoutEasing =\n 'spring' | 'linear' | 'easeInEaseOut' | 'easeIn' | 'easeOut' | 'keyboard';\n\nexport interface LayoutChange {\n readonly duration?: number;\n readonly easing?: LayoutEasing;\n /** What a view appearing does. `opacity` fades it in; the default is to scale it up. */\n readonly appear?: 'opacity' | 'scaleXY' | 'none';\n /** What a view leaving does. */\n readonly leave?: 'opacity' | 'scaleXY' | 'none';\n}\n\nexport interface NativeLayoutAnimation {\n configureNext(config: object, onDone?: () => void): void;\n}\n\nconst DEFAULTS = { duration: 300, easing: 'easeInEaseOut' as LayoutEasing };\n\n/**\n * How long past its duration an animation is given before `animate` resolves without its\n * completion, which Android never calls: a few frames of slack, so that on iOS its own completion,\n * which lands at the end of the duration, is the one that resolves it.\n */\nconst COMPLETION_GRACE_MS = 50;\n\n/**\n * `inject(LayoutAnimation).animate(() => this.rows.update(...))`.\n *\n * The only way to say \"animate the layout this change produces\": a transition needs a value to\n * animate from, and a row that moves up because the one above it left never had one.\n */\n@Service()\nexport class LayoutAnimation {\n /** Overridden in a test to watch a configuration without one being applied. */\n static readonly SOURCE = new InjectionToken<NativeLayoutAnimation | null>(\n 'angular-native.layoutAnimationSource',\n { factory: () => reactNative()?.LayoutAnimation ?? null },\n );\n\n private readonly native = inject(LayoutAnimation.SOURCE);\n\n /**\n * Animate the layout the next commit produces, and run `change` to cause it.\n *\n * The change is taken rather than left to the caller because the two have to be adjacent: a\n * `configureNext` with nothing after it animates whatever commit happens next, which may be a\n * different screen entirely. Resolves when the animation ends, or immediately where the platform\n * does not report that.\n */\n async animate(change: () => void, options: LayoutChange = {}): Promise<void> {\n if (!this.native) {\n change();\n return;\n }\n\n const done = new Promise<void>((resolve) => {\n this.native!.configureNext(config(options), resolve);\n // Android does not call the completion, so nothing should wait on it forever.\n setTimeout(resolve, (options.duration ?? DEFAULTS.duration) + COMPLETION_GRACE_MS);\n });\n\n change();\n await done;\n }\n}\n\n/**\n * The config React Native takes, from the three things worth naming.\n *\n * `create` and `delete` need a `property` as well as a type, because a view appearing has no\n * previous size to animate from - it has to be told what to animate *of*. Leaving that out is the\n * most common way one of these does nothing.\n */\nfunction config(options: LayoutChange): object {\n const duration = options.duration ?? DEFAULTS.duration;\n const easing = options.easing ?? DEFAULTS.easing;\n const appear = options.appear ?? 'opacity';\n const leave = options.leave ?? 'opacity';\n\n return {\n duration,\n update: { type: easing, ...(easing === 'spring' ? { springDamping: 0.7 } : {}) },\n ...(appear === 'none' ? {} : { create: { type: easing, property: appear } }),\n ...(leave === 'none' ? {} : { delete: { type: easing, property: leave } }),\n };\n}\n"]}
|
package/dist/react-native.d.ts
CHANGED
|
@@ -168,9 +168,13 @@ export interface NativeKeyboardEvent {
|
|
|
168
168
|
* `null` off a device, where each capability falls back to doing nothing - the same as an
|
|
169
169
|
* optional injection token nobody provided.
|
|
170
170
|
*
|
|
171
|
-
* The engine's presence is what tells the two apart. In Node there is no
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
171
|
+
* The engine's presence is what tells the two apart. In Node and in a browser there is no
|
|
172
|
+
* `nativeFabricUIManager`; on a device there is one, and a missing `require` would mean the bundler
|
|
173
|
+
* stopped emitting CommonJS under us. That is worth saying out loud rather than quietly rendering
|
|
174
|
+
* an app whose keyboard never moves.
|
|
175
|
+
*
|
|
176
|
+
* `require` alone cannot tell them apart: a browser bundle can have one. Rolldown gives a `vite
|
|
177
|
+
* build` its own `require` for an external module, which passes `typeof require === 'function'`
|
|
178
|
+
* and throws when called.
|
|
175
179
|
*/
|
|
176
180
|
export declare function reactNative(): ReactNative | null;
|
package/dist/react-native.js
CHANGED
|
@@ -18,21 +18,26 @@
|
|
|
18
18
|
* `null` off a device, where each capability falls back to doing nothing - the same as an
|
|
19
19
|
* optional injection token nobody provided.
|
|
20
20
|
*
|
|
21
|
-
* The engine's presence is what tells the two apart. In Node there is no
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
21
|
+
* The engine's presence is what tells the two apart. In Node and in a browser there is no
|
|
22
|
+
* `nativeFabricUIManager`; on a device there is one, and a missing `require` would mean the bundler
|
|
23
|
+
* stopped emitting CommonJS under us. That is worth saying out loud rather than quietly rendering
|
|
24
|
+
* an app whose keyboard never moves.
|
|
25
|
+
*
|
|
26
|
+
* `require` alone cannot tell them apart: a browser bundle can have one. Rolldown gives a `vite
|
|
27
|
+
* build` its own `require` for an external module, which passes `typeof require === 'function'`
|
|
28
|
+
* and throws when called.
|
|
25
29
|
*/
|
|
26
30
|
export function reactNative() {
|
|
31
|
+
if (globalThis.nativeFabricUIManager === undefined) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
27
34
|
// `require` has a type only where the app's tsconfig loads Node's or React Native's types, and
|
|
28
35
|
// a browser app's loads neither. `@ts-expect-error` would fail where it does.
|
|
29
36
|
// @ts-ignore
|
|
30
37
|
if (typeof require === 'function')
|
|
31
38
|
return require('react-native');
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
'inert. The bundle is not CommonJS; check the Metro transform.');
|
|
35
|
-
}
|
|
39
|
+
console.error('[angular-native] react-native could not be required, so every platform capability is ' +
|
|
40
|
+
'inert. The bundle is not CommonJS; check the Metro transform.');
|
|
36
41
|
return null;
|
|
37
42
|
}
|
|
38
43
|
//# sourceMappingURL=react-native.js.map
|
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;AA8IH
|
|
1
|
+
{"version":3,"file":"react-native.js","sourceRoot":"","sources":["../src/react-native.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AA8IH;;;;;;;;;;;;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 Platform: { OS: string };\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 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
|
@@ -12,8 +12,14 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { InjectionToken, type Signal } from '@angular/core';
|
|
14
14
|
import * as i0 from "@angular/core";
|
|
15
|
-
/**
|
|
16
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Dark text for a light bar, light text for a dark one. `default` is whatever the OS picks, which on
|
|
17
|
+
* Android is light text whatever the scheme. `auto` is dark text in the light color scheme and
|
|
18
|
+
* light text in the dark one, and follows `ColorScheme`, an in-app theme switch included.
|
|
19
|
+
*/
|
|
20
|
+
export type StatusBarStyle = 'default' | 'light' | 'dark' | 'auto';
|
|
21
|
+
/** A style the platform takes: `auto` is resolved against the color scheme before it gets there. */
|
|
22
|
+
export type PlatformStatusBarStyle = Exclude<StatusBarStyle, 'auto'>;
|
|
17
23
|
/** What a claim asks for. Anything absent is left as whatever the claim underneath said. */
|
|
18
24
|
export interface StatusBarState {
|
|
19
25
|
readonly style?: StatusBarStyle;
|
|
@@ -26,7 +32,7 @@ export interface StatusBarState {
|
|
|
26
32
|
}
|
|
27
33
|
/** Where the bar actually is. A fake stands in for the platform in tests. */
|
|
28
34
|
export interface StatusBarSource {
|
|
29
|
-
setStyle(style:
|
|
35
|
+
setStyle(style: PlatformStatusBarStyle, animated?: boolean): void;
|
|
30
36
|
setHidden(hidden: boolean, animation?: 'none' | 'fade' | 'slide'): void;
|
|
31
37
|
setBackgroundColor(color: string, animated?: boolean): void;
|
|
32
38
|
setTranslucent(translucent: boolean): void;
|
|
@@ -45,6 +51,7 @@ export declare class StatusBar {
|
|
|
45
51
|
/** Overridden in a test to watch the bar without one on screen. */
|
|
46
52
|
static readonly SOURCE: InjectionToken<StatusBarSource>;
|
|
47
53
|
private readonly source;
|
|
54
|
+
private readonly scheme;
|
|
48
55
|
private readonly stack;
|
|
49
56
|
/** What is actually showing: every claim in order, later ones winning per property. */
|
|
50
57
|
readonly state: Signal<StatusBarState>;
|
|
@@ -53,6 +60,7 @@ export declare class StatusBar {
|
|
|
53
60
|
* wants is the safe-area top inset, which `SafeArea` has.
|
|
54
61
|
*/
|
|
55
62
|
readonly height: Signal<number>;
|
|
63
|
+
constructor();
|
|
56
64
|
/** The base claim, for an app that sets the bar once at startup. */
|
|
57
65
|
set(state: StatusBarState): void;
|
|
58
66
|
/** A claim on top of whatever is there. Call the returned function to drop it. */
|
package/dist/status-bar.js
CHANGED
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
* `expo-status-bar` is the same statics with a React component around them, so nothing here needs
|
|
11
11
|
* that package installed.
|
|
12
12
|
*/
|
|
13
|
-
import { InjectionToken, Service, computed, inject, signal, untracked, } from '@angular/core';
|
|
13
|
+
import { DestroyRef, InjectionToken, Service, computed, inject, signal, untracked, } from '@angular/core';
|
|
14
|
+
import { ColorScheme } from "./color-scheme.js";
|
|
14
15
|
import { reactNative } from "./react-native.js";
|
|
15
16
|
import * as i0 from "@angular/core";
|
|
16
17
|
/** RN spells the styles for its own platforms; `light` means light *content*, as CSS would. */
|
|
@@ -50,6 +51,7 @@ export class StatusBar {
|
|
|
50
51
|
factory: statusBarSource,
|
|
51
52
|
});
|
|
52
53
|
source = inject(StatusBar.SOURCE);
|
|
54
|
+
scheme = inject(ColorScheme);
|
|
53
55
|
stack = signal([{}], /* @ts-ignore */
|
|
54
56
|
...(ngDevMode ? [{ debugName: "stack" }] : /* istanbul ignore next */ []));
|
|
55
57
|
/** What is actually showing: every claim in order, later ones winning per property. */
|
|
@@ -60,6 +62,17 @@ export class StatusBar {
|
|
|
60
62
|
* wants is the safe-area top inset, which `SafeArea` has.
|
|
61
63
|
*/
|
|
62
64
|
height = signal(this.source.height ?? 0).asReadonly();
|
|
65
|
+
constructor() {
|
|
66
|
+
// Straight from the source rather than through an effect, so an `auto` bar changes in the same
|
|
67
|
+
// turn as the scheme. The scheme is the listener's own: `ColorScheme.current` may not have
|
|
68
|
+
// heard yet.
|
|
69
|
+
const stop = inject(ColorScheme.SOURCE).subscribe((scheme) => {
|
|
70
|
+
const { style, animated } = untracked(this.state);
|
|
71
|
+
if (style === 'auto')
|
|
72
|
+
this.source.setStyle(resolve(style, scheme), animated);
|
|
73
|
+
});
|
|
74
|
+
inject(DestroyRef).onDestroy(stop);
|
|
75
|
+
}
|
|
63
76
|
/** The base claim, for an app that sets the bar once at startup. */
|
|
64
77
|
set(state) {
|
|
65
78
|
this.stack.update((entries) => [state, ...entries.slice(1)]);
|
|
@@ -84,8 +97,9 @@ export class StatusBar {
|
|
|
84
97
|
*/
|
|
85
98
|
apply() {
|
|
86
99
|
const { style, hidden, animated, backgroundColor, translucent } = untracked(this.state);
|
|
87
|
-
if (style !== undefined)
|
|
88
|
-
this.source.setStyle(style, animated);
|
|
100
|
+
if (style !== undefined) {
|
|
101
|
+
this.source.setStyle(resolve(style, untracked(this.scheme.current)), animated);
|
|
102
|
+
}
|
|
89
103
|
if (hidden !== undefined)
|
|
90
104
|
this.source.setHidden(hidden, animated ? 'fade' : undefined);
|
|
91
105
|
if (backgroundColor !== undefined)
|
|
@@ -98,5 +112,11 @@ export class StatusBar {
|
|
|
98
112
|
}
|
|
99
113
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: StatusBar, decorators: [{
|
|
100
114
|
type: Service
|
|
101
|
-
}] });
|
|
115
|
+
}], ctorParameters: () => [] });
|
|
116
|
+
/** Dark text on the light scheme's light background, light text on the dark one's. */
|
|
117
|
+
function resolve(style, scheme) {
|
|
118
|
+
if (style !== 'auto')
|
|
119
|
+
return style;
|
|
120
|
+
return scheme === 'dark' ? 'light' : 'dark';
|
|
121
|
+
}
|
|
102
122
|
//# sourceMappingURL=status-bar.js.map
|
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,cAAc,EACd,OAAO,EACP,QAAQ,EACR,MAAM,EACN,MAAM,EACN,SAAS,GAEV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;;AA0BhD,+FAA+F;AAC/F,MAAM,UAAU,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,cAAc,EAAW,CAAC;AAEjG,MAAM,UAAU,eAAe;IAC7B,MAAM,MAAM,GAAG,WAAW,EAAE,CAAC;IAC7B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO;YACL,QAAQ,EAAE,GAAG,EAAE,GAAE,CAAC;YAClB,SAAS,EAAE,GAAG,EAAE,GAAE,CAAC;YACnB,kBAAkB,EAAE,GAAG,EAAE,GAAE,CAAC;YAC5B,cAAc,EAAE,GAAG,EAAE,GAAE,CAAC;YACxB,MAAM,EAAE,SAAS;SAClB,CAAC;IACJ,CAAC;IAED,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;IAC7B,OAAO;QACL,QAAQ,EAAE,CAAC,KA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AC,WAAW,CAAC,CAAC;IACzE,CAAC;uGAnDU,SAAS;wGAAT,SAAS;;2FAAT,SAAS;kBADrB,OAAO","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 InjectionToken,\n Service,\n computed,\n inject,\n signal,\n untracked,\n type Signal,\n} from '@angular/core';\nimport { reactNative } from './react-native.ts';\n\n/** Dark text for a light bar, light text for a dark one. `default` is whatever the OS picks. */\nexport type StatusBarStyle = 'default' | 'light' | 'dark';\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: StatusBarStyle, 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 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 /** The base claim, for an app that sets the bar once at startup. */\n set(state: StatusBarState): void {\n this.stack.update((entries) => [state, ...entries.slice(1)]);\n this.apply();\n }\n\n /** A claim on top of whatever is there. Call the returned function to drop it. */\n push(state: StatusBarState): () => void {\n const entry = { ...state };\n this.stack.update((entries) => [...entries, entry]);\n this.apply();\n\n return () => {\n this.stack.update((entries) => entries.filter((one) => one !== entry));\n this.apply();\n };\n }\n\n /**\n * Push the merged state at the platform.\n *\n * Written whole rather than diffed: the platform's own setters are the cheap part, and a diff\n * would have to know which properties a *dropped* claim had been holding. Read untracked, so an\n * effect that sets the bar does not also subscribe to it and run again on every later claim.\n */\n private apply(): void {\n const { style, hidden, animated, backgroundColor, translucent } = untracked(this.state);\n if (style !== undefined) this.source.setStyle(style, animated);\n if (hidden !== undefined) this.source.setHidden(hidden, animated ? 'fade' : undefined);\n if (backgroundColor !== undefined) this.source.setBackgroundColor(backgroundColor, animated);\n if (translucent !== undefined) this.source.setTranslucent(translucent);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"status-bar.js","sourceRoot":"","sources":["../src/status-bar.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EACL,UAAU,EACV,cAAc,EACd,OAAO,EACP,QAAQ,EACR,MAAM,EACN,MAAM,EACN,SAAS,GAEV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,WAAW,EAAe,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;;AAiChD,+FAA+F;AAC/F,MAAM,UAAU,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,cAAc,EAAW,CAAC;AAEjG,MAAM,UAAU,eAAe;IAC7B,MAAM,MAAM,GAAG,WAAW,EAAE,CAAC;IAC7B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO;YACL,QAAQ,EAAE,GAAG,EAAE,GAAE,CAAC;YAClB,SAAS,EAAE,GAAG,EAAE,GAAE,CAAC;YACnB,kBAAkB,EAAE,GAAG,EAAE,GAAE,CAAC;YAC5B,cAAc,EAAE,GAAG,EAAE,GAAE,CAAC;YACxB,MAAM,EAAE,SAAS;SAClB,CAAC;IACJ,CAAC;IAED,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;IAC7B,OAAO;QACL,QAAQ,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,CAAC,SAAS,CAAC,WAAW,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC;QACjF,SAAS,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,SAA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E,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;QACjF,CAAC;QACD,IAAI,MAAM,KAAK,SAAS;YAAE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QACvF,IAAI,eAAe,KAAK,SAAS;YAAE,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC;QAC7F,IAAI,WAAW,KAAK,SAAS;YAAE,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;IACzE,CAAC;uGAjEU,SAAS;wGAAT,SAAS;;2FAAT,SAAS;kBADrB,OAAO;;AAqER,sFAAsF;AACtF,SAAS,OAAO,CAAC,KAAqB,EAAE,MAAc;IACpD,IAAI,KAAK,KAAK,MAAM;QAAE,OAAO,KAAK,CAAC;IACnC,OAAO,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;AAC9C,CAAC","sourcesContent":["/**\n * The status bar: what colour its text is, whether it is there at all, and how tall it is.\n *\n * React Native only offers this as a component. `<StatusBar />` applies its style by *rendering*,\n * and does it through a stack of entries so that a screen pushed on top can change the bar and\n * the screen underneath gets its own back when that one leaves. None of the rendering survives\n * without React - but the statics underneath do, and the stack is exactly what a navigation-driven\n * app needs, so it is the part worth keeping.\n *\n * `expo-status-bar` is the same statics with a React component around them, so nothing here needs\n * that package installed.\n */\nimport {\n DestroyRef,\n InjectionToken,\n Service,\n computed,\n inject,\n signal,\n untracked,\n type Signal,\n} from '@angular/core';\nimport { ColorScheme, type Scheme } from './color-scheme.ts';\nimport { reactNative } from './react-native.ts';\n\n/**\n * Dark text for a light bar, light text for a dark one. `default` is whatever the OS picks, which on\n * Android is light text whatever the scheme. `auto` is dark text in the light color scheme and\n * light text in the dark one, and follows `ColorScheme`, an in-app theme switch included.\n */\nexport type StatusBarStyle = 'default' | 'light' | 'dark' | 'auto';\n\n/** A style the platform takes: `auto` is resolved against the color scheme before it gets there. */\nexport type PlatformStatusBarStyle = Exclude<StatusBarStyle, 'auto'>;\n\n/** What a claim asks for. Anything absent is left as whatever the claim underneath said. */\nexport interface StatusBarState {\n readonly style?: StatusBarStyle;\n readonly hidden?: boolean;\n readonly animated?: boolean;\n /** Android only: the bar's own background. iOS has no such thing. */\n readonly backgroundColor?: string;\n /** Android only: whether content draws underneath the bar. */\n readonly translucent?: boolean;\n}\n\n/** Where the bar actually is. A fake stands in for the platform in tests. */\nexport interface StatusBarSource {\n setStyle(style: PlatformStatusBarStyle, animated?: boolean): void;\n setHidden(hidden: boolean, animation?: 'none' | 'fade' | 'slide'): void;\n setBackgroundColor(color: string, animated?: boolean): void;\n setTranslucent(translucent: boolean): void;\n /** Android reports one; iOS does not, where the safe-area inset is the number that matters. */\n readonly height: number | undefined;\n}\n\n/** RN spells the styles for its own platforms; `light` means light *content*, as CSS would. */\nconst BAR_STYLES = { default: 'default', light: 'light-content', dark: 'dark-content' } as const;\n\nexport function statusBarSource(): StatusBarSource {\n const native = reactNative();\n if (!native) {\n return {\n setStyle: () => {},\n setHidden: () => {},\n setBackgroundColor: () => {},\n setTranslucent: () => {},\n height: undefined,\n };\n }\n\n const { StatusBar } = native;\n return {\n setStyle: (style, animated) => StatusBar.setBarStyle(BAR_STYLES[style], animated),\n setHidden: (hidden, animation) => StatusBar.setHidden(hidden, animation),\n setBackgroundColor: (color, animated) => StatusBar.setBackgroundColor(color, animated),\n setTranslucent: (translucent) => StatusBar.setTranslucent(translucent),\n get height() {\n return StatusBar.currentHeight;\n },\n };\n}\n\n/**\n * A stack, not a setter.\n *\n * A modal that makes the bar light has to put back whatever the screen behind it asked for when\n * it is dismissed, and nothing else in an app remembers what that was. `push` returns the\n * function that drops the claim, so a screen can hand it straight to `DestroyRef.onDestroy`.\n */\n@Service()\nexport class StatusBar {\n /** Overridden in a test to watch the bar without one on screen. */\n static readonly SOURCE = new InjectionToken<StatusBarSource>('angular-native.statusBarSource', {\n factory: statusBarSource,\n });\n\n private readonly source = inject(StatusBar.SOURCE);\n private readonly scheme = inject(ColorScheme);\n private readonly stack = signal<readonly StatusBarState[]>([{}]);\n\n /** What is actually showing: every claim in order, later ones winning per property. */\n readonly state: Signal<StatusBarState> = computed(() =>\n this.stack().reduce((merged, entry) => ({ ...merged, ...entry }), {}),\n );\n\n /**\n * How tall it is, in points. Android reports it; iOS does not, and on iOS the number a layout\n * wants is the safe-area top inset, which `SafeArea` has.\n */\n readonly height: Signal<number> = signal(this.source.height ?? 0).asReadonly();\n\n constructor() {\n // Straight from the source rather than through an effect, so an `auto` bar changes in the same\n // turn as the scheme. The scheme is the listener's own: `ColorScheme.current` may not have\n // heard yet.\n const stop = inject(ColorScheme.SOURCE).subscribe((scheme) => {\n const { style, animated } = untracked(this.state);\n if (style === 'auto') this.source.setStyle(resolve(style, scheme), animated);\n });\n inject(DestroyRef).onDestroy(stop);\n }\n\n /** The base claim, for an app that sets the bar once at startup. */\n set(state: StatusBarState): void {\n this.stack.update((entries) => [state, ...entries.slice(1)]);\n this.apply();\n }\n\n /** A claim on top of whatever is there. Call the returned function to drop it. */\n push(state: StatusBarState): () => void {\n const entry = { ...state };\n this.stack.update((entries) => [...entries, entry]);\n this.apply();\n\n return () => {\n this.stack.update((entries) => entries.filter((one) => one !== entry));\n this.apply();\n };\n }\n\n /**\n * Push the merged state at the platform.\n *\n * Written whole rather than diffed: the platform's own setters are the cheap part, and a diff\n * would have to know which properties a *dropped* claim had been holding. Read untracked, so an\n * effect that sets the bar does not also subscribe to it and run again on every later claim.\n */\n private apply(): void {\n const { style, hidden, animated, backgroundColor, translucent } = untracked(this.state);\n if (style !== undefined) {\n this.source.setStyle(resolve(style, untracked(this.scheme.current)), animated);\n }\n if (hidden !== undefined) this.source.setHidden(hidden, animated ? 'fade' : undefined);\n if (backgroundColor !== undefined) this.source.setBackgroundColor(backgroundColor, animated);\n if (translucent !== undefined) this.source.setTranslucent(translucent);\n }\n}\n\n/** Dark text on the light scheme's light background, light text on the dark one's. */\nfunction resolve(style: StatusBarStyle, scheme: Scheme): PlatformStatusBarStyle {\n if (style !== 'auto') return style;\n return scheme === 'dark' ? 'light' : 'dark';\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ng-native/device",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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.3.0"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"@angular/core": "^22.0.0",
|
|
@@ -48,7 +48,8 @@
|
|
|
48
48
|
"dist"
|
|
49
49
|
],
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@angular/core": "22.2.0"
|
|
51
|
+
"@angular/core": "22.2.0",
|
|
52
|
+
"@babel/core": "^7.29.7"
|
|
52
53
|
},
|
|
53
54
|
"exports": {
|
|
54
55
|
".": {
|