@ng-native/device 0.3.0 → 0.5.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/color-scheme.js +31 -3
- package/dist/color-scheme.js.map +1 -1
- package/dist/conditions.js +3 -0
- package/dist/conditions.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/os-version.d.ts +9 -0
- package/dist/os-version.js +16 -0
- package/dist/os-version.js.map +1 -0
- package/dist/react-native.d.ts +2 -0
- package/dist/react-native.js.map +1 -1
- package/dist/screen.js +17 -1
- package/dist/screen.js.map +1 -1
- package/package.json +2 -2
package/dist/color-scheme.js
CHANGED
|
@@ -8,6 +8,13 @@
|
|
|
8
8
|
import { DestroyRef, InjectionToken, Service, inject, signal } from '@angular/core';
|
|
9
9
|
import { reactNative } from "./react-native.js";
|
|
10
10
|
import * as i0 from "@angular/core";
|
|
11
|
+
/**
|
|
12
|
+
* Every source's listeners, told of a scheme the app sets. React Native takes it at once but
|
|
13
|
+
* reports it only when its root view next changes appearance, and on iOS a full-screen modal takes
|
|
14
|
+
* that view out of the window, so the change arrived when the modal closed. The platform's own
|
|
15
|
+
* report, when it comes, repeats the same scheme.
|
|
16
|
+
*/
|
|
17
|
+
const setListeners = new Set();
|
|
11
18
|
export function colorSchemeSource() {
|
|
12
19
|
const native = reactNative();
|
|
13
20
|
if (!native)
|
|
@@ -17,10 +24,31 @@ export function colorSchemeSource() {
|
|
|
17
24
|
return {
|
|
18
25
|
current: read,
|
|
19
26
|
subscribe: (listener) => {
|
|
20
|
-
|
|
21
|
-
|
|
27
|
+
// Each scheme once: the platform's report repeats one the app set, and it also reports
|
|
28
|
+
// appearance changes that are not the scheme.
|
|
29
|
+
let last = read();
|
|
30
|
+
const onChange = () => {
|
|
31
|
+
const scheme = read();
|
|
32
|
+
if (scheme === last)
|
|
33
|
+
return;
|
|
34
|
+
last = scheme;
|
|
35
|
+
listener(scheme);
|
|
36
|
+
};
|
|
37
|
+
const subscription = native.Appearance.addChangeListener(onChange);
|
|
38
|
+
setListeners.add(onChange);
|
|
39
|
+
return () => {
|
|
40
|
+
subscription.remove();
|
|
41
|
+
setListeners.delete(onChange);
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
set: (scheme) => {
|
|
45
|
+
native.Appearance.setColorScheme?.(scheme ?? 'unspecified');
|
|
46
|
+
// Back to the system's waits for the platform's report: React Native resolves it from a
|
|
47
|
+
// native cache that a full-screen modal on iOS can leave stale.
|
|
48
|
+
if (scheme !== null)
|
|
49
|
+
for (const listener of [...setListeners])
|
|
50
|
+
listener();
|
|
22
51
|
},
|
|
23
|
-
set: (scheme) => native.Appearance.setColorScheme?.(scheme ?? 'unspecified'),
|
|
24
52
|
};
|
|
25
53
|
}
|
|
26
54
|
export class ColorScheme {
|
package/dist/color-scheme.js.map
CHANGED
|
@@ -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,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,OA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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 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"]}
|
package/dist/conditions.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { accessibilitySource } from "./accessibility.js";
|
|
2
2
|
import { colorSchemeSource } from "./color-scheme.js";
|
|
3
|
+
import { directionSource } from "./direction.js";
|
|
3
4
|
import { screenSource } from "./screen.js";
|
|
4
5
|
import { reactNative } from "./react-native.js";
|
|
5
6
|
/** The system text size, as a multiplier. One off a device. */
|
|
@@ -17,6 +18,8 @@ export function currentConditions() {
|
|
|
17
18
|
// already on screen, so nothing is lost by learning it a tick late.
|
|
18
19
|
reducedMotion: false,
|
|
19
20
|
fontScale: fontScale(),
|
|
21
|
+
// Settled while the native side starts up, and fixed until the app restarts.
|
|
22
|
+
direction: directionSource().current(),
|
|
20
23
|
};
|
|
21
24
|
}
|
|
22
25
|
/**
|
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;A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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 { directionSource } from './direction.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 // Settled while the native side starts up, and fixed until the app restarts.\n direction: directionSource().current(),\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/index.d.ts
CHANGED
|
@@ -24,3 +24,4 @@ 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
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';
|
|
27
|
+
export { OS_VERSION } from './os-version.ts';
|
package/dist/index.js
CHANGED
|
@@ -23,4 +23,5 @@ export { SafeArea } from "./safe-area.js";
|
|
|
23
23
|
export { COMPACT_WIDTH, Screen } from "./screen.js";
|
|
24
24
|
export { StatusBar, statusBarSource, } from "./status-bar.js";
|
|
25
25
|
export { SCREEN_IN_FRONT } from "./screen-in-front.js";
|
|
26
|
+
export { OS_VERSION } from "./os-version.js";
|
|
26
27
|
//# sourceMappingURL=index.js.map
|
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,OAAO,EAA0C,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,OAAO,EAAmC,MAAM,cAAc,CAAC;AACxE,OAAO,EACL,eAAe,GAIhB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,OAAO,EAAyC,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAwB,MAAM,gBAAgB,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAA2B,MAAM,oBAAoB,CAAC;AAC/F,OAAO,EAAE,QAAQ,EAA6C,MAAM,eAAe,CAAC;AAEpF,OAAO,EAAE,QAAQ,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"]}
|
|
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,OAAO,EAA0C,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,OAAO,EAAmC,MAAM,cAAc,CAAC;AACxE,OAAO,EACL,eAAe,GAIhB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,OAAO,EAAyC,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAwB,MAAM,gBAAgB,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAA2B,MAAM,oBAAoB,CAAC;AAC/F,OAAO,EAAE,QAAQ,EAA6C,MAAM,eAAe,CAAC;AAEpF,OAAO,EAAE,QAAQ,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;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,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';\nexport { OS_VERSION } from './os-version.ts';\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { InjectionToken } from '@angular/core';
|
|
2
|
+
/**
|
|
3
|
+
* The major version of the operating system the app runs on: 26 on iOS 26.5, and the API level
|
|
4
|
+
* on Android. Null where there is none to ask, the web and a test in Node.
|
|
5
|
+
*
|
|
6
|
+
* For a default that follows what the platform draws in that version, where nothing native says
|
|
7
|
+
* which it is. A test provides the version it wants.
|
|
8
|
+
*/
|
|
9
|
+
export declare const OS_VERSION: InjectionToken<number | null>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { InjectionToken } from '@angular/core';
|
|
2
|
+
import { reactNative } from "./react-native.js";
|
|
3
|
+
/**
|
|
4
|
+
* The major version of the operating system the app runs on: 26 on iOS 26.5, and the API level
|
|
5
|
+
* on Android. Null where there is none to ask, the web and a test in Node.
|
|
6
|
+
*
|
|
7
|
+
* For a default that follows what the platform draws in that version, where nothing native says
|
|
8
|
+
* which it is. A test provides the version it wants.
|
|
9
|
+
*/
|
|
10
|
+
export const OS_VERSION = new InjectionToken('angular-native.osVersion', {
|
|
11
|
+
factory: () => {
|
|
12
|
+
const version = Number.parseInt(String(reactNative()?.Platform.Version), 10);
|
|
13
|
+
return Number.isNaN(version) ? null : version;
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
//# sourceMappingURL=os-version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"os-version.js","sourceRoot":"","sources":["../src/os-version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,cAAc,CAAgB,0BAA0B,EAAE;IACtF,OAAO,EAAE,GAAG,EAAE;QACZ,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;QAC7E,OAAO,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;IAChD,CAAC;CACF,CAAC,CAAC","sourcesContent":["import { InjectionToken } from '@angular/core';\nimport { reactNative } from './react-native.ts';\n\n/**\n * The major version of the operating system the app runs on: 26 on iOS 26.5, and the API level\n * on Android. Null where there is none to ask, the web and a test in Node.\n *\n * For a default that follows what the platform draws in that version, where nothing native says\n * which it is. A test provides the version it wants.\n */\nexport const OS_VERSION = new InjectionToken<number | null>('angular-native.osVersion', {\n factory: () => {\n const version = Number.parseInt(String(reactNative()?.Platform.Version), 10);\n return Number.isNaN(version) ? null : version;\n },\n});\n"]}
|
package/dist/react-native.d.ts
CHANGED
|
@@ -103,8 +103,10 @@ export interface ReactNative {
|
|
|
103
103
|
/** The user's text size setting, as a multiplier. One is the default. */
|
|
104
104
|
getFontScale(): number;
|
|
105
105
|
};
|
|
106
|
+
/** `Version` is a string on iOS, `'26.5'`, and the API level, a number, on Android. */
|
|
106
107
|
Platform: {
|
|
107
108
|
OS: string;
|
|
109
|
+
Version?: string | number;
|
|
108
110
|
};
|
|
109
111
|
Share: {
|
|
110
112
|
share(content: {
|
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;AA+IH;;;;;;;;;;;;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 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/screen.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* for `Dimensions.get` directly gets a value that never updates on rotation.
|
|
8
8
|
*/
|
|
9
9
|
import { DestroyRef, InjectionToken, Service, computed, inject, signal, } from '@angular/core';
|
|
10
|
+
import { HostEngine } from '@ng-native/fabric';
|
|
10
11
|
import { reactNative } from "./react-native.js";
|
|
11
12
|
import { SafeArea } from "./safe-area.js";
|
|
12
13
|
import * as i0 from "@angular/core";
|
|
@@ -28,10 +29,25 @@ export function screenSource() {
|
|
|
28
29
|
},
|
|
29
30
|
};
|
|
30
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* The screen as the engine was told it, where there is no React Native to ask: a test, whose
|
|
34
|
+
* `conditions` size what `@media` sees, so the two views of the screen agree. Null on a host whose
|
|
35
|
+
* engine keeps no viewport.
|
|
36
|
+
*/
|
|
37
|
+
function engineScreenSource() {
|
|
38
|
+
const engine = inject(HostEngine, { optional: true });
|
|
39
|
+
if (!engine?.viewport)
|
|
40
|
+
return null;
|
|
41
|
+
const current = () => ({ window: engine.viewport, screen: engine.viewport });
|
|
42
|
+
return {
|
|
43
|
+
current,
|
|
44
|
+
subscribe: (listener) => engine.watchViewport?.(() => listener(current())) ?? (() => { }),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
31
47
|
export class Screen {
|
|
32
48
|
/** Overridden in a test to resize the screen, or rotate it. */
|
|
33
49
|
static SOURCE = new InjectionToken('angular-native.screenSource', {
|
|
34
|
-
factory: screenSource,
|
|
50
|
+
factory: () => (reactNative() ? screenSource() : (engineScreenSource() ?? screenSource())),
|
|
35
51
|
});
|
|
36
52
|
source = inject(Screen.SOURCE);
|
|
37
53
|
safeArea = inject(SafeArea);
|
package/dist/screen.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"screen.js","sourceRoot":"","sources":["../src/screen.ts"],"names":[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AG,MAAM,CAAQ,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE;8EAAC,CAAC;IAE9D;;;;;;;;;;;;;OAaG;IACM,MAAM,GAAiB,QAAQ,CAAC,GAAG,EAAE;QAC5C,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACpC,OAAO,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,MAAM,CAAC;IACpF,CAAC;+EAAC,CAAC;IACH,wEAAwE;IAC/D,OAAO,GAAiB,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,MAAM;gFAAC,CAAC;IAC5D,WAAW,GAAqC,QAAQ,CAAC,GAAG,EAAE,CACrE,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,UAAU;oFACtE,CAAC;IAEF;;;;;;;;;;;;;;OAcG;IACM,OAAO,GAAoB,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,GAAG,aAAa;gFAAC,CAAC;IAExF;QACE,MAAM,CAAC,UAAU,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACxF,CAAC;uGArDU,MAAM;wGAAN,MAAM;;2FAAN,MAAM;kBADlB,OAAO","sourcesContent":["/**\n * How big the screen is, and which way up.\n *\n * The engine already tracks this for media queries, but only for the cascade: it resolves `@media`\n * and viewport units and tells nobody. Component logic that has to branch on size - a two-column\n * layout above a breakpoint, a different image for a tall screen - has no way to ask, and reaching\n * for `Dimensions.get` directly gets a value that never updates on rotation.\n */\nimport {\n DestroyRef,\n InjectionToken,\n Service,\n computed,\n inject,\n signal,\n type Signal,\n} from '@angular/core';\nimport { HostEngine, type Engine } from '@ng-native/fabric';\nimport { reactNative } from './react-native.ts';\nimport { SafeArea } from './safe-area.ts';\n\nexport interface Size {\n readonly width: number;\n readonly height: number;\n}\n\nexport interface Sizes {\n /**\n * What `Dimensions` calls the window, which is not always what the app can draw in.\n *\n * On Android 15 an app draws edge to edge, painting behind the status and navigation bars, and\n * this reports the area *between* them - short by their height. `Screen.window` prefers the\n * safe-area provider's measured frame for that reason; this is the fallback for the frame before\n * the provider has laid out.\n */\n readonly window: Size;\n /** The physical display. */\n readonly screen: Size;\n}\n\nexport interface ScreenSource {\n current(): Sizes;\n subscribe(listener: (sizes: Sizes) => void): () => void;\n}\n\nconst NOTHING: Sizes = { window: { width: 0, height: 0 }, screen: { width: 0, height: 0 } };\n\n/** Tailwind's `md`. Below it a phone layout, at or above it a tablet one. */\nexport const COMPACT_WIDTH = 768;\n\nexport function screenSource(): ScreenSource {\n const native = reactNative();\n if (!native) return { current: () => NOTHING, subscribe: () => () => {} };\n\n return {\n current: () => ({\n window: native.Dimensions.get('window'),\n screen: native.Dimensions.get('screen'),\n }),\n subscribe: (listener) => {\n const subscription = native.Dimensions.addEventListener('change', (sizes) =>\n listener({ window: sizes.window, screen: sizes.screen }),\n );\n return () => subscription.remove();\n },\n };\n}\n\n/**\n * The screen as the engine was told it, where there is no React Native to ask: a test, whose\n * `conditions` size what `@media` sees, so the two views of the screen agree. Null on a host whose\n * engine keeps no viewport.\n */\nfunction engineScreenSource(): ScreenSource | null {\n const engine = inject(HostEngine, { optional: true }) as Partial<\n Pick<Engine, 'viewport' | 'watchViewport'>\n > | null;\n if (!engine?.viewport) return null;\n const current = (): Sizes => ({ window: engine.viewport!, screen: engine.viewport! });\n return {\n current,\n subscribe: (listener) => engine.watchViewport?.(() => listener(current())) ?? (() => {}),\n };\n}\n\n@Service()\nexport class Screen {\n /** Overridden in a test to resize the screen, or rotate it. */\n static readonly SOURCE = new InjectionToken<ScreenSource>('angular-native.screenSource', {\n factory: () => (reactNative() ? screenSource() : (engineScreenSource() ?? screenSource())),\n });\n\n private readonly source = inject(Screen.SOURCE);\n private readonly safeArea = inject(SafeArea);\n private readonly sizes = signal<Sizes>(this.source.current());\n\n /**\n * What the app can draw in: the one almost everything wants.\n *\n * Measured by the safe-area provider rather than read from `Dimensions`, because on Android 15\n * an app draws edge to edge - behind the status and navigation bars - and `Dimensions` reports\n * the area between them instead. On a 1080x2400 phone that was 838.5pt against a real drawable\n * height of 914.3, so viewport units, height media queries and anything sizing itself from this\n * were all short by the bars. The provider measures the frame it was actually handed, which is\n * the drawable area by definition and on both platforms.\n *\n * `Dimensions` is the fallback for the one frame between mounting and the provider laying out,\n * because a window of zero for that frame would be worse than a slightly wrong one. An app with\n * no `<safe-area-provider>` never gets past the fallback, which is the behaviour it had before.\n */\n readonly window: Signal<Size> = computed(() => {\n const frame = this.safeArea.frame();\n return frame ? { width: frame.width, height: frame.height } : this.sizes().window;\n });\n /** The physical display, which on Android is larger than the window. */\n readonly display: Signal<Size> = computed(() => this.sizes().screen);\n readonly orientation: Signal<'portrait' | 'landscape'> = computed(() =>\n this.window().width > this.window().height ? 'landscape' : 'portrait',\n );\n\n /**\n * Whether the window is narrow enough to want the phone layout.\n *\n * The one branch a component library actually needs, and the reason it is a signal rather than\n * a media query: a sidebar that is a rail on an iPad and a sheet on a phone is not two sets of\n * classes on one tree, it is two different trees. shadcn's own sidebar branches in JavaScript\n * for exactly this reason, and `@media` in the stylesheet cannot decide which components to\n * build. Where the difference *is* only classes, write `md:` and let the cascade do it - the\n * compiler answers width, height and orientation queries, so Tailwind's breakpoints work.\n *\n * `COMPACT_WIDTH` is Tailwind's `md`, which is also the number `useIsMobile` uses upstream.\n * It is close to, but not the same as, iOS's own compact/regular width class: an iPad mini in\n * portrait is 744pt, which Apple calls regular and this calls compact. Close enough to be the\n * right default and named so an app that disagrees can say so.\n */\n readonly compact: Signal<boolean> = computed(() => this.window().width < COMPACT_WIDTH);\n\n constructor() {\n inject(DestroyRef).onDestroy(this.source.subscribe((sizes) => this.sizes.set(sizes)));\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ng-native/device",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.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.5.0"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"@angular/core": "^22.0.0",
|