@ng-native/device 0.15.0 → 0.17.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/conditions.d.ts +3 -2
- package/dist/conditions.js +10 -3
- package/dist/conditions.js.map +1 -1
- package/dist/deep-links.d.ts +5 -0
- package/dist/deep-links.js +7 -0
- package/dist/deep-links.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/keyboard.d.ts +42 -8
- package/dist/keyboard.js +27 -5
- package/dist/keyboard.js.map +1 -1
- package/dist/merge-claims.d.ts +6 -0
- package/dist/merge-claims.js +16 -0
- package/dist/merge-claims.js.map +1 -0
- package/dist/native-history.d.ts +8 -0
- package/dist/native-history.js +9 -0
- package/dist/native-history.js.map +1 -0
- package/dist/navigation-bar.d.ts +6 -12
- package/dist/navigation-bar.js +69 -31
- package/dist/navigation-bar.js.map +1 -1
- package/dist/status-bar.d.ts +7 -15
- package/dist/status-bar.js +72 -37
- package/dist/status-bar.js.map +1 -1
- package/dist/window-claims.d.ts +70 -0
- package/dist/window-claims.js +132 -0
- package/dist/window-claims.js.map +1 -0
- package/package.json +2 -2
package/dist/conditions.d.ts
CHANGED
|
@@ -36,8 +36,9 @@ export declare function currentConditions(): Conditions;
|
|
|
36
36
|
* out from the pixel ratio; off a device there is no answer, and inventing one would be a line of
|
|
37
37
|
* the wrong weight in every test that draws one.
|
|
38
38
|
*
|
|
39
|
-
* Not watched, unlike the conditions:
|
|
40
|
-
*
|
|
39
|
+
* Not watched, unlike the conditions: React Native works the hairline out once and keeps it, so
|
|
40
|
+
* a window moved to a screen of another density keeps the first screen's, as a React Native app's
|
|
41
|
+
* `StyleSheet.hairlineWidth` does. The safe-area insets arrive through `updateTokens`.
|
|
41
42
|
*/
|
|
42
43
|
export declare function deviceTokens(): Record<string, TokenValue>;
|
|
43
44
|
/**
|
package/dist/conditions.js
CHANGED
|
@@ -7,6 +7,10 @@ import { reactNative } from "./react-native.js";
|
|
|
7
7
|
function fontScale() {
|
|
8
8
|
return reactNative()?.PixelRatio.getFontScale() ?? 1;
|
|
9
9
|
}
|
|
10
|
+
/** The screen's pixels in a point. One off a device. */
|
|
11
|
+
function pixelRatio() {
|
|
12
|
+
return reactNative()?.PixelRatio.get() ?? 1;
|
|
13
|
+
}
|
|
10
14
|
export function currentConditions() {
|
|
11
15
|
const { window } = screenSource().current();
|
|
12
16
|
return {
|
|
@@ -18,6 +22,8 @@ export function currentConditions() {
|
|
|
18
22
|
// already on screen, so nothing is lost by learning it a tick late.
|
|
19
23
|
reducedMotion: false,
|
|
20
24
|
fontScale: fontScale(),
|
|
25
|
+
// Read again when the window is resized, which it is when it moves to a screen of another density.
|
|
26
|
+
pixelRatio: pixelRatio(),
|
|
21
27
|
// Settled while the native side starts up, and fixed until the app restarts.
|
|
22
28
|
direction: directionSource().current(),
|
|
23
29
|
};
|
|
@@ -31,8 +37,9 @@ export function currentConditions() {
|
|
|
31
37
|
* out from the pixel ratio; off a device there is no answer, and inventing one would be a line of
|
|
32
38
|
* the wrong weight in every test that draws one.
|
|
33
39
|
*
|
|
34
|
-
* Not watched, unlike the conditions:
|
|
35
|
-
*
|
|
40
|
+
* Not watched, unlike the conditions: React Native works the hairline out once and keeps it, so
|
|
41
|
+
* a window moved to a screen of another density keeps the first screen's, as a React Native app's
|
|
42
|
+
* `StyleSheet.hairlineWidth` does. The safe-area insets arrive through `updateTokens`.
|
|
36
43
|
*/
|
|
37
44
|
export function deviceTokens() {
|
|
38
45
|
const native = reactNative();
|
|
@@ -73,7 +80,7 @@ export function watchConditions(engine, options = {}) {
|
|
|
73
80
|
if (rescaled)
|
|
74
81
|
engine.remeasureText?.();
|
|
75
82
|
};
|
|
76
|
-
const sizes = screen.subscribe(({ window }) => resize({ width: window.width, height: window.height }, fontScale()));
|
|
83
|
+
const sizes = screen.subscribe(({ window }) => resize({ width: window.width, height: window.height, pixelRatio: pixelRatio() }, fontScale()));
|
|
77
84
|
const scheme = colors.subscribe((colorScheme) => push({ colorScheme }));
|
|
78
85
|
const settings = accessibility.subscribe((change) => {
|
|
79
86
|
if (change.fontScale !== undefined && change.fontScale !== scale)
|
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,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,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;QACpB,SAAS,EAAE,SAAS,EAAE;QACtB,6EAA6E;QAC7E,SAAS,EAAE,eAAe,EAAE,CAAC,OAAO,EAAE;KACvC,CAAC;AACJ,CAAC;AAED
|
|
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;A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AAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC,CAC9F,CAAC;IACF,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC;IACxE,MAAM,QAAQ,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,EAAE;QAClD,IAAI,MAAM,CAAC,SAAS,KAAK,SAAS,IAAI,MAAM,CAAC,SAAS,KAAK,KAAK;YAAE,MAAM,CAAC,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 { 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\n/** The screen's pixels in a point. One off a device. */\nfunction pixelRatio(): number {\n return reactNative()?.PixelRatio.get() ?? 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 // Read again when the window is resized, which it is when it moves to a screen of another density.\n pixelRatio: pixelRatio(),\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: React Native works the hairline out once and keeps it, so\n * a window moved to a screen of another density keeps the first screen's, as a React Native app's\n * `StyleSheet.hairlineWidth` does. The safe-area insets 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, pixelRatio: pixelRatio() }, 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/deep-links.d.ts
CHANGED
|
@@ -41,6 +41,11 @@ export declare class DeepLinks {
|
|
|
41
41
|
* that injects the router reaches `DeepLinks` through the location, and would be a cycle at boot.
|
|
42
42
|
*/
|
|
43
43
|
private deliver;
|
|
44
|
+
/**
|
|
45
|
+
* Follow a path of the app's own as a link to it that arrived from outside is followed: a
|
|
46
|
+
* library that sets `location.href` to a page of the app goes there the way a link does.
|
|
47
|
+
*/
|
|
48
|
+
follow(path: string): void;
|
|
44
49
|
/** Hand a url to whatever else on the device handles it: a browser, Maps, another app. */
|
|
45
50
|
open(url: string): void;
|
|
46
51
|
/**
|
package/dist/deep-links.js
CHANGED
|
@@ -154,6 +154,13 @@ export class DeepLinks {
|
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Follow a path of the app's own as a link to it that arrived from outside is followed: a
|
|
159
|
+
* library that sets `location.href` to a page of the app goes there the way a link does.
|
|
160
|
+
*/
|
|
161
|
+
follow(path) {
|
|
162
|
+
this.listeners.forEach((listener) => this.deliver(listener, path));
|
|
163
|
+
}
|
|
157
164
|
/** Hand a url to whatever else on the device handles it: a browser, Maps, another app. */
|
|
158
165
|
open(url) {
|
|
159
166
|
this.source.open(url);
|
package/dist/deep-links.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deep-links.js","sourceRoot":"","sources":["../src/deep-links.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACxF,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;;AAWhD;;;GAGG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,MAAM,GAAG,WAAW,EAAE,CAAC;IAC7B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO;YACL,SAAS,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC;YACtC,SAAS,EAAE,GAAG,EAAE,CAAC,GAAG,E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AAC,YAAY,EAAE,EAAE,CAAC;IAC/B,CAAC;uGAxEU,SAAS;wGAAT,SAAS;;2FAAT,SAAS;kBADrB,OAAO","sourcesContent":["/**\n * Links that arrive from outside the app: a `canary://` url, a universal link, a notification.\n */\nimport { ErrorHandler, InjectionToken, Injector, Service, inject } from '@angular/core';\nimport { reactNative } from './react-native.ts';\n\nexport interface DeepLinkSource {\n /** The url the app was launched with. A promise, and nothing says it settles before mount. */\n launchUrl(): Promise<string | null>;\n subscribe(listener: (url: string) => void): () => void;\n open(url: string): void;\n /** Optional, so a source written before there was one is still a source. */\n openSettings?(): void;\n}\n\n/**\n * React Native's `Linking`, with each url whole: the scheme, host, query and fragment that\n * `DeepLinks` strips to a path. Off a device, a source that never delivers a link.\n */\nexport function deepLinkSource(): DeepLinkSource {\n const native = reactNative();\n if (!native) {\n return {\n launchUrl: () => Promise.resolve(null),\n subscribe: () => () => {},\n open: () => {},\n openSettings: () => {},\n };\n }\n\n return {\n launchUrl: () => native.Linking.getInitialURL(),\n subscribe: (listener) => {\n const subscription = native.Linking.addEventListener('url', ({ url }) => listener(url));\n return () => subscription.remove();\n },\n open: (url) => void native.Linking.openURL(url).catch(() => {}),\n openSettings: () => void native.Linking.openSettings().catch(() => {}),\n };\n}\n\n/**\n * The path a url means to this app: everything after the scheme and host.\n *\n * Prefixes are app configuration and every app's are different, but stripping one is not: what a\n * router can navigate to is a path. `canary://primitives` and `https://example.com/primitives`\n * both mean `/primitives` - which takes noticing that only the second one has a host.\n *\n * Expo Go is the exception worth handling here rather than in every app: it serves every project\n * from one development url, puts the app's own path after `/--`, and has a host like a web url\n * rather than a path like an app's own scheme.\n *\n * The development client is the other. `expo run:ios` launches the app through\n * `<scheme>://expo-development-client/?url=...`, which is Expo telling its own launcher which\n * bundle to load and means nothing to the app. Left alone it reaches the router as a path, matches\n * no route, and the app shows a blank screen on every launch during development - which looks\n * exactly like a bug in the app.\n */\n\n/** Expo's own launch hosts. Not paths: instructions to the launcher, which the app never routes. */\nconst EXPO_INTERNAL = new Set(['expo-development-client']);\n\n/** Whether the first segment names one of Expo's launchers rather than something in the app. */\nfunction isLauncher(rest: string): boolean {\n return EXPO_INTERNAL.has(rest.split(/[/?#]/, 1)[0] ?? '');\n}\n\n/** Schemes that carry a host to skip before the path starts. */\nconst HAS_HOST = new Set(['http', 'https', 'exp', 'exps']);\n\n/**\n * The app's path after Expo Go's `/--/`, or null for a url with none in its path. In a query or a\n * fragment, `/--/` is the app's own: a search for it is not a launch prefix.\n */\nfunction expoGoPath(rest: string): string | null {\n const end = rest.search(/[?#]/);\n const marker = (end === -1 ? rest : rest.slice(0, end)).indexOf('/--/');\n return marker === -1 ? null : rest.slice(marker + 3);\n}\n\nexport function pathOf(url: string | null): string | null {\n if (!url) return null;\n const scheme = /^([a-z][a-z0-9+.-]*):\\/\\//i.exec(url);\n const rest = scheme ? url.slice(scheme[0].length) : url;\n\n const expoGo = expoGoPath(rest);\n if (expoGo !== null) return expoGo;\n if (isLauncher(rest)) return null;\n\n // A url with a host has one to skip. A custom scheme does not: `canary://settings` names a\n // path, not a machine, and treating the two alike is how it quietly becomes `/`.\n if (HAS_HOST.has(scheme?.[1]?.toLowerCase() ?? '')) {\n // The host ends at the path, or at a query or fragment when there is no path.\n const end = rest.search(/[/?#]/);\n if (end === -1) return '/';\n return rest[end] === '/' ? rest.slice(end) : `/${rest.slice(end)}`;\n }\n return rest.startsWith('/') ? rest : `/${rest}`;\n}\n\n/**\n * The launch url is delivered whichever way is true at the time: as the initial url if it is\n * known before anything asks, and as an ordinary link if the app is already up. Both happen -\n * the promise races the first navigation and neither order is guaranteed - and a link that\n * arrives late is still a link, so nothing is dropped either way.\n */\n@Service()\nexport class DeepLinks {\n /** Overridden in a test to deliver a link with no platform under it. */\n static readonly SOURCE = new InjectionToken<DeepLinkSource>('angular-native.deepLinkSource', {\n factory: deepLinkSource,\n });\n\n private readonly source = inject(DeepLinks.SOURCE);\n private readonly injector = inject(Injector);\n private launch: string | null = null;\n private readonly listeners = new Set<(path: string) => void>();\n\n constructor() {\n void this.source.launchUrl().then((url) => {\n const path = pathOf(url);\n if (!path || path === '/') return;\n if (this.listeners.size) this.listeners.forEach((listener) => this.deliver(listener, path));\n else this.launch = path;\n });\n }\n\n /** The path the app was launched with, if it is known yet. */\n initialUrl(): string | null {\n return this.launch;\n }\n\n /** Links that arrive while the app is running, as paths. Returns an unsubscribe. */\n subscribe(listener: (path: string) => void): () => void {\n // Each subscription is its own entry, so the same function subscribed twice stops once.\n const subscription = (path: string) => listener(path);\n this.listeners.add(subscription);\n const unsubscribe = this.source.subscribe((url) => {\n const path = pathOf(url);\n if (path) listener(path);\n });\n return () => {\n this.listeners.delete(subscription);\n unsubscribe();\n };\n }\n\n /**\n * One listener throwing is reported, and does not keep the launch url from the rest. The\n * `ErrorHandler` is looked up when that happens rather than when this is made: an app's handler\n * that injects the router reaches `DeepLinks` through the location, and would be a cycle at boot.\n */\n private deliver(listener: (path: string) => void, path: string): void {\n try {\n listener(path);\n } catch (error) {\n // A handler that rethrows, as some apps' do, would otherwise stop the listeners after this.\n try {\n const errors = this.injector.get(ErrorHandler, null);\n if (errors) errors.handleError(error);\n else console.error(error);\n } catch (reporting) {\n if (reporting === error) console.error(error);\n else console.error(error, reporting);\n }\n }\n }\n\n /** Hand a url to whatever else on the device handles it: a browser, Maps, another app. */\n open(url: string): void {\n this.source.open(url);\n }\n\n /**\n * Open the app's own page in the system settings, where a person turns on a permission the\n * platform no longer asks for. Android has no url for that page, so `open()` cannot reach it.\n */\n openSettings(): void {\n this.source.openSettings?.();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"deep-links.js","sourceRoot":"","sources":["../src/deep-links.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACxF,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;;AAWhD;;;GAGG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AK,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;YACvC,CAAC;QACH,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,IAAY;QACjB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC;IACrE,CAAC;IAED,0FAA0F;IAC1F,IAAI,CAAC,GAAW;QACd,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IAED;;;OAGG;IACH,YAAY;QACV,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,EAAE,CAAC;IAC/B,CAAC;uGAhFU,SAAS;wGAAT,SAAS;;2FAAT,SAAS;kBADrB,OAAO","sourcesContent":["/**\n * Links that arrive from outside the app: a `canary://` url, a universal link, a notification.\n */\nimport { ErrorHandler, InjectionToken, Injector, Service, inject } from '@angular/core';\nimport { reactNative } from './react-native.ts';\n\nexport interface DeepLinkSource {\n /** The url the app was launched with. A promise, and nothing says it settles before mount. */\n launchUrl(): Promise<string | null>;\n subscribe(listener: (url: string) => void): () => void;\n open(url: string): void;\n /** Optional, so a source written before there was one is still a source. */\n openSettings?(): void;\n}\n\n/**\n * React Native's `Linking`, with each url whole: the scheme, host, query and fragment that\n * `DeepLinks` strips to a path. Off a device, a source that never delivers a link.\n */\nexport function deepLinkSource(): DeepLinkSource {\n const native = reactNative();\n if (!native) {\n return {\n launchUrl: () => Promise.resolve(null),\n subscribe: () => () => {},\n open: () => {},\n openSettings: () => {},\n };\n }\n\n return {\n launchUrl: () => native.Linking.getInitialURL(),\n subscribe: (listener) => {\n const subscription = native.Linking.addEventListener('url', ({ url }) => listener(url));\n return () => subscription.remove();\n },\n open: (url) => void native.Linking.openURL(url).catch(() => {}),\n openSettings: () => void native.Linking.openSettings().catch(() => {}),\n };\n}\n\n/**\n * The path a url means to this app: everything after the scheme and host.\n *\n * Prefixes are app configuration and every app's are different, but stripping one is not: what a\n * router can navigate to is a path. `canary://primitives` and `https://example.com/primitives`\n * both mean `/primitives` - which takes noticing that only the second one has a host.\n *\n * Expo Go is the exception worth handling here rather than in every app: it serves every project\n * from one development url, puts the app's own path after `/--`, and has a host like a web url\n * rather than a path like an app's own scheme.\n *\n * The development client is the other. `expo run:ios` launches the app through\n * `<scheme>://expo-development-client/?url=...`, which is Expo telling its own launcher which\n * bundle to load and means nothing to the app. Left alone it reaches the router as a path, matches\n * no route, and the app shows a blank screen on every launch during development - which looks\n * exactly like a bug in the app.\n */\n\n/** Expo's own launch hosts. Not paths: instructions to the launcher, which the app never routes. */\nconst EXPO_INTERNAL = new Set(['expo-development-client']);\n\n/** Whether the first segment names one of Expo's launchers rather than something in the app. */\nfunction isLauncher(rest: string): boolean {\n return EXPO_INTERNAL.has(rest.split(/[/?#]/, 1)[0] ?? '');\n}\n\n/** Schemes that carry a host to skip before the path starts. */\nconst HAS_HOST = new Set(['http', 'https', 'exp', 'exps']);\n\n/**\n * The app's path after Expo Go's `/--/`, or null for a url with none in its path. In a query or a\n * fragment, `/--/` is the app's own: a search for it is not a launch prefix.\n */\nfunction expoGoPath(rest: string): string | null {\n const end = rest.search(/[?#]/);\n const marker = (end === -1 ? rest : rest.slice(0, end)).indexOf('/--/');\n return marker === -1 ? null : rest.slice(marker + 3);\n}\n\nexport function pathOf(url: string | null): string | null {\n if (!url) return null;\n const scheme = /^([a-z][a-z0-9+.-]*):\\/\\//i.exec(url);\n const rest = scheme ? url.slice(scheme[0].length) : url;\n\n const expoGo = expoGoPath(rest);\n if (expoGo !== null) return expoGo;\n if (isLauncher(rest)) return null;\n\n // A url with a host has one to skip. A custom scheme does not: `canary://settings` names a\n // path, not a machine, and treating the two alike is how it quietly becomes `/`.\n if (HAS_HOST.has(scheme?.[1]?.toLowerCase() ?? '')) {\n // The host ends at the path, or at a query or fragment when there is no path.\n const end = rest.search(/[/?#]/);\n if (end === -1) return '/';\n return rest[end] === '/' ? rest.slice(end) : `/${rest.slice(end)}`;\n }\n return rest.startsWith('/') ? rest : `/${rest}`;\n}\n\n/**\n * The launch url is delivered whichever way is true at the time: as the initial url if it is\n * known before anything asks, and as an ordinary link if the app is already up. Both happen -\n * the promise races the first navigation and neither order is guaranteed - and a link that\n * arrives late is still a link, so nothing is dropped either way.\n */\n@Service()\nexport class DeepLinks {\n /** Overridden in a test to deliver a link with no platform under it. */\n static readonly SOURCE = new InjectionToken<DeepLinkSource>('angular-native.deepLinkSource', {\n factory: deepLinkSource,\n });\n\n private readonly source = inject(DeepLinks.SOURCE);\n private readonly injector = inject(Injector);\n private launch: string | null = null;\n private readonly listeners = new Set<(path: string) => void>();\n\n constructor() {\n void this.source.launchUrl().then((url) => {\n const path = pathOf(url);\n if (!path || path === '/') return;\n if (this.listeners.size) this.listeners.forEach((listener) => this.deliver(listener, path));\n else this.launch = path;\n });\n }\n\n /** The path the app was launched with, if it is known yet. */\n initialUrl(): string | null {\n return this.launch;\n }\n\n /** Links that arrive while the app is running, as paths. Returns an unsubscribe. */\n subscribe(listener: (path: string) => void): () => void {\n // Each subscription is its own entry, so the same function subscribed twice stops once.\n const subscription = (path: string) => listener(path);\n this.listeners.add(subscription);\n const unsubscribe = this.source.subscribe((url) => {\n const path = pathOf(url);\n if (path) listener(path);\n });\n return () => {\n this.listeners.delete(subscription);\n unsubscribe();\n };\n }\n\n /**\n * One listener throwing is reported, and does not keep the launch url from the rest. The\n * `ErrorHandler` is looked up when that happens rather than when this is made: an app's handler\n * that injects the router reaches `DeepLinks` through the location, and would be a cycle at boot.\n */\n private deliver(listener: (path: string) => void, path: string): void {\n try {\n listener(path);\n } catch (error) {\n // A handler that rethrows, as some apps' do, would otherwise stop the listeners after this.\n try {\n const errors = this.injector.get(ErrorHandler, null);\n if (errors) errors.handleError(error);\n else console.error(error);\n } catch (reporting) {\n if (reporting === error) console.error(error);\n else console.error(error, reporting);\n }\n }\n }\n\n /**\n * Follow a path of the app's own as a link to it that arrived from outside is followed: a\n * library that sets `location.href` to a page of the app goes there the way a link does.\n */\n follow(path: string): void {\n this.listeners.forEach((listener) => this.deliver(listener, path));\n }\n\n /** Hand a url to whatever else on the device handles it: a browser, Maps, another app. */\n open(url: string): void {\n this.source.open(url);\n }\n\n /**\n * Open the app's own page in the system settings, where a person turns on a permission the\n * platform no longer asks for. Android has no url for that page, so `open()` cannot reach it.\n */\n openSettings(): void {\n this.source.openSettings?.();\n }\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -18,11 +18,13 @@ export { LayoutAnimation, type LayoutChange, type LayoutEasing, type NativeLayou
|
|
|
18
18
|
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
|
-
export { Keyboard, type KeyboardMetrics, type KeyboardSource } from './keyboard.ts';
|
|
21
|
+
export { KEYBOARD_MOTION, Keyboard, keyboardSource, type KeyboardMetrics, type KeyboardMotion, type KeyboardSource, } from './keyboard.ts';
|
|
22
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
25
|
export { StatusBar, statusBarSource, type PlatformStatusBarStyle, type StatusBarSource, type StatusBarState, type StatusBarStyle, } from './status-bar.ts';
|
|
26
|
+
export { TopClaim, WindowClaims, onWindowFront, sharedBySource, type Claim, } from './window-claims.ts';
|
|
26
27
|
export { NavigationBar, navigationBarSource, type NavigationBarSource, type NavigationBarState, type NavigationBarStyle, } from './navigation-bar.ts';
|
|
27
28
|
export { SCREEN_IN_FRONT } from './screen-in-front.ts';
|
|
29
|
+
export { NATIVE_HISTORY } from './native-history.ts';
|
|
28
30
|
export { OS_VERSION } from './os-version.ts';
|
package/dist/index.js
CHANGED
|
@@ -18,11 +18,13 @@ export { LayoutAnimation, } from "./layout-animation.js";
|
|
|
18
18
|
export { Sharing } from "./sharing.js";
|
|
19
19
|
export { Vibration } from "./vibration.js";
|
|
20
20
|
export { HardwareBack, hardwareBackSource } from "./hardware-back.js";
|
|
21
|
-
export { Keyboard } from "./keyboard.js";
|
|
21
|
+
export { KEYBOARD_MOTION, Keyboard, keyboardSource, } from "./keyboard.js";
|
|
22
22
|
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
|
+
export { TopClaim, WindowClaims, onWindowFront, sharedBySource, } from "./window-claims.js";
|
|
25
26
|
export { NavigationBar, navigationBarSource, } from "./navigation-bar.js";
|
|
26
27
|
export { SCREEN_IN_FRONT } from "./screen-in-front.js";
|
|
28
|
+
export { NATIVE_HISTORY } from "./native-history.js";
|
|
27
29
|
export { OS_VERSION } from "./os-version.js";
|
|
28
30
|
//# 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,cAAc,EAAE,MAAM,EAAuB,MAAM,iBAAiB,CAAC;AACzF,OAAO,EACL,SAAS,GAIV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,iBAAiB,GAGlB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,OAAO,EAA0C,MAA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,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,EAA4C,MAAM,aAAa,CAAC;AAC9F,OAAO,EACL,SAAS,EACT,eAAe,GAKhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,cAAc,GAEf,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,aAAa,EACb,mBAAmB,GAIpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,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, deepLinkSource, 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 {\n KEYBOARD_MOTION,\n Keyboard,\n keyboardSource,\n type KeyboardMetrics,\n type KeyboardMotion,\n type KeyboardSource,\n} 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 {\n TopClaim,\n WindowClaims,\n onWindowFront,\n sharedBySource,\n type Claim,\n} from './window-claims.ts';\nexport {\n NavigationBar,\n navigationBarSource,\n type NavigationBarSource,\n type NavigationBarState,\n type NavigationBarStyle,\n} from './navigation-bar.ts';\nexport { SCREEN_IN_FRONT } from './screen-in-front.ts';\nexport { NATIVE_HISTORY } from './native-history.ts';\nexport { OS_VERSION } from './os-version.ts';\n"]}
|
package/dist/keyboard.d.ts
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
* The software keyboard: where it is, and how long it takes to get there.
|
|
3
3
|
*
|
|
4
4
|
* On iOS the metrics change as the keyboard starts to move, with the duration and curve it is
|
|
5
|
-
* moving on, so a layout can move with it
|
|
5
|
+
* moving on, so a layout can move with it. On Android React Native says only where the keyboard is
|
|
6
|
+
* going, as it starts to move, with no duration, so a layout jumps there while the keyboard slides;
|
|
7
|
+
* `@ng-native/expo`'s `provideNativeKeyboard()` adds the duration and curve. See `keyboardSource`.
|
|
6
8
|
*/
|
|
7
9
|
import { InjectionToken, type Signal } from '@angular/core';
|
|
8
10
|
import * as i0 from "@angular/core";
|
|
@@ -16,16 +18,21 @@ export interface KeyboardMetrics {
|
|
|
16
18
|
readonly duration?: number;
|
|
17
19
|
/**
|
|
18
20
|
* The curve its own animation runs on, for anything moving with it to match: one of
|
|
19
|
-
* `LayoutEasing`'s names. On iOS that is usually `'keyboard'`, the keyboard's own curve.
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
21
|
+
* `LayoutEasing`'s names. On iOS that is usually `'keyboard'`, the keyboard's own curve. React
|
|
22
|
+
* Native's own events on Android carry `'keyboard'` with a duration of zero: they say where the
|
|
23
|
+
* keyboard is going and nothing of how it gets there, so nothing should try to animate alongside
|
|
24
|
+
* them. `provideNativeKeyboard()` reports Android's duration, with `'easeOut'`.
|
|
23
25
|
*/
|
|
24
26
|
readonly easing?: string;
|
|
25
27
|
}
|
|
26
28
|
/** Where the metrics come from. A fake stands in for the platform in tests. */
|
|
27
29
|
export interface KeyboardSource {
|
|
28
30
|
subscribe(listener: (metrics: KeyboardMetrics) => void): () => void;
|
|
31
|
+
/**
|
|
32
|
+
* Where the keyboard is at each frame of its motion, for a source that knows: before the motion
|
|
33
|
+
* starts, at every frame of it, and null once it is over. One that does not has no such method.
|
|
34
|
+
*/
|
|
35
|
+
subscribeMotion?(listener: (frame: KeyboardMetrics | null) => void): () => void;
|
|
29
36
|
dismiss(): void;
|
|
30
37
|
}
|
|
31
38
|
/**
|
|
@@ -38,10 +45,25 @@ export interface KeyboardSource {
|
|
|
38
45
|
* is ignored while it is down: UIKit posts one beside every show and hide as well, and the one
|
|
39
46
|
* beside a hide is the frame the keyboard leaves by, off the bottom of the screen.
|
|
40
47
|
*
|
|
41
|
-
* Android sends no Will events at all, so there it is the Did events
|
|
42
|
-
*
|
|
48
|
+
* Android sends no Will events at all, so there it is the Did events. They arrive once the
|
|
49
|
+
* window's insets have changed, which is as the keyboard starts to move rather than once it has
|
|
50
|
+
* stopped, with a duration of zero: they say nothing of the motion.
|
|
43
51
|
*/
|
|
44
52
|
export declare function keyboardSource(): KeyboardSource;
|
|
53
|
+
/**
|
|
54
|
+
* A native view that reports the keyboard's motion frame by frame, for a view to follow it on the
|
|
55
|
+
* native side: a `<keyboard-dock>` on Android, where React Native says only where the keyboard
|
|
56
|
+
* is going. `@ng-native/expo`'s `provideNativeKeyboard()` provides one; without it this is null.
|
|
57
|
+
*
|
|
58
|
+
* The view sends `onKeyboardMoveStart`, `onKeyboardMove` and `onKeyboardMoveEnd`, each with the
|
|
59
|
+
* `height` of the keyboard over the view's own bottom edge, in points, and is laid out over the
|
|
60
|
+
* element it reports for.
|
|
61
|
+
*/
|
|
62
|
+
export interface KeyboardMotion {
|
|
63
|
+
/** The Fabric name of the view. */
|
|
64
|
+
readonly viewName: string;
|
|
65
|
+
}
|
|
66
|
+
export declare const KEYBOARD_MOTION: InjectionToken<KeyboardMotion | null>;
|
|
45
67
|
/**
|
|
46
68
|
* Subscribed for the life of the app, which is the life of the service, and removed when the app
|
|
47
69
|
* is destroyed. A component that mounts mid-gesture wants the height that is already true rather
|
|
@@ -55,10 +77,22 @@ export declare class Keyboard {
|
|
|
55
77
|
static readonly SOURCE: InjectionToken<KeyboardSource>;
|
|
56
78
|
private readonly source;
|
|
57
79
|
private readonly current;
|
|
58
|
-
|
|
80
|
+
private readonly frame;
|
|
81
|
+
/**
|
|
82
|
+
* Everything the platform said, for a layout that needs the animation duration too. It changes
|
|
83
|
+
* as the keyboard starts to move, to where the keyboard is going.
|
|
84
|
+
*/
|
|
59
85
|
readonly metrics: Signal<KeyboardMetrics>;
|
|
60
86
|
readonly height: Signal<number>;
|
|
61
87
|
readonly visible: Signal<boolean>;
|
|
88
|
+
/**
|
|
89
|
+
* Whether `position` follows the keyboard frame by frame: on Android with `@ng-native/expo`'s
|
|
90
|
+
* `provideNativeKeyboard()`, where a layout cannot animate alongside the keyboard and has to
|
|
91
|
+
* move with it instead. Elsewhere it is `metrics`, and a layout animates to where that says.
|
|
92
|
+
*/
|
|
93
|
+
readonly followsMotion: boolean;
|
|
94
|
+
/** Where the keyboard is now: at every frame of its motion where `followsMotion`. */
|
|
95
|
+
readonly position: Signal<KeyboardMetrics>;
|
|
62
96
|
constructor();
|
|
63
97
|
/** Put the keyboard away, as tapping outside a field would. */
|
|
64
98
|
dismiss(): void;
|
package/dist/keyboard.js
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
* The software keyboard: where it is, and how long it takes to get there.
|
|
3
3
|
*
|
|
4
4
|
* On iOS the metrics change as the keyboard starts to move, with the duration and curve it is
|
|
5
|
-
* moving on, so a layout can move with it
|
|
5
|
+
* moving on, so a layout can move with it. On Android React Native says only where the keyboard is
|
|
6
|
+
* going, as it starts to move, with no duration, so a layout jumps there while the keyboard slides;
|
|
7
|
+
* `@ng-native/expo`'s `provideNativeKeyboard()` adds the duration and curve. See `keyboardSource`.
|
|
6
8
|
*/
|
|
7
9
|
import { DestroyRef, InjectionToken, Service, computed, inject, signal, } from '@angular/core';
|
|
8
10
|
import { reactNative } from "./react-native.js";
|
|
@@ -28,8 +30,9 @@ const metricsOf = (event) => ({
|
|
|
28
30
|
* is ignored while it is down: UIKit posts one beside every show and hide as well, and the one
|
|
29
31
|
* beside a hide is the frame the keyboard leaves by, off the bottom of the screen.
|
|
30
32
|
*
|
|
31
|
-
* Android sends no Will events at all, so there it is the Did events
|
|
32
|
-
*
|
|
33
|
+
* Android sends no Will events at all, so there it is the Did events. They arrive once the
|
|
34
|
+
* window's insets have changed, which is as the keyboard starts to move rather than once it has
|
|
35
|
+
* stopped, with a duration of zero: they say nothing of the motion.
|
|
33
36
|
*/
|
|
34
37
|
export function keyboardSource() {
|
|
35
38
|
const native = reactNative();
|
|
@@ -65,6 +68,7 @@ export function keyboardSource() {
|
|
|
65
68
|
dismiss: () => keyboard.dismiss(),
|
|
66
69
|
};
|
|
67
70
|
}
|
|
71
|
+
export const KEYBOARD_MOTION = new InjectionToken('angular-native.keyboardMotion', { providedIn: 'root', factory: () => null });
|
|
68
72
|
/**
|
|
69
73
|
* Subscribed for the life of the app, which is the life of the service, and removed when the app
|
|
70
74
|
* is destroyed. A component that mounts mid-gesture wants the height that is already true rather
|
|
@@ -81,14 +85,32 @@ export class Keyboard {
|
|
|
81
85
|
source = inject(Keyboard.SOURCE);
|
|
82
86
|
current = signal({ height: 0 }, /* @ts-ignore */
|
|
83
87
|
...(ngDevMode ? [{ debugName: "current" }] : /* istanbul ignore next */ []));
|
|
84
|
-
|
|
88
|
+
frame = signal(null, /* @ts-ignore */
|
|
89
|
+
...(ngDevMode ? [{ debugName: "frame" }] : /* istanbul ignore next */ []));
|
|
90
|
+
/**
|
|
91
|
+
* Everything the platform said, for a layout that needs the animation duration too. It changes
|
|
92
|
+
* as the keyboard starts to move, to where the keyboard is going.
|
|
93
|
+
*/
|
|
85
94
|
metrics = this.current.asReadonly();
|
|
86
95
|
height = computed(() => this.current().height, /* @ts-ignore */
|
|
87
96
|
...(ngDevMode ? [{ debugName: "height" }] : /* istanbul ignore next */ []));
|
|
88
97
|
visible = computed(() => this.current().height > 0, /* @ts-ignore */
|
|
89
98
|
...(ngDevMode ? [{ debugName: "visible" }] : /* istanbul ignore next */ []));
|
|
99
|
+
/**
|
|
100
|
+
* Whether `position` follows the keyboard frame by frame: on Android with `@ng-native/expo`'s
|
|
101
|
+
* `provideNativeKeyboard()`, where a layout cannot animate alongside the keyboard and has to
|
|
102
|
+
* move with it instead. Elsewhere it is `metrics`, and a layout animates to where that says.
|
|
103
|
+
*/
|
|
104
|
+
followsMotion = this.source.subscribeMotion !== undefined;
|
|
105
|
+
/** Where the keyboard is now: at every frame of its motion where `followsMotion`. */
|
|
106
|
+
position = computed(() => this.frame() ?? this.current(), /* @ts-ignore */
|
|
107
|
+
...(ngDevMode ? [{ debugName: "position" }] : /* istanbul ignore next */ []));
|
|
90
108
|
constructor() {
|
|
91
|
-
inject(DestroyRef)
|
|
109
|
+
const destroyRef = inject(DestroyRef);
|
|
110
|
+
destroyRef.onDestroy(this.source.subscribe((metrics) => this.current.set(metrics)));
|
|
111
|
+
const stop = this.source.subscribeMotion?.((frame) => this.frame.set(frame));
|
|
112
|
+
if (stop)
|
|
113
|
+
destroyRef.onDestroy(stop);
|
|
92
114
|
}
|
|
93
115
|
/** Put the keyboard away, as tapping outside a field would. */
|
|
94
116
|
dismiss() {
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AO,QAAQ;IACnB;;;OAGG;IACH,MAAM,CAAU,MAAM,GAAG,IAAI,cAAc,CAAiB,+BAA+B,EAAE;QAC3F,OAAO,EAAE,cAAc;KACxB,CAAC,CAAC;IAEc,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACjC,OAAO,GAAG,MAAM,CAAkB,EAAE,MAAM,EAAE,CAAC,EAAE;gFAAC,CAAC;IAElE,wFAAwF;IAC/E,OAAO,GAA4B,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;IAC7D,MAAM,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,MAAM;+EAAC,CAAC;IAC/C,OAAO,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,MAAM,GAAG,CAAC;gFAAC,CAAC;IAE7D;QACE,MAAM,CAAC,UAAU,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAC9F,CAAC;IAED,+DAA+D;IAC/D,OAAO;QACL,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;IACxB,CAAC;uGAxBU,QAAQ;wGAAR,QAAQ;;2FAAR,QAAQ;kBADpB,OAAO","sourcesContent":["/**\n * The software keyboard: where it is, and how long it takes to get there.\n *\n * On iOS the metrics change as the keyboard starts to move, with the duration and curve it is\n * moving on, so a layout can move with it; on Android, once it has arrived. See `keyboardSource`.\n */\nimport {\n DestroyRef,\n InjectionToken,\n Service,\n computed,\n inject,\n signal,\n type Signal,\n} from '@angular/core';\nimport { reactNative, type NativeKeyboardEvent } from './react-native.ts';\n\n/** What the platform reports when the keyboard moves. */\nexport interface KeyboardMetrics {\n /** Height in dp; zero when the keyboard is hidden. */\n readonly height: number;\n /** Where its top edge is, from the top of the screen. Absent when hidden. */\n readonly screenY?: number;\n /** How long its own animation takes, in ms, for anything moving with it. */\n readonly duration?: number;\n /**\n * The curve its own animation runs on, for anything moving with it to match: one of\n * `LayoutEasing`'s names. On iOS that is usually `'keyboard'`, the keyboard's own curve. On\n * Android it is always `'keyboard'` paired with a duration of zero: the platform animates its\n * own keyboard, the event arrives once it has, and nothing here should try to animate alongside\n * it.\n */\n readonly easing?: string;\n}\n\n/** Where the metrics come from. A fake stands in for the platform in tests. */\nexport interface KeyboardSource {\n subscribe(listener: (metrics: KeyboardMetrics) => void): () => void;\n dismiss(): void;\n}\n\n/** The timing a keyboard event carries, when it carries any. */\nfunction timingOf(event: NativeKeyboardEvent): Pick<KeyboardMetrics, 'duration' | 'easing'> {\n if (event.duration === undefined) return {};\n return { duration: event.duration, easing: event.easing };\n}\n\nconst metricsOf = (event: NativeKeyboardEvent): KeyboardMetrics => ({\n height: event.endCoordinates.height,\n screenY: event.endCoordinates.screenY,\n ...timingOf(event),\n});\n\n/**\n * The events RN's own KeyboardAvoidingView listens for, which differ by platform.\n *\n * On iOS the Will events: they arrive as the keyboard starts to move, carrying its duration and\n * curve, so a layout configured from them moves with the keyboard. The Did events arrive once it\n * has landed, and a layout that waits for them moves after it. `keyboardWillChangeFrame` covers a\n * keyboard that changes size while it is up - the predictive bar, another language's layout - and\n * is ignored while it is down: UIKit posts one beside every show and hide as well, and the one\n * beside a hide is the frame the keyboard leaves by, off the bottom of the screen.\n *\n * Android sends no Will events at all, so there it is the Did events, which arrive with a\n * duration of zero because the platform animates its own keyboard.\n */\nexport function keyboardSource(): KeyboardSource {\n const native = reactNative();\n if (!native) return { subscribe: () => () => {}, dismiss: () => {} };\n const { Keyboard: keyboard, Platform } = native;\n\n return {\n subscribe: (listener) => {\n if (Platform?.OS !== 'ios') {\n const subscriptions = [\n keyboard.addListener('keyboardDidShow', (event) => listener(metricsOf(event))),\n keyboard.addListener('keyboardDidHide', () => listener({ height: 0 })),\n ];\n return () => subscriptions.forEach((subscription) => subscription.remove());\n }\n let up = false;\n const subscriptions = [\n keyboard.addListener('keyboardWillShow', (event) => {\n up = true;\n listener(metricsOf(event));\n }),\n keyboard.addListener('keyboardWillChangeFrame', (event) => {\n if (up) listener(metricsOf(event));\n }),\n keyboard.addListener('keyboardWillHide', (event) => {\n up = false;\n listener({ height: 0, ...timingOf(event) });\n }),\n ];\n return () => subscriptions.forEach((subscription) => subscription.remove());\n },\n dismiss: () => keyboard.dismiss(),\n };\n}\n\n/**\n * Subscribed for the life of the app, which is the life of the service, and removed when the app\n * is destroyed. A component that mounts mid-gesture wants the height that is already true rather\n * than the next change, which is why the subscription is the service's and not the component's.\n */\n@Service()\nexport class Keyboard {\n /**\n * Where the metrics actually come from. Overriding this token is how a test drives the keyboard,\n * and it is finer than replacing the service: the code under test stays the real thing.\n */\n static readonly SOURCE = new InjectionToken<KeyboardSource>('angular-native.keyboardSource', {\n factory: keyboardSource,\n });\n\n private readonly source = inject(Keyboard.SOURCE);\n private readonly current = signal<KeyboardMetrics>({ height: 0 });\n\n /** Everything the platform said, for a layout that needs the animation duration too. */\n readonly metrics: Signal<KeyboardMetrics> = this.current.asReadonly();\n readonly height = computed(() => this.current().height);\n readonly visible = computed(() => this.current().height > 0);\n\n constructor() {\n inject(DestroyRef).onDestroy(this.source.subscribe((metrics) => this.current.set(metrics)));\n }\n\n /** Put the keyboard away, as tapping outside a field would. */\n dismiss(): void {\n this.source.dismiss();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"keyboard.js","sourceRoot":"","sources":["../src/keyboard.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACL,UAAU,EACV,cAAc,EACd,OAAO,EACP,QAAQ,EACR,MAAM,EACN,MAAM,GAEP,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,WAAW,EAA4B,MAAM,mBAAmB,CAAC;;AA+B1E,gEAAgE;AAChE,SAAS,QAAQ,CAAC,KAA0B;IAC1C,IAAI,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ourcesContent":["/**\n * The software keyboard: where it is, and how long it takes to get there.\n *\n * On iOS the metrics change as the keyboard starts to move, with the duration and curve it is\n * moving on, so a layout can move with it. On Android React Native says only where the keyboard is\n * going, as it starts to move, with no duration, so a layout jumps there while the keyboard slides;\n * `@ng-native/expo`'s `provideNativeKeyboard()` adds the duration and curve. See `keyboardSource`.\n */\nimport {\n DestroyRef,\n InjectionToken,\n Service,\n computed,\n inject,\n signal,\n type Signal,\n} from '@angular/core';\nimport { reactNative, type NativeKeyboardEvent } from './react-native.ts';\n\n/** What the platform reports when the keyboard moves. */\nexport interface KeyboardMetrics {\n /** Height in dp; zero when the keyboard is hidden. */\n readonly height: number;\n /** Where its top edge is, from the top of the screen. Absent when hidden. */\n readonly screenY?: number;\n /** How long its own animation takes, in ms, for anything moving with it. */\n readonly duration?: number;\n /**\n * The curve its own animation runs on, for anything moving with it to match: one of\n * `LayoutEasing`'s names. On iOS that is usually `'keyboard'`, the keyboard's own curve. React\n * Native's own events on Android carry `'keyboard'` with a duration of zero: they say where the\n * keyboard is going and nothing of how it gets there, so nothing should try to animate alongside\n * them. `provideNativeKeyboard()` reports Android's duration, with `'easeOut'`.\n */\n readonly easing?: string;\n}\n\n/** Where the metrics come from. A fake stands in for the platform in tests. */\nexport interface KeyboardSource {\n subscribe(listener: (metrics: KeyboardMetrics) => void): () => void;\n /**\n * Where the keyboard is at each frame of its motion, for a source that knows: before the motion\n * starts, at every frame of it, and null once it is over. One that does not has no such method.\n */\n subscribeMotion?(listener: (frame: KeyboardMetrics | null) => void): () => void;\n dismiss(): void;\n}\n\n/** The timing a keyboard event carries, when it carries any. */\nfunction timingOf(event: NativeKeyboardEvent): Pick<KeyboardMetrics, 'duration' | 'easing'> {\n if (event.duration === undefined) return {};\n return { duration: event.duration, easing: event.easing };\n}\n\nconst metricsOf = (event: NativeKeyboardEvent): KeyboardMetrics => ({\n height: event.endCoordinates.height,\n screenY: event.endCoordinates.screenY,\n ...timingOf(event),\n});\n\n/**\n * The events RN's own KeyboardAvoidingView listens for, which differ by platform.\n *\n * On iOS the Will events: they arrive as the keyboard starts to move, carrying its duration and\n * curve, so a layout configured from them moves with the keyboard. The Did events arrive once it\n * has landed, and a layout that waits for them moves after it. `keyboardWillChangeFrame` covers a\n * keyboard that changes size while it is up - the predictive bar, another language's layout - and\n * is ignored while it is down: UIKit posts one beside every show and hide as well, and the one\n * beside a hide is the frame the keyboard leaves by, off the bottom of the screen.\n *\n * Android sends no Will events at all, so there it is the Did events. They arrive once the\n * window's insets have changed, which is as the keyboard starts to move rather than once it has\n * stopped, with a duration of zero: they say nothing of the motion.\n */\nexport function keyboardSource(): KeyboardSource {\n const native = reactNative();\n if (!native) return { subscribe: () => () => {}, dismiss: () => {} };\n const { Keyboard: keyboard, Platform } = native;\n\n return {\n subscribe: (listener) => {\n if (Platform?.OS !== 'ios') {\n const subscriptions = [\n keyboard.addListener('keyboardDidShow', (event) => listener(metricsOf(event))),\n keyboard.addListener('keyboardDidHide', () => listener({ height: 0 })),\n ];\n return () => subscriptions.forEach((subscription) => subscription.remove());\n }\n let up = false;\n const subscriptions = [\n keyboard.addListener('keyboardWillShow', (event) => {\n up = true;\n listener(metricsOf(event));\n }),\n keyboard.addListener('keyboardWillChangeFrame', (event) => {\n if (up) listener(metricsOf(event));\n }),\n keyboard.addListener('keyboardWillHide', (event) => {\n up = false;\n listener({ height: 0, ...timingOf(event) });\n }),\n ];\n return () => subscriptions.forEach((subscription) => subscription.remove());\n },\n dismiss: () => keyboard.dismiss(),\n };\n}\n\n/**\n * A native view that reports the keyboard's motion frame by frame, for a view to follow it on the\n * native side: a `<keyboard-dock>` on Android, where React Native says only where the keyboard\n * is going. `@ng-native/expo`'s `provideNativeKeyboard()` provides one; without it this is null.\n *\n * The view sends `onKeyboardMoveStart`, `onKeyboardMove` and `onKeyboardMoveEnd`, each with the\n * `height` of the keyboard over the view's own bottom edge, in points, and is laid out over the\n * element it reports for.\n */\nexport interface KeyboardMotion {\n /** The Fabric name of the view. */\n readonly viewName: string;\n}\n\nexport const KEYBOARD_MOTION = new InjectionToken<KeyboardMotion | null>(\n 'angular-native.keyboardMotion',\n { providedIn: 'root', factory: () => null },\n);\n\n/**\n * Subscribed for the life of the app, which is the life of the service, and removed when the app\n * is destroyed. A component that mounts mid-gesture wants the height that is already true rather\n * than the next change, which is why the subscription is the service's and not the component's.\n */\n@Service()\nexport class Keyboard {\n /**\n * Where the metrics actually come from. Overriding this token is how a test drives the keyboard,\n * and it is finer than replacing the service: the code under test stays the real thing.\n */\n static readonly SOURCE = new InjectionToken<KeyboardSource>('angular-native.keyboardSource', {\n factory: keyboardSource,\n });\n\n private readonly source = inject(Keyboard.SOURCE);\n private readonly current = signal<KeyboardMetrics>({ height: 0 });\n private readonly frame = signal<KeyboardMetrics | null>(null);\n\n /**\n * Everything the platform said, for a layout that needs the animation duration too. It changes\n * as the keyboard starts to move, to where the keyboard is going.\n */\n readonly metrics: Signal<KeyboardMetrics> = this.current.asReadonly();\n readonly height = computed(() => this.current().height);\n readonly visible = computed(() => this.current().height > 0);\n\n /**\n * Whether `position` follows the keyboard frame by frame: on Android with `@ng-native/expo`'s\n * `provideNativeKeyboard()`, where a layout cannot animate alongside the keyboard and has to\n * move with it instead. Elsewhere it is `metrics`, and a layout animates to where that says.\n */\n readonly followsMotion = this.source.subscribeMotion !== undefined;\n\n /** Where the keyboard is now: at every frame of its motion where `followsMotion`. */\n readonly position: Signal<KeyboardMetrics> = computed(() => this.frame() ?? this.current());\n\n constructor() {\n const destroyRef = inject(DestroyRef);\n destroyRef.onDestroy(this.source.subscribe((metrics) => this.current.set(metrics)));\n const stop = this.source.subscribeMotion?.((frame) => this.frame.set(frame));\n if (stop) destroyRef.onDestroy(stop);\n }\n\n /** Put the keyboard away, as tapping outside a field would. */\n dismiss(): void {\n this.source.dismiss();\n }\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every claim in order, later ones winning per property. A property set to `undefined` is as
|
|
3
|
+
* absent as a missing one and leaves whatever the claim underneath said: `{ style: maybeStyle }`
|
|
4
|
+
* compiles without `exactOptionalPropertyTypes`, and a spread would let it wipe the value.
|
|
5
|
+
*/
|
|
6
|
+
export declare function mergeClaims<T extends object>(claims: readonly T[]): T;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every claim in order, later ones winning per property. A property set to `undefined` is as
|
|
3
|
+
* absent as a missing one and leaves whatever the claim underneath said: `{ style: maybeStyle }`
|
|
4
|
+
* compiles without `exactOptionalPropertyTypes`, and a spread would let it wipe the value.
|
|
5
|
+
*/
|
|
6
|
+
export function mergeClaims(claims) {
|
|
7
|
+
const merged = {};
|
|
8
|
+
for (const claim of claims) {
|
|
9
|
+
for (const [key, value] of Object.entries(claim)) {
|
|
10
|
+
if (value !== undefined)
|
|
11
|
+
merged[key] = value;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return merged;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=merge-claims.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge-claims.js","sourceRoot":"","sources":["../src/merge-claims.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAmB,MAAoB;IAChE,MAAM,MAAM,GAA4B,EAAE,CAAC;IAC3C,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACjD,IAAI,KAAK,KAAK,SAAS;gBAAE,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QAC/C,CAAC;IACH,CAAC;IACD,OAAO,MAAW,CAAC;AACrB,CAAC","sourcesContent":["/**\n * Every claim in order, later ones winning per property. A property set to `undefined` is as\n * absent as a missing one and leaves whatever the claim underneath said: `{ style: maybeStyle }`\n * compiles without `exactOptionalPropertyTypes`, and a spread would let it wipe the value.\n */\nexport function mergeClaims<T extends object>(claims: readonly T[]): T {\n const merged: Record<string, unknown> = {};\n for (const claim of claims) {\n for (const [key, value] of Object.entries(claim)) {\n if (value !== undefined) merged[key] = value;\n }\n }\n return merged as T;\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { InjectionToken } from '@angular/core';
|
|
2
|
+
/**
|
|
3
|
+
* The history the native router keeps, where an app has one: `provideNativeRouter()` provides its
|
|
4
|
+
* `PlatformLocation` here, and as `PlatformLocation` from here. A package that stands one in for an
|
|
5
|
+
* app with no router reads this first, so the router's is kept in whichever order the two are
|
|
6
|
+
* provided.
|
|
7
|
+
*/
|
|
8
|
+
export declare const NATIVE_HISTORY: InjectionToken<object>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { InjectionToken } from '@angular/core';
|
|
2
|
+
/**
|
|
3
|
+
* The history the native router keeps, where an app has one: `provideNativeRouter()` provides its
|
|
4
|
+
* `PlatformLocation` here, and as `PlatformLocation` from here. A package that stands one in for an
|
|
5
|
+
* app with no router reads this first, so the router's is kept in whichever order the two are
|
|
6
|
+
* provided.
|
|
7
|
+
*/
|
|
8
|
+
export const NATIVE_HISTORY = new InjectionToken('angular-native.nativeHistory');
|
|
9
|
+
//# sourceMappingURL=native-history.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-history.js","sourceRoot":"","sources":["../src/native-history.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,cAAc,CAAS,8BAA8B,CAAC,CAAC","sourcesContent":["import { InjectionToken } from '@angular/core';\n\n/**\n * The history the native router keeps, where an app has one: `provideNativeRouter()` provides its\n * `PlatformLocation` here, and as `PlatformLocation` from here. A package that stands one in for an\n * app with no router reads this first, so the router's is kept in whichever order the two are\n * provided.\n */\nexport const NATIVE_HISTORY = new InjectionToken<object>('angular-native.nativeHistory');\n"]}
|
package/dist/navigation-bar.d.ts
CHANGED
|
@@ -33,6 +33,8 @@ export interface NavigationBarSource {
|
|
|
33
33
|
* `navigationBarHidden`, once any screen has set one. So a hidden claim rides on every screen too.
|
|
34
34
|
*/
|
|
35
35
|
readonly screensSetBar?: boolean;
|
|
36
|
+
/** Calls `listener` when a window comes to the front, to be given the whole bar again. */
|
|
37
|
+
onWindowFront?(listener: () => void): () => void;
|
|
36
38
|
}
|
|
37
39
|
export declare function navigationBarSource(): NavigationBarSource;
|
|
38
40
|
/**
|
|
@@ -43,8 +45,10 @@ export declare class NavigationBar {
|
|
|
43
45
|
/** Overridden in a test to watch the bar without one on screen. */
|
|
44
46
|
static readonly SOURCE: InjectionToken<NavigationBarSource>;
|
|
45
47
|
private readonly source;
|
|
46
|
-
|
|
47
|
-
private readonly
|
|
48
|
+
/** This app, among the apps claiming the bar: its scheme is what an `auto` style it claims follows. */
|
|
49
|
+
private readonly owner;
|
|
50
|
+
/** Every app's claims on this bar: the window is the runtime's, not an app's. */
|
|
51
|
+
private readonly window;
|
|
48
52
|
/** What is actually showing: every claim in order, later ones winning per property. */
|
|
49
53
|
readonly state: Signal<NavigationBarState>;
|
|
50
54
|
/**
|
|
@@ -59,16 +63,6 @@ export declare class NavigationBar {
|
|
|
59
63
|
set(state: NavigationBarState): void;
|
|
60
64
|
/** A claim on top of whatever is there. Call the returned function to drop it. */
|
|
61
65
|
push(state: NavigationBarState): () => void;
|
|
62
|
-
/** The properties a claim has had the platform change, which no claim names any more. */
|
|
63
|
-
private readonly changed;
|
|
64
|
-
/** Whether a claim has ever set the style, after which an unclaimed bar follows the scheme. */
|
|
65
|
-
private styled;
|
|
66
|
-
/**
|
|
67
|
-
* Push the merged state at the platform. A property the last claim to name it has dropped goes
|
|
68
|
-
* back, once: the style to `auto`, which then keeps following the scheme, and the bar to shown.
|
|
69
|
-
*/
|
|
70
|
-
private apply;
|
|
71
|
-
private changes;
|
|
72
66
|
static ɵfac: i0.ɵɵFactoryDeclaration<NavigationBar, never>;
|
|
73
67
|
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
74
68
|
}
|