@ng-native/device 0.16.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/navigation-bar.js
CHANGED
|
@@ -10,9 +10,11 @@
|
|
|
10
10
|
* `expo-navigation-bar`. Without it, and on iOS, which has no navigation bar, every claim is kept
|
|
11
11
|
* but changes nothing.
|
|
12
12
|
*/
|
|
13
|
-
import { DestroyRef, InjectionToken, Service, computed, inject,
|
|
13
|
+
import { DestroyRef, InjectionToken, Service, computed, inject, untracked, } from '@angular/core';
|
|
14
14
|
import { ColorScheme } from "./color-scheme.js";
|
|
15
|
+
import { mergeClaims } from "./merge-claims.js";
|
|
15
16
|
import { reactNative } from "./react-native.js";
|
|
17
|
+
import { WindowClaims, onWindowFront, sharedBySource } from "./window-claims.js";
|
|
16
18
|
import * as i0 from "@angular/core";
|
|
17
19
|
const NONE = { setStyle: () => { }, setHidden: () => { } };
|
|
18
20
|
export function navigationBarSource() {
|
|
@@ -24,11 +26,13 @@ export function navigationBarSource() {
|
|
|
24
26
|
// react-native-screens would hide the bar the next time one appears.
|
|
25
27
|
if (!native)
|
|
26
28
|
return NONE;
|
|
27
|
-
|
|
29
|
+
// One per module, so every app the runtime mounts claims the same bar.
|
|
30
|
+
return sharedBySource(native, () => ({
|
|
28
31
|
setStyle: (style) => void native.setStyle?.(style)?.catch(() => { }),
|
|
29
32
|
setHidden: (hidden) => void native.setHidden?.(hidden)?.catch(() => { }),
|
|
30
33
|
screensSetBar: true,
|
|
31
|
-
|
|
34
|
+
onWindowFront,
|
|
35
|
+
}));
|
|
32
36
|
}
|
|
33
37
|
/**
|
|
34
38
|
* A stack, not a setter, for the same reason as `StatusBar`'s: whatever hid the bar has to give it
|
|
@@ -38,12 +42,12 @@ export class NavigationBar {
|
|
|
38
42
|
/** Overridden in a test to watch the bar without one on screen. */
|
|
39
43
|
static SOURCE = new InjectionToken('angular-native.navigationBarSource', { factory: navigationBarSource });
|
|
40
44
|
source = inject(NavigationBar.SOURCE);
|
|
41
|
-
scheme
|
|
42
|
-
|
|
43
|
-
|
|
45
|
+
/** This app, among the apps claiming the bar: its scheme is what an `auto` style it claims follows. */
|
|
46
|
+
owner = { scheme: inject(ColorScheme) };
|
|
47
|
+
/** Every app's claims on this bar: the window is the runtime's, not an app's. */
|
|
48
|
+
window = sharedBySource(this.source, () => new NavigationBarWindow(this.source));
|
|
44
49
|
/** What is actually showing: every claim in order, later ones winning per property. */
|
|
45
|
-
state =
|
|
46
|
-
...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
|
|
50
|
+
state = this.window.state;
|
|
47
51
|
/**
|
|
48
52
|
* What a screen with no `navigationBarHidden` of its own carries, so the claim still holds when
|
|
49
53
|
* it appears. Empty but on Android. The router passes it on.
|
|
@@ -52,60 +56,94 @@ export class NavigationBar {
|
|
|
52
56
|
...(ngDevMode ? [{ debugName: "forScreens" }] : /* istanbul ignore next */ []));
|
|
53
57
|
constructor() {
|
|
54
58
|
// Straight from the source, as `StatusBar` does, so the buttons change in the same turn as the
|
|
55
|
-
// scheme.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
// scheme.
|
|
60
|
+
const stop = inject(ColorScheme.SOURCE).subscribe((scheme) => this.window.schemeChanged(this.owner, scheme));
|
|
61
|
+
inject(DestroyRef).onDestroy(() => {
|
|
62
|
+
stop();
|
|
63
|
+
// An app that goes takes its claims with it, and leaves the bar to the apps still here.
|
|
64
|
+
this.window.claims.drop(this.owner);
|
|
65
|
+
this.window.apply();
|
|
62
66
|
});
|
|
63
|
-
inject(DestroyRef).onDestroy(stop);
|
|
64
67
|
}
|
|
65
68
|
/** The base claim, for an app that sets the bar once at startup. */
|
|
66
69
|
set(state) {
|
|
67
|
-
this.
|
|
68
|
-
this.apply();
|
|
70
|
+
this.window.claims.setBase(this.owner, state);
|
|
71
|
+
this.window.apply();
|
|
69
72
|
}
|
|
70
73
|
/** A claim on top of whatever is there. Call the returned function to drop it. */
|
|
71
74
|
push(state) {
|
|
72
|
-
const
|
|
73
|
-
this.
|
|
74
|
-
this.apply();
|
|
75
|
+
const drop = this.window.claims.push(this.owner, { ...state });
|
|
76
|
+
this.window.apply();
|
|
75
77
|
return () => {
|
|
76
|
-
|
|
77
|
-
this.apply();
|
|
78
|
+
drop();
|
|
79
|
+
this.window.apply();
|
|
78
80
|
};
|
|
79
81
|
}
|
|
82
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: NavigationBar, deps: [], target: i0.ɵɵFactoryTarget.Service });
|
|
83
|
+
static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.2.0", ngImport: i0, type: NavigationBar });
|
|
84
|
+
}
|
|
85
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: NavigationBar, decorators: [{
|
|
86
|
+
type: Service
|
|
87
|
+
}], ctorParameters: () => [] });
|
|
88
|
+
/** The bar, as every app on one source claims it. */
|
|
89
|
+
class NavigationBarWindow {
|
|
90
|
+
claims = new WindowClaims();
|
|
91
|
+
state = computed(() => mergeClaims(this.claims.all().map((claim) => claim.value)), /* @ts-ignore */
|
|
92
|
+
...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
|
|
80
93
|
/** The properties a claim has had the platform change, which no claim names any more. */
|
|
81
94
|
changed = new Set();
|
|
82
95
|
/** Whether a claim has ever set the style, after which an unclaimed bar follows the scheme. */
|
|
83
96
|
styled = false;
|
|
97
|
+
source;
|
|
98
|
+
constructor(source) {
|
|
99
|
+
this.source = source;
|
|
100
|
+
// Lives as long as the source, which is the runtime's.
|
|
101
|
+
source.onWindowFront?.(() => this.apply(true));
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Android puts the buttons back to the new scheme's own on a scheme change, so a fixed style is
|
|
105
|
+
* sent again too. A bar no style claim names any more is `auto`, once one has named a style, and
|
|
106
|
+
* follows the scheme the listener heard.
|
|
107
|
+
*/
|
|
108
|
+
schemeChanged(owner, scheme) {
|
|
109
|
+
const claimed = untracked(() => this.styleOwner());
|
|
110
|
+
if (claimed && claimed.owner !== owner)
|
|
111
|
+
return;
|
|
112
|
+
const style = claimed?.style ?? (this.styled ? 'auto' : undefined);
|
|
113
|
+
if (style !== undefined)
|
|
114
|
+
this.source.setStyle(resolve(style, scheme));
|
|
115
|
+
}
|
|
84
116
|
/**
|
|
85
117
|
* Push the merged state at the platform. A property the last claim to name it has dropped goes
|
|
86
118
|
* back, once: the style to `auto`, which then keeps following the scheme, and the bar to shown.
|
|
119
|
+
* A window come to the front is given what is claimed, and an `auto` style once one was named.
|
|
87
120
|
*/
|
|
88
|
-
apply() {
|
|
121
|
+
apply(front = false) {
|
|
89
122
|
const { style, hidden } = untracked(this.state);
|
|
90
|
-
if (this.changes('style', style)) {
|
|
123
|
+
if (this.changes('style', style) || (front && this.styled)) {
|
|
91
124
|
this.styled = true;
|
|
92
|
-
this.source.setStyle(resolve(style ?? 'auto', untracked(this.scheme
|
|
125
|
+
this.source.setStyle(resolve(style ?? 'auto', untracked(() => this.scheme())));
|
|
93
126
|
}
|
|
94
127
|
if (this.changes('hidden', hidden))
|
|
95
128
|
this.source.setHidden(hidden ?? false);
|
|
96
129
|
}
|
|
130
|
+
/** The scheme of the app whose style is in force, or of the app that claimed last. */
|
|
131
|
+
scheme() {
|
|
132
|
+
const owner = this.styleOwner()?.owner ?? this.claims.owners().at(-1);
|
|
133
|
+
return owner?.scheme.current() ?? 'light';
|
|
134
|
+
}
|
|
135
|
+
/** The style in force and the app whose claim it is. */
|
|
136
|
+
styleOwner() {
|
|
137
|
+
const claim = this.claims.last((state) => state.style !== undefined);
|
|
138
|
+
return claim && { style: claim.value.style, owner: claim.owner };
|
|
139
|
+
}
|
|
97
140
|
changes(property, value) {
|
|
98
141
|
if (value === undefined)
|
|
99
142
|
return this.changed.delete(property);
|
|
100
143
|
this.changed.add(property);
|
|
101
144
|
return true;
|
|
102
145
|
}
|
|
103
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: NavigationBar, deps: [], target: i0.ɵɵFactoryTarget.Service });
|
|
104
|
-
static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.2.0", ngImport: i0, type: NavigationBar });
|
|
105
146
|
}
|
|
106
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: NavigationBar, decorators: [{
|
|
107
|
-
type: Service
|
|
108
|
-
}], ctorParameters: () => [] });
|
|
109
147
|
/** Dark buttons on the light scheme's light background, light ones on the dark one's. */
|
|
110
148
|
function resolve(style, scheme) {
|
|
111
149
|
if (style !== 'auto')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"navigation-bar.js","s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AE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC;IAC7E,CAAC;IAEO,OAAO,CAAC,QAAkC,EAAE,KAAc;QAChE,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC9D,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;uGA5EU,aAAa;wGAAb,aAAa;;2FAAb,aAAa;kBADzB,OAAO;;AAgFR,yFAAyF;AACzF,SAAS,OAAO,CAAC,KAAyB,EAAE,MAAc;IACxD,IAAI,KAAK,KAAK,MAAM;QAAE,OAAO,KAAK,CAAC;IACnC,OAAO,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;AAC9C,CAAC","sourcesContent":["/**\n * Android's navigation bar: the colour of its buttons, and whether it is there at all.\n *\n * The same stack of claims as `StatusBar`, so a video player can hide the bar while it is open and\n * the screen behind gets the bar back when it closes. `style: 'auto'` follows `ColorScheme`, a\n * theme the app sets included, and a fixed style holds through a scheme change.\n *\n * Driven through `expo-navigation-bar`'s native module, reached by name so nothing here imports the\n * package. Expo Go carries it; a development build has it once the app installs\n * `expo-navigation-bar`. Without it, and on iOS, which has no navigation bar, every claim is kept\n * but changes nothing.\n */\nimport {\n DestroyRef,\n InjectionToken,\n Service,\n computed,\n inject,\n signal,\n untracked,\n type Signal,\n} from '@angular/core';\nimport { ColorScheme, type Scheme } from './color-scheme.ts';\nimport { reactNative } from './react-native.ts';\n\n/**\n * The colour of the bar's buttons. `dark` is dark buttons, for a light screen behind them, and\n * `light` light ones, as `StatusBarStyle` names its text. `auto` is dark buttons in the light\n * colour scheme and light ones in the dark one, and follows `ColorScheme`.\n */\nexport type NavigationBarStyle = 'light' | 'dark' | 'auto';\n\n/** What a claim asks for. Anything absent is left as whatever the claim underneath said. */\nexport interface NavigationBarState {\n readonly style?: NavigationBarStyle;\n /** Hide the bar until a swipe from the edge of the screen shows it for a moment. */\n readonly hidden?: boolean;\n}\n\n/** Where the bar actually is. A fake stands in for the platform in tests. */\nexport interface NavigationBarSource {\n setStyle(style: Exclude<NavigationBarStyle, 'auto'>): void;\n setHidden(hidden: boolean): void;\n /**\n * react-native-screens shows or hides the bar each time a screen appears, from that screen's own\n * `navigationBarHidden`, once any screen has set one. So a hidden claim rides on every screen too.\n */\n readonly screensSetBar?: boolean;\n}\n\n/** `expo-navigation-bar`'s native module, as much of it as this uses. */\ninterface NativeNavigationBar {\n setStyle?(style: 'light' | 'dark'): Promise<void>;\n setHidden?(hidden: boolean): Promise<void>;\n}\n\nconst NONE: NavigationBarSource = { setStyle: () => {}, setHidden: () => {} };\n\nexport function navigationBarSource(): NavigationBarSource {\n if (reactNative()?.Platform?.OS !== 'android') return NONE;\n const modules = (globalThis as { expo?: { modules?: Record<string, unknown> } }).expo?.modules;\n const native = modules?.['ExpoNavigationBar'] as NativeNavigationBar | undefined;\n // Without the module a claim changes nothing, so it does not ride on the screens either, where\n // react-native-screens would hide the bar the next time one appears.\n if (!native) return NONE;\n return {\n setStyle: (style) => void native.setStyle?.(style)?.catch(() => {}),\n setHidden: (hidden) => void native.setHidden?.(hidden)?.catch(() => {}),\n screensSetBar: true,\n };\n}\n\n/**\n * A stack, not a setter, for the same reason as `StatusBar`'s: whatever hid the bar has to give it\n * back to whatever was there before. `push` returns the function that drops the claim.\n */\n@Service()\nexport class NavigationBar {\n /** Overridden in a test to watch the bar without one on screen. */\n static readonly SOURCE = new InjectionToken<NavigationBarSource>(\n 'angular-native.navigationBarSource',\n { factory: navigationBarSource },\n );\n\n private readonly source = inject(NavigationBar.SOURCE);\n private readonly scheme = inject(ColorScheme);\n private readonly stack = signal<readonly NavigationBarState[]>([{}]);\n\n /** What is actually showing: every claim in order, later ones winning per property. */\n readonly state: Signal<NavigationBarState> = computed(() =>\n this.stack().reduce((merged, entry) => ({ ...merged, ...entry }), {}),\n );\n\n /**\n * What a screen with no `navigationBarHidden` of its own carries, so the claim still holds when\n * it appears. Empty but on Android. The router passes it on.\n */\n readonly forScreens: Signal<{ readonly hidden?: boolean }> = computed(() =>\n this.source.screensSetBar ? { hidden: this.state().hidden } : {},\n );\n\n constructor() {\n // Straight from the source, as `StatusBar` does, so the buttons change in the same turn as the\n // scheme. Android puts the buttons back to the new scheme's own on a scheme change, so a fixed\n // style is sent again too. A bar no style claim names any more is `auto`, once one has named\n // a style.\n const stop = inject(ColorScheme.SOURCE).subscribe((scheme) => {\n const style = untracked(this.state).style ?? (this.styled ? 'auto' : undefined);\n if (style !== undefined) this.source.setStyle(resolve(style, scheme));\n });\n inject(DestroyRef).onDestroy(stop);\n }\n\n /** The base claim, for an app that sets the bar once at startup. */\n set(state: NavigationBarState): void {\n this.stack.update((entries) => [state, ...entries.slice(1)]);\n this.apply();\n }\n\n /** A claim on top of whatever is there. Call the returned function to drop it. */\n push(state: NavigationBarState): () => void {\n const entry = { ...state };\n this.stack.update((entries) => [...entries, entry]);\n this.apply();\n return () => {\n this.stack.update((entries) => entries.filter((one) => one !== entry));\n this.apply();\n };\n }\n\n /** The properties a claim has had the platform change, which no claim names any more. */\n private readonly changed = new Set<keyof NavigationBarState>();\n\n /** Whether a claim has ever set the style, after which an unclaimed bar follows the scheme. */\n private styled = false;\n\n /**\n * Push the merged state at the platform. A property the last claim to name it has dropped goes\n * back, once: the style to `auto`, which then keeps following the scheme, and the bar to shown.\n */\n private apply(): void {\n const { style, hidden } = untracked(this.state);\n if (this.changes('style', style)) {\n this.styled = true;\n this.source.setStyle(resolve(style ?? 'auto', untracked(this.scheme.current)));\n }\n if (this.changes('hidden', hidden)) this.source.setHidden(hidden ?? false);\n }\n\n private changes(property: keyof NavigationBarState, value: unknown): boolean {\n if (value === undefined) return this.changed.delete(property);\n this.changed.add(property);\n return true;\n }\n}\n\n/** Dark buttons on the light scheme's light background, light ones on the dark one's. */\nfunction resolve(style: NavigationBarStyle, scheme: Scheme): 'light' | 'dark' {\n if (style !== 'auto') return style;\n return scheme === 'dark' ? 'light' : 'dark';\n}\n"]}
|
|
1
|
+
{"version":3,"file":"navigation-bar.js","sourceRoot":"","sources":["../src/navigation-bar.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EACL,UAAU,EACV,cAAc,EACd,OAAO,EACP,QAAQ,EACR,MAAM,EACN,SAAS,GAEV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,WAAW,EAAe,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;;AAmCjF,MAAM,IAAI,GAAwB,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE,CAAC;AAE9E,MAAM,UAAU,mBAAmB;IACjC,IAAI,WAAW,EAAE,EAAE,QAAQ,EAAE,EAAE,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IAC3D,MAAM,OAAO,GAAI,UAA+D,CAAC,IAAI,EAAE,OAAO,CAAC;IAC/F,MAAM,MAAM,GAAG,OAAO,EAAE,CAAC,mBAAmB,CAAoC,CAAC;IACjF,+FAA+F;IAC/F,qEAAqE;IACrE,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IACzB,uEAAuE;IACvE,OAAO,cAAc,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;QACnC,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,MAAM,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC;QACnE,SAAS,EAAE,CA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;IAC9E,MAAM;QACZ,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,EAAE,EAAE,KAAK,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QACtE,OAAO,KAAK,EAAE,MAAM,CAAC,OAAO,EAAE,IAAI,OAAO,CAAC;IAC5C,CAAC;IAED,wDAAwD;IAChD,UAAU;QAChB,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC;QACrE,OAAO,KAAK,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,KAAM,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;IACpE,CAAC;IAEO,OAAO,CAAC,QAAkC,EAAE,KAAc;QAChE,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC9D,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED,yFAAyF;AACzF,SAAS,OAAO,CAAC,KAAyB,EAAE,MAAc;IACxD,IAAI,KAAK,KAAK,MAAM;QAAE,OAAO,KAAK,CAAC;IACnC,OAAO,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;AAC9C,CAAC","sourcesContent":["/**\n * Android's navigation bar: the colour of its buttons, and whether it is there at all.\n *\n * The same stack of claims as `StatusBar`, so a video player can hide the bar while it is open and\n * the screen behind gets the bar back when it closes. `style: 'auto'` follows `ColorScheme`, a\n * theme the app sets included, and a fixed style holds through a scheme change.\n *\n * Driven through `expo-navigation-bar`'s native module, reached by name so nothing here imports the\n * package. Expo Go carries it; a development build has it once the app installs\n * `expo-navigation-bar`. Without it, and on iOS, which has no navigation bar, every claim is kept\n * but changes nothing.\n */\nimport {\n DestroyRef,\n InjectionToken,\n Service,\n computed,\n inject,\n untracked,\n type Signal,\n} from '@angular/core';\nimport { ColorScheme, type Scheme } from './color-scheme.ts';\nimport { mergeClaims } from './merge-claims.ts';\nimport { reactNative } from './react-native.ts';\nimport { WindowClaims, onWindowFront, sharedBySource } from './window-claims.ts';\n\n/**\n * The colour of the bar's buttons. `dark` is dark buttons, for a light screen behind them, and\n * `light` light ones, as `StatusBarStyle` names its text. `auto` is dark buttons in the light\n * colour scheme and light ones in the dark one, and follows `ColorScheme`.\n */\nexport type NavigationBarStyle = 'light' | 'dark' | 'auto';\n\n/** What a claim asks for. Anything absent is left as whatever the claim underneath said. */\nexport interface NavigationBarState {\n readonly style?: NavigationBarStyle;\n /** Hide the bar until a swipe from the edge of the screen shows it for a moment. */\n readonly hidden?: boolean;\n}\n\n/** Where the bar actually is. A fake stands in for the platform in tests. */\nexport interface NavigationBarSource {\n setStyle(style: Exclude<NavigationBarStyle, 'auto'>): void;\n setHidden(hidden: boolean): void;\n /**\n * react-native-screens shows or hides the bar each time a screen appears, from that screen's own\n * `navigationBarHidden`, once any screen has set one. So a hidden claim rides on every screen too.\n */\n readonly screensSetBar?: boolean;\n /** Calls `listener` when a window comes to the front, to be given the whole bar again. */\n onWindowFront?(listener: () => void): () => void;\n}\n\n/** `expo-navigation-bar`'s native module, as much of it as this uses. */\ninterface NativeNavigationBar {\n setStyle?(style: 'light' | 'dark'): Promise<void>;\n setHidden?(hidden: boolean): Promise<void>;\n}\n\nconst NONE: NavigationBarSource = { setStyle: () => {}, setHidden: () => {} };\n\nexport function navigationBarSource(): NavigationBarSource {\n if (reactNative()?.Platform?.OS !== 'android') return NONE;\n const modules = (globalThis as { expo?: { modules?: Record<string, unknown> } }).expo?.modules;\n const native = modules?.['ExpoNavigationBar'] as NativeNavigationBar | undefined;\n // Without the module a claim changes nothing, so it does not ride on the screens either, where\n // react-native-screens would hide the bar the next time one appears.\n if (!native) return NONE;\n // One per module, so every app the runtime mounts claims the same bar.\n return sharedBySource(native, () => ({\n setStyle: (style) => void native.setStyle?.(style)?.catch(() => {}),\n setHidden: (hidden) => void native.setHidden?.(hidden)?.catch(() => {}),\n screensSetBar: true,\n onWindowFront,\n }));\n}\n\n/**\n * A stack, not a setter, for the same reason as `StatusBar`'s: whatever hid the bar has to give it\n * back to whatever was there before. `push` returns the function that drops the claim.\n */\n@Service()\nexport class NavigationBar {\n /** Overridden in a test to watch the bar without one on screen. */\n static readonly SOURCE = new InjectionToken<NavigationBarSource>(\n 'angular-native.navigationBarSource',\n { factory: navigationBarSource },\n );\n\n private readonly source = inject(NavigationBar.SOURCE);\n /** This app, among the apps claiming the bar: its scheme is what an `auto` style it claims follows. */\n private readonly owner: Owner = { scheme: inject(ColorScheme) };\n /** Every app's claims on this bar: the window is the runtime's, not an app's. */\n private readonly window = sharedBySource(this.source, () => new NavigationBarWindow(this.source));\n\n /** What is actually showing: every claim in order, later ones winning per property. */\n readonly state: Signal<NavigationBarState> = this.window.state;\n\n /**\n * What a screen with no `navigationBarHidden` of its own carries, so the claim still holds when\n * it appears. Empty but on Android. The router passes it on.\n */\n readonly forScreens: Signal<{ readonly hidden?: boolean }> = computed(() =>\n this.source.screensSetBar ? { hidden: this.state().hidden } : {},\n );\n\n constructor() {\n // Straight from the source, as `StatusBar` does, so the buttons change in the same turn as the\n // scheme.\n const stop = inject(ColorScheme.SOURCE).subscribe((scheme) =>\n this.window.schemeChanged(this.owner, scheme),\n );\n inject(DestroyRef).onDestroy(() => {\n stop();\n // An app that goes takes its claims with it, and leaves the bar to the apps still here.\n this.window.claims.drop(this.owner);\n this.window.apply();\n });\n }\n\n /** The base claim, for an app that sets the bar once at startup. */\n set(state: NavigationBarState): void {\n this.window.claims.setBase(this.owner, state);\n this.window.apply();\n }\n\n /** A claim on top of whatever is there. Call the returned function to drop it. */\n push(state: NavigationBarState): () => void {\n const drop = this.window.claims.push(this.owner, { ...state });\n this.window.apply();\n return () => {\n drop();\n this.window.apply();\n };\n }\n}\n\ninterface Owner {\n readonly scheme: ColorScheme;\n}\n\n/** The bar, as every app on one source claims it. */\nclass NavigationBarWindow {\n readonly claims = new WindowClaims<NavigationBarState, Owner>();\n readonly state: Signal<NavigationBarState> = computed(() =>\n mergeClaims(this.claims.all().map((claim) => claim.value)),\n );\n\n /** The properties a claim has had the platform change, which no claim names any more. */\n private readonly changed = new Set<keyof NavigationBarState>();\n\n /** Whether a claim has ever set the style, after which an unclaimed bar follows the scheme. */\n private styled = false;\n\n private readonly source: NavigationBarSource;\n\n constructor(source: NavigationBarSource) {\n this.source = source;\n // Lives as long as the source, which is the runtime's.\n source.onWindowFront?.(() => this.apply(true));\n }\n\n /**\n * Android puts the buttons back to the new scheme's own on a scheme change, so a fixed style is\n * sent again too. A bar no style claim names any more is `auto`, once one has named a style, and\n * follows the scheme the listener heard.\n */\n schemeChanged(owner: Owner, scheme: Scheme): void {\n const claimed = untracked(() => this.styleOwner());\n if (claimed && claimed.owner !== owner) return;\n const style = claimed?.style ?? (this.styled ? 'auto' : undefined);\n if (style !== undefined) this.source.setStyle(resolve(style, scheme));\n }\n\n /**\n * Push the merged state at the platform. A property the last claim to name it has dropped goes\n * back, once: the style to `auto`, which then keeps following the scheme, and the bar to shown.\n * A window come to the front is given what is claimed, and an `auto` style once one was named.\n */\n apply(front = false): void {\n const { style, hidden } = untracked(this.state);\n if (this.changes('style', style) || (front && this.styled)) {\n this.styled = true;\n this.source.setStyle(\n resolve(\n style ?? 'auto',\n untracked(() => this.scheme()),\n ),\n );\n }\n if (this.changes('hidden', hidden)) this.source.setHidden(hidden ?? false);\n }\n\n /** The scheme of the app whose style is in force, or of the app that claimed last. */\n private scheme(): Scheme {\n const owner = this.styleOwner()?.owner ?? this.claims.owners().at(-1);\n return owner?.scheme.current() ?? 'light';\n }\n\n /** The style in force and the app whose claim it is. */\n private styleOwner(): { style: NavigationBarStyle; owner: Owner } | undefined {\n const claim = this.claims.last((state) => state.style !== undefined);\n return claim && { style: claim.value.style!, owner: claim.owner };\n }\n\n private changes(property: keyof NavigationBarState, value: unknown): boolean {\n if (value === undefined) return this.changed.delete(property);\n this.changed.add(property);\n return true;\n }\n}\n\n/** Dark buttons on the light scheme's light background, light ones on the dark one's. */\nfunction resolve(style: NavigationBarStyle, scheme: Scheme): 'light' | 'dark' {\n if (style !== 'auto') return style;\n return scheme === 'dark' ? 'light' : 'dark';\n}\n"]}
|
package/dist/status-bar.d.ts
CHANGED
|
@@ -54,7 +54,10 @@ export interface StatusBarSource {
|
|
|
54
54
|
* own props or, with none, to light text and shown. So a claim has to ride on every screen too.
|
|
55
55
|
*/
|
|
56
56
|
readonly screensSetBar?: boolean;
|
|
57
|
+
/** Calls `listener` when a window comes to the front, to be given the whole bar again. */
|
|
58
|
+
onWindowFront?(listener: () => void): () => void;
|
|
57
59
|
}
|
|
60
|
+
/** One per React Native, so every app the runtime mounts claims the same bar. */
|
|
58
61
|
export declare function statusBarSource(): StatusBarSource;
|
|
59
62
|
/**
|
|
60
63
|
* A stack, not a setter.
|
|
@@ -67,8 +70,10 @@ export declare class StatusBar {
|
|
|
67
70
|
/** Overridden in a test to watch the bar without one on screen. */
|
|
68
71
|
static readonly SOURCE: InjectionToken<StatusBarSource>;
|
|
69
72
|
private readonly source;
|
|
70
|
-
|
|
71
|
-
private readonly
|
|
73
|
+
/** This app, among the apps claiming the bar: its scheme is what an `auto` style it claims follows. */
|
|
74
|
+
private readonly owner;
|
|
75
|
+
/** Every app's claims on this bar: the window is the runtime's, not an app's. */
|
|
76
|
+
private readonly window;
|
|
72
77
|
/** What is actually showing: every claim in order, later ones winning per property. */
|
|
73
78
|
readonly state: Signal<StatusBarState>;
|
|
74
79
|
/**
|
|
@@ -90,19 +95,6 @@ export declare class StatusBar {
|
|
|
90
95
|
set(state: StatusBarState): void;
|
|
91
96
|
/** A claim on top of whatever is there. Call the returned function to drop it. */
|
|
92
97
|
push(state: StatusBarState): () => void;
|
|
93
|
-
/** The properties a claim has had the platform change, which no claim names any more. */
|
|
94
|
-
private readonly changed;
|
|
95
|
-
/**
|
|
96
|
-
* Push the merged state at the platform.
|
|
97
|
-
*
|
|
98
|
-
* Written whole rather than diffed: the platform's own setters are the cheap part. A property
|
|
99
|
-
* the last claim to name it has dropped goes back to the platform's own, once. Not the
|
|
100
|
-
* background color, whose own the theme decides. Read untracked, so an effect that sets the bar
|
|
101
|
-
* does not also subscribe to it and run again on every later claim.
|
|
102
|
-
*/
|
|
103
|
-
private apply;
|
|
104
|
-
/** Whether to tell the platform: a claim names `property`, or the last one to has dropped. */
|
|
105
|
-
private changes;
|
|
106
98
|
static ɵfac: i0.ɵɵFactoryDeclaration<StatusBar, never>;
|
|
107
99
|
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
108
100
|
}
|
package/dist/status-bar.js
CHANGED
|
@@ -12,21 +12,27 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { DestroyRef, InjectionToken, Service, computed, inject, signal, untracked, } from '@angular/core';
|
|
14
14
|
import { ColorScheme } from "./color-scheme.js";
|
|
15
|
+
import { mergeClaims } from "./merge-claims.js";
|
|
15
16
|
import { reactNative } from "./react-native.js";
|
|
17
|
+
import { WindowClaims, onWindowFront, sharedBySource } from "./window-claims.js";
|
|
16
18
|
import * as i0 from "@angular/core";
|
|
17
19
|
/** RN spells the styles for its own platforms; `light` means light *content*, as CSS would. */
|
|
18
20
|
const BAR_STYLES = { default: 'default', light: 'light-content', dark: 'dark-content' };
|
|
21
|
+
const NONE = {
|
|
22
|
+
setStyle: () => { },
|
|
23
|
+
setHidden: () => { },
|
|
24
|
+
setBackgroundColor: () => { },
|
|
25
|
+
setTranslucent: () => { },
|
|
26
|
+
height: undefined,
|
|
27
|
+
};
|
|
28
|
+
/** One per React Native, so every app the runtime mounts claims the same bar. */
|
|
19
29
|
export function statusBarSource() {
|
|
20
30
|
const native = reactNative();
|
|
21
|
-
if (!native)
|
|
22
|
-
return
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
setTranslucent: () => { },
|
|
27
|
-
height: undefined,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
31
|
+
if (!native)
|
|
32
|
+
return NONE;
|
|
33
|
+
return sharedBySource(native, () => nativeSource(native));
|
|
34
|
+
}
|
|
35
|
+
function nativeSource(native) {
|
|
30
36
|
const { StatusBar } = native;
|
|
31
37
|
const android = native.Platform?.OS === 'android';
|
|
32
38
|
// Android 16 draws an app targeting SDK 35 or later edge-to-edge whatever its theme says. Before
|
|
@@ -57,6 +63,7 @@ export function statusBarSource() {
|
|
|
57
63
|
return StatusBar.currentHeight;
|
|
58
64
|
},
|
|
59
65
|
screensSetBar: android,
|
|
66
|
+
onWindowFront,
|
|
60
67
|
};
|
|
61
68
|
}
|
|
62
69
|
/**
|
|
@@ -85,12 +92,12 @@ export class StatusBar {
|
|
|
85
92
|
factory: statusBarSource,
|
|
86
93
|
});
|
|
87
94
|
source = inject(StatusBar.SOURCE);
|
|
88
|
-
scheme
|
|
89
|
-
|
|
90
|
-
|
|
95
|
+
/** This app, among the apps claiming the bar: its scheme is what an `auto` style it claims follows. */
|
|
96
|
+
owner = { scheme: inject(ColorScheme) };
|
|
97
|
+
/** Every app's claims on this bar: the window is the runtime's, not an app's. */
|
|
98
|
+
window = sharedBySource(this.source, () => new StatusBarWindow(this.source));
|
|
91
99
|
/** What is actually showing: every claim in order, later ones winning per property. */
|
|
92
|
-
state =
|
|
93
|
-
...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
|
|
100
|
+
state = this.window.state;
|
|
94
101
|
/**
|
|
95
102
|
* How tall it is, in points. Android reports it; iOS does not, and on iOS the number a layout
|
|
96
103
|
* wants is the safe-area top inset, which `SafeArea` has.
|
|
@@ -105,59 +112,92 @@ export class StatusBar {
|
|
|
105
112
|
if (!this.source.screensSetBar)
|
|
106
113
|
return {};
|
|
107
114
|
const { style, hidden } = this.state();
|
|
108
|
-
return { style: style &&
|
|
115
|
+
return { style: style && this.window.resolve(style), hidden };
|
|
109
116
|
}, /* @ts-ignore */
|
|
110
117
|
...(ngDevMode ? [{ debugName: "forScreens" }] : /* istanbul ignore next */ []));
|
|
111
118
|
constructor() {
|
|
112
119
|
// Straight from the source rather than through an effect, so an `auto` bar changes in the same
|
|
113
120
|
// turn as the scheme. The scheme is the listener's own: `ColorScheme.current` may not have
|
|
114
121
|
// heard yet.
|
|
115
|
-
const stop = inject(ColorScheme.SOURCE).subscribe((scheme) =>
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
122
|
+
const stop = inject(ColorScheme.SOURCE).subscribe((scheme) => this.window.schemeChanged(this.owner, scheme));
|
|
123
|
+
inject(DestroyRef).onDestroy(() => {
|
|
124
|
+
stop();
|
|
125
|
+
// An app that goes takes its claims with it, and leaves the bar to the apps still here.
|
|
126
|
+
this.window.claims.drop(this.owner);
|
|
127
|
+
this.window.apply();
|
|
119
128
|
});
|
|
120
|
-
inject(DestroyRef).onDestroy(stop);
|
|
121
129
|
}
|
|
122
130
|
/** The base claim, for an app that sets the bar once at startup. */
|
|
123
131
|
set(state) {
|
|
124
|
-
this.
|
|
125
|
-
this.apply();
|
|
132
|
+
this.window.claims.setBase(this.owner, state);
|
|
133
|
+
this.window.apply();
|
|
126
134
|
}
|
|
127
135
|
/** A claim on top of whatever is there. Call the returned function to drop it. */
|
|
128
136
|
push(state) {
|
|
129
|
-
const
|
|
130
|
-
this.
|
|
131
|
-
this.apply();
|
|
137
|
+
const drop = this.window.claims.push(this.owner, { ...state });
|
|
138
|
+
this.window.apply();
|
|
132
139
|
return () => {
|
|
133
|
-
|
|
134
|
-
this.apply();
|
|
140
|
+
drop();
|
|
141
|
+
this.window.apply();
|
|
135
142
|
};
|
|
136
143
|
}
|
|
144
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: StatusBar, deps: [], target: i0.ɵɵFactoryTarget.Service });
|
|
145
|
+
static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.2.0", ngImport: i0, type: StatusBar });
|
|
146
|
+
}
|
|
147
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: StatusBar, decorators: [{
|
|
148
|
+
type: Service
|
|
149
|
+
}], ctorParameters: () => [] });
|
|
150
|
+
/** The bar, as every app on one source claims it. */
|
|
151
|
+
class StatusBarWindow {
|
|
152
|
+
claims = new WindowClaims();
|
|
153
|
+
state = computed(() => mergeClaims(this.claims.all().map((claim) => claim.value)), /* @ts-ignore */
|
|
154
|
+
...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
|
|
137
155
|
/** The properties a claim has had the platform change, which no claim names any more. */
|
|
138
156
|
changed = new Set();
|
|
157
|
+
source;
|
|
158
|
+
constructor(source) {
|
|
159
|
+
this.source = source;
|
|
160
|
+
// Lives as long as the source, which is the runtime's.
|
|
161
|
+
source.onWindowFront?.(() => this.apply(true));
|
|
162
|
+
}
|
|
163
|
+
/** `style` for the platform, `auto` by the scheme of the app whose claim the style is. */
|
|
164
|
+
resolve(style, scheme) {
|
|
165
|
+
return resolve(style, scheme ?? this.styleOwner()?.scheme.current() ?? 'light');
|
|
166
|
+
}
|
|
167
|
+
schemeChanged(owner, scheme) {
|
|
168
|
+
const { style, animated } = untracked(this.state);
|
|
169
|
+
if (style !== 'auto' || untracked(() => this.styleOwner()) !== owner)
|
|
170
|
+
return;
|
|
171
|
+
this.source.setStyle(this.resolve(style, scheme), animated);
|
|
172
|
+
}
|
|
139
173
|
/**
|
|
140
174
|
* Push the merged state at the platform.
|
|
141
175
|
*
|
|
142
176
|
* Written whole rather than diffed: the platform's own setters are the cheap part. A property
|
|
143
177
|
* the last claim to name it has dropped goes back to the platform's own, once. Not the
|
|
144
178
|
* background color, whose own the theme decides. Read untracked, so an effect that sets the bar
|
|
145
|
-
* does not also subscribe to it and run again on every later claim.
|
|
179
|
+
* does not also subscribe to it and run again on every later claim. A window come to the front
|
|
180
|
+
* is given what is claimed, with nothing animated and nothing put back.
|
|
146
181
|
*/
|
|
147
|
-
apply() {
|
|
182
|
+
apply(front = false) {
|
|
148
183
|
const { style, hidden, animated, backgroundColor, translucent } = untracked(this.state);
|
|
184
|
+
const animate = front ? undefined : animated;
|
|
149
185
|
if (this.changes('style', style)) {
|
|
150
|
-
this.source.setStyle(resolve(style ?? 'default'
|
|
186
|
+
this.source.setStyle(untracked(() => this.resolve(style ?? 'default')), animate);
|
|
151
187
|
}
|
|
152
188
|
if (this.changes('hidden', hidden)) {
|
|
153
|
-
this.source.setHidden(hidden ?? false,
|
|
189
|
+
this.source.setHidden(hidden ?? false, animate ? 'fade' : undefined);
|
|
154
190
|
}
|
|
155
191
|
if (backgroundColor !== undefined)
|
|
156
|
-
this.source.setBackgroundColor(backgroundColor,
|
|
192
|
+
this.source.setBackgroundColor(backgroundColor, animate);
|
|
157
193
|
if (this.changes('translucent', translucent)) {
|
|
158
194
|
this.source.setTranslucent(translucent ?? false);
|
|
159
195
|
}
|
|
160
196
|
}
|
|
197
|
+
/** The app whose claim the style in force comes from. */
|
|
198
|
+
styleOwner() {
|
|
199
|
+
return this.claims.last((state) => state.style !== undefined)?.owner;
|
|
200
|
+
}
|
|
161
201
|
/** Whether to tell the platform: a claim names `property`, or the last one to has dropped. */
|
|
162
202
|
changes(property, value) {
|
|
163
203
|
if (value === undefined)
|
|
@@ -165,12 +205,7 @@ export class StatusBar {
|
|
|
165
205
|
this.changed.add(property);
|
|
166
206
|
return true;
|
|
167
207
|
}
|
|
168
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: StatusBar, deps: [], target: i0.ɵɵFactoryTarget.Service });
|
|
169
|
-
static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.2.0", ngImport: i0, type: StatusBar });
|
|
170
208
|
}
|
|
171
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: StatusBar, decorators: [{
|
|
172
|
-
type: Service
|
|
173
|
-
}], ctorParameters: () => [] });
|
|
174
209
|
/** Dark text on the light scheme's light background, light text on the dark one's. */
|
|
175
210
|
function resolve(style, scheme) {
|
|
176
211
|
if (style !== 'auto')
|
package/dist/status-bar.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"status-bar.js","sourceRoot":"","sources":["../src/status-bar.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EACL,UAAU,EACV,cAAc,EACd,OAAO,EACP,QAAQ,EACR,MAAM,EACN,MAAM,EACN,SAAS,GAEV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,WAAW,EAAe,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;;AAiDhD,+FAA+F;AAC/F,MAAM,UAAU,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,cAAc,EAAW,CAAC;AAEjG,MAAM,UAAU,eAAe;IAC7B,MAAM,MAAM,GAAG,WAAW,EAAE,CAAC;IAC7B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO;YACL,QAAQ,EAAE,GAAG,EAAE,GAAE,CAAC;YAClB,SAAS,EAAE,GAAG,EAAE,GAAE,CAAC;YACnB,kBAAkB,EAAE,GAAG,EAAE,GAAE,CAAC;YAC5B,cAAc,EAAE,GAAG,EAAE,GAAE,CAAC;YACxB,MAAM,EAAE,SAAS;SAClB,CAAC;IACJ,CAAC;IAED,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;IAC7B,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,EAAE,EAAE,KAAK,SAAS,CAAC;IAClD,iGAAiG;IACjG,2FAA2F;IAC3F,qFAAqF;IACrF,MAAM,IAAI,GAAG,MAAM,CAAC,mB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GR,sFAAsF;AACtF,SAAS,OAAO,CAAC,KAAqB,EAAE,MAAc;IACpD,IAAI,KAAK,KAAK,MAAM;QAAE,OAAO,KAAK,CAAC;IACnC,OAAO,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;AAC9C,CAAC","sourcesContent":["/**\n * The status bar: what colour its text is, whether it is there at all, and how tall it is.\n *\n * React Native only offers this as a component. `<StatusBar />` applies its style by *rendering*,\n * and does it through a stack of entries so that a screen pushed on top can change the bar and\n * the screen underneath gets its own back when that one leaves. None of the rendering survives\n * without React - but the statics underneath do, and the stack is exactly what a navigation-driven\n * app needs, so it is the part worth keeping.\n *\n * `expo-status-bar` is the same statics with a React component around them, so nothing here needs\n * that package installed.\n */\nimport {\n DestroyRef,\n InjectionToken,\n Service,\n computed,\n inject,\n signal,\n untracked,\n type Signal,\n} from '@angular/core';\nimport { ColorScheme, type Scheme } from './color-scheme.ts';\nimport { reactNative } from './react-native.ts';\n\n/**\n * Dark text for a light bar, light text for a dark one. `default` is whatever the OS picks, which on\n * Android is light text whatever the scheme. `auto` is dark text in the light color scheme and\n * light text in the dark one, and follows `ColorScheme`, an in-app theme switch included.\n */\nexport type StatusBarStyle = 'default' | 'light' | 'dark' | 'auto';\n\n/** A style the platform takes: `auto` is resolved against the color scheme before it gets there. */\nexport type PlatformStatusBarStyle = Exclude<StatusBarStyle, 'auto'>;\n\n/** What a claim asks for. Anything absent is left as whatever the claim underneath said. */\nexport interface StatusBarState {\n readonly style?: StatusBarStyle;\n readonly hidden?: boolean;\n readonly animated?: boolean;\n /**\n * Android only: the bar's own background. iOS has no such thing.\n *\n * @deprecated Has no effect. Android apps on Expo SDK 57 draw edge-to-edge, where the status bar\n * has no background of its own and React Native ignores the change. Draw a view behind the bar\n * instead. Never sent on iOS.\n */\n readonly backgroundColor?: string;\n /**\n * Android only: whether content draws underneath the bar.\n *\n * @deprecated Has no effect. Android apps on Expo SDK 57 draw edge-to-edge, so content is always\n * underneath the bar and React Native ignores the change. Never sent on iOS.\n */\n readonly translucent?: boolean;\n}\n\n/** Where the bar actually is. A fake stands in for the platform in tests. */\nexport interface StatusBarSource {\n setStyle(style: PlatformStatusBarStyle, animated?: boolean): void;\n setHidden(hidden: boolean, animation?: 'none' | 'fade' | 'slide'): void;\n setBackgroundColor(color: string, animated?: boolean): void;\n setTranslucent(translucent: boolean): void;\n /** Android reports one; iOS does not, where the safe-area inset is the number that matters. */\n readonly height: number | undefined;\n /**\n * Android: react-native-screens sets the bar again each time a screen appears, from that screen's\n * own props or, with none, to light text and shown. So a claim has to ride on every screen too.\n */\n readonly screensSetBar?: boolean;\n}\n\n/** RN spells the styles for its own platforms; `light` means light *content*, as CSS would. */\nconst BAR_STYLES = { default: 'default', light: 'light-content', dark: 'dark-content' } as const;\n\nexport function statusBarSource(): StatusBarSource {\n const native = reactNative();\n if (!native) {\n return {\n setStyle: () => {},\n setHidden: () => {},\n setBackgroundColor: () => {},\n setTranslucent: () => {},\n height: undefined,\n };\n }\n\n const { StatusBar } = native;\n const android = native.Platform?.OS === 'android';\n // Android 16 draws an app targeting SDK 35 or later edge-to-edge whatever its theme says. Before\n // it, a theme can opt out, and React Native's own answer is the flag its status bar module\n // checks. That answer is not enough on its own: Expo Go on Android 16 reports false.\n const info = native.TurboModuleRegistry?.get('DeviceInfo') as\n { getConstants?(): { isEdgeToEdge?: boolean } } | null | undefined;\n const edgeToEdge =\n android &&\n (Number(native.Platform.Version) >= 36 || info?.getConstants?.().isEdgeToEdge === true);\n const warned = new Set<string>();\n return {\n setStyle: (style, animated) => StatusBar.setBarStyle(BAR_STYLES[style], animated),\n setHidden: (hidden, animation) => StatusBar.setHidden(hidden, animation),\n setBackgroundColor: (color, animated) => {\n if (!android) return;\n if (edgeToEdge) warnNoEffect('backgroundColor', warned);\n StatusBar.setBackgroundColor(color, animated);\n },\n setTranslucent: (translucent) => {\n if (!android) return;\n if (edgeToEdge) warnNoEffect('translucent', warned);\n StatusBar.setTranslucent(translucent);\n },\n get height() {\n return StatusBar.currentHeight;\n },\n screensSetBar: android,\n };\n}\n\ndeclare const ngDevMode: unknown;\n\n/**\n * Says, once per option and in development only, that Android ignores it. React Native's own\n * module returns early with \"current activity is edge-to-edge\", which only shows in logcat.\n */\nfunction warnNoEffect(option: 'backgroundColor' | 'translucent', warned: Set<string>): void {\n if (typeof ngDevMode !== 'undefined' && !ngDevMode) return;\n if (warned.has(option)) return;\n warned.add(option);\n console.warn(\n `[angular-native] StatusBar ${option} has no effect: Android draws the app edge-to-edge, ` +\n 'so content is always under the status bar. See https://ng-native.com/guide/android-edge-to-edge',\n );\n}\n\n/**\n * A stack, not a setter.\n *\n * A modal that makes the bar light has to put back whatever the screen behind it asked for when\n * it is dismissed, and nothing else in an app remembers what that was. `push` returns the\n * function that drops the claim, so a screen can hand it straight to `DestroyRef.onDestroy`.\n */\n@Service()\nexport class StatusBar {\n /** Overridden in a test to watch the bar without one on screen. */\n static readonly SOURCE = new InjectionToken<StatusBarSource>('angular-native.statusBarSource', {\n factory: statusBarSource,\n });\n\n private readonly source = inject(StatusBar.SOURCE);\n private readonly scheme = inject(ColorScheme);\n private readonly stack = signal<readonly StatusBarState[]>([{}]);\n\n /** What is actually showing: every claim in order, later ones winning per property. */\n readonly state: Signal<StatusBarState> = computed(() =>\n this.stack().reduce((merged, entry) => ({ ...merged, ...entry }), {}),\n );\n\n /**\n * How tall it is, in points. Android reports it; iOS does not, and on iOS the number a layout\n * wants is the safe-area top inset, which `SafeArea` has.\n */\n readonly height: Signal<number> = signal(this.source.height ?? 0).asReadonly();\n\n /**\n * What a screen with no style or visibility of its own carries, so the claim is still what shows\n * when it appears. Empty but on Android, where a screen appearing sets the bar from its own props\n * and falls back to light text otherwise. The router passes it on.\n */\n readonly forScreens: Signal<{\n readonly style?: PlatformStatusBarStyle;\n readonly hidden?: boolean;\n }> = computed(() => {\n if (!this.source.screensSetBar) return {};\n const { style, hidden } = this.state();\n return { style: style && resolve(style, this.scheme.current()), hidden };\n });\n\n constructor() {\n // Straight from the source rather than through an effect, so an `auto` bar changes in the same\n // turn as the scheme. The scheme is the listener's own: `ColorScheme.current` may not have\n // heard yet.\n const stop = inject(ColorScheme.SOURCE).subscribe((scheme) => {\n const { style, animated } = untracked(this.state);\n if (style === 'auto') this.source.setStyle(resolve(style, scheme), animated);\n });\n inject(DestroyRef).onDestroy(stop);\n }\n\n /** The base claim, for an app that sets the bar once at startup. */\n set(state: StatusBarState): void {\n this.stack.update((entries) => [state, ...entries.slice(1)]);\n this.apply();\n }\n\n /** A claim on top of whatever is there. Call the returned function to drop it. */\n push(state: StatusBarState): () => void {\n const entry = { ...state };\n this.stack.update((entries) => [...entries, entry]);\n this.apply();\n\n return () => {\n this.stack.update((entries) => entries.filter((one) => one !== entry));\n this.apply();\n };\n }\n\n /** The properties a claim has had the platform change, which no claim names any more. */\n private readonly changed = new Set<'style' | 'hidden' | 'translucent'>();\n\n /**\n * Push the merged state at the platform.\n *\n * Written whole rather than diffed: the platform's own setters are the cheap part. A property\n * the last claim to name it has dropped goes back to the platform's own, once. Not the\n * background color, whose own the theme decides. Read untracked, so an effect that sets the bar\n * does not also subscribe to it and run again on every later claim.\n */\n private apply(): void {\n const { style, hidden, animated, backgroundColor, translucent } = untracked(this.state);\n if (this.changes('style', style)) {\n this.source.setStyle(resolve(style ?? 'default', untracked(this.scheme.current)), animated);\n }\n if (this.changes('hidden', hidden)) {\n this.source.setHidden(hidden ?? false, animated ? 'fade' : undefined);\n }\n if (backgroundColor !== undefined) this.source.setBackgroundColor(backgroundColor, animated);\n if (this.changes('translucent', translucent)) {\n this.source.setTranslucent(translucent ?? false);\n }\n }\n\n /** Whether to tell the platform: a claim names `property`, or the last one to has dropped. */\n private changes(property: 'style' | 'hidden' | 'translucent', value: unknown): boolean {\n if (value === undefined) return this.changed.delete(property);\n this.changed.add(property);\n return true;\n }\n}\n\n/** Dark text on the light scheme's light background, light text on the dark one's. */\nfunction resolve(style: StatusBarStyle, scheme: Scheme): PlatformStatusBarStyle {\n if (style !== 'auto') return style;\n return scheme === 'dark' ? 'light' : 'dark';\n}\n"]}
|
|
1
|
+
{"version":3,"file":"status-bar.js","sourceRoot":"","sources":["../src/status-bar.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EACL,UAAU,EACV,cAAc,EACd,OAAO,EACP,QAAQ,EACR,MAAM,EACN,MAAM,EACN,SAAS,GAEV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,WAAW,EAAe,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;;AAmDjF,+FAA+F;AAC/F,MAAM,UAAU,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,cAAc,EAAW,CAAC;AAEjG,MAAM,IAAI,GAAoB;IAC5B,QAAQ,EAAE,GAAG,EAAE,GAAE,CAAC;IAClB,SAAS,EAAE,GAAG,EAAE,GAAE,CAAC;IACnB,kBAAkB,EAAE,GAAG,EAAE,GAAE,CAAC;IAC5B,cAAc,EAAE,GAAG,EAAE,GAAE,CAAC;IACxB,MAAM,EAAE,SAAS;CAClB,CAAC;AAEF,iFAAiF;AACjF,MAAM,UAAU,eAAe;IAC7B,MAAM,MAAM,GAAG,WAAW,EAAE,CAAC;IAC7B,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IACzB,OAAO,cAAc,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED,SAAS,YAAY,CAAC,MAAmD;IACvE,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;IAC7B,MAAM,OAAO,GAAG,MAAM,CAAC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S,OAAO,CAAC,KAAqB,EAAE,MAAc;IACpD,IAAI,KAAK,KAAK,MAAM;QAAE,OAAO,KAAK,CAAC;IACnC,OAAO,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;AAC9C,CAAC","sourcesContent":["/**\n * The status bar: what colour its text is, whether it is there at all, and how tall it is.\n *\n * React Native only offers this as a component. `<StatusBar />` applies its style by *rendering*,\n * and does it through a stack of entries so that a screen pushed on top can change the bar and\n * the screen underneath gets its own back when that one leaves. None of the rendering survives\n * without React - but the statics underneath do, and the stack is exactly what a navigation-driven\n * app needs, so it is the part worth keeping.\n *\n * `expo-status-bar` is the same statics with a React component around them, so nothing here needs\n * that package installed.\n */\nimport {\n DestroyRef,\n InjectionToken,\n Service,\n computed,\n inject,\n signal,\n untracked,\n type Signal,\n} from '@angular/core';\nimport { ColorScheme, type Scheme } from './color-scheme.ts';\nimport { mergeClaims } from './merge-claims.ts';\nimport { reactNative } from './react-native.ts';\nimport { WindowClaims, onWindowFront, sharedBySource } from './window-claims.ts';\n\n/**\n * Dark text for a light bar, light text for a dark one. `default` is whatever the OS picks, which on\n * Android is light text whatever the scheme. `auto` is dark text in the light color scheme and\n * light text in the dark one, and follows `ColorScheme`, an in-app theme switch included.\n */\nexport type StatusBarStyle = 'default' | 'light' | 'dark' | 'auto';\n\n/** A style the platform takes: `auto` is resolved against the color scheme before it gets there. */\nexport type PlatformStatusBarStyle = Exclude<StatusBarStyle, 'auto'>;\n\n/** What a claim asks for. Anything absent is left as whatever the claim underneath said. */\nexport interface StatusBarState {\n readonly style?: StatusBarStyle;\n readonly hidden?: boolean;\n readonly animated?: boolean;\n /**\n * Android only: the bar's own background. iOS has no such thing.\n *\n * @deprecated Has no effect. Android apps on Expo SDK 57 draw edge-to-edge, where the status bar\n * has no background of its own and React Native ignores the change. Draw a view behind the bar\n * instead. Never sent on iOS.\n */\n readonly backgroundColor?: string;\n /**\n * Android only: whether content draws underneath the bar.\n *\n * @deprecated Has no effect. Android apps on Expo SDK 57 draw edge-to-edge, so content is always\n * underneath the bar and React Native ignores the change. Never sent on iOS.\n */\n readonly translucent?: boolean;\n}\n\n/** Where the bar actually is. A fake stands in for the platform in tests. */\nexport interface StatusBarSource {\n setStyle(style: PlatformStatusBarStyle, animated?: boolean): void;\n setHidden(hidden: boolean, animation?: 'none' | 'fade' | 'slide'): void;\n setBackgroundColor(color: string, animated?: boolean): void;\n setTranslucent(translucent: boolean): void;\n /** Android reports one; iOS does not, where the safe-area inset is the number that matters. */\n readonly height: number | undefined;\n /**\n * Android: react-native-screens sets the bar again each time a screen appears, from that screen's\n * own props or, with none, to light text and shown. So a claim has to ride on every screen too.\n */\n readonly screensSetBar?: boolean;\n /** Calls `listener` when a window comes to the front, to be given the whole bar again. */\n onWindowFront?(listener: () => void): () => void;\n}\n\n/** RN spells the styles for its own platforms; `light` means light *content*, as CSS would. */\nconst BAR_STYLES = { default: 'default', light: 'light-content', dark: 'dark-content' } as const;\n\nconst NONE: StatusBarSource = {\n setStyle: () => {},\n setHidden: () => {},\n setBackgroundColor: () => {},\n setTranslucent: () => {},\n height: undefined,\n};\n\n/** One per React Native, so every app the runtime mounts claims the same bar. */\nexport function statusBarSource(): StatusBarSource {\n const native = reactNative();\n if (!native) return NONE;\n return sharedBySource(native, () => nativeSource(native));\n}\n\nfunction nativeSource(native: NonNullable<ReturnType<typeof reactNative>>): StatusBarSource {\n const { StatusBar } = native;\n const android = native.Platform?.OS === 'android';\n // Android 16 draws an app targeting SDK 35 or later edge-to-edge whatever its theme says. Before\n // it, a theme can opt out, and React Native's own answer is the flag its status bar module\n // checks. That answer is not enough on its own: Expo Go on Android 16 reports false.\n const info = native.TurboModuleRegistry?.get('DeviceInfo') as\n { getConstants?(): { isEdgeToEdge?: boolean } } | null | undefined;\n const edgeToEdge =\n android &&\n (Number(native.Platform.Version) >= 36 || info?.getConstants?.().isEdgeToEdge === true);\n const warned = new Set<string>();\n return {\n setStyle: (style, animated) => StatusBar.setBarStyle(BAR_STYLES[style], animated),\n setHidden: (hidden, animation) => StatusBar.setHidden(hidden, animation),\n setBackgroundColor: (color, animated) => {\n if (!android) return;\n if (edgeToEdge) warnNoEffect('backgroundColor', warned);\n StatusBar.setBackgroundColor(color, animated);\n },\n setTranslucent: (translucent) => {\n if (!android) return;\n if (edgeToEdge) warnNoEffect('translucent', warned);\n StatusBar.setTranslucent(translucent);\n },\n get height() {\n return StatusBar.currentHeight;\n },\n screensSetBar: android,\n onWindowFront,\n };\n}\n\ndeclare const ngDevMode: unknown;\n\n/**\n * Says, once per option and in development only, that Android ignores it. React Native's own\n * module returns early with \"current activity is edge-to-edge\", which only shows in logcat.\n */\nfunction warnNoEffect(option: 'backgroundColor' | 'translucent', warned: Set<string>): void {\n if (typeof ngDevMode !== 'undefined' && !ngDevMode) return;\n if (warned.has(option)) return;\n warned.add(option);\n console.warn(\n `[angular-native] StatusBar ${option} has no effect: Android draws the app edge-to-edge, ` +\n 'so content is always under the status bar. See https://ng-native.com/guide/android-edge-to-edge',\n );\n}\n\n/**\n * A stack, not a setter.\n *\n * A modal that makes the bar light has to put back whatever the screen behind it asked for when\n * it is dismissed, and nothing else in an app remembers what that was. `push` returns the\n * function that drops the claim, so a screen can hand it straight to `DestroyRef.onDestroy`.\n */\n@Service()\nexport class StatusBar {\n /** Overridden in a test to watch the bar without one on screen. */\n static readonly SOURCE = new InjectionToken<StatusBarSource>('angular-native.statusBarSource', {\n factory: statusBarSource,\n });\n\n private readonly source = inject(StatusBar.SOURCE);\n /** This app, among the apps claiming the bar: its scheme is what an `auto` style it claims follows. */\n private readonly owner: Owner = { scheme: inject(ColorScheme) };\n /** Every app's claims on this bar: the window is the runtime's, not an app's. */\n private readonly window = sharedBySource(this.source, () => new StatusBarWindow(this.source));\n\n /** What is actually showing: every claim in order, later ones winning per property. */\n readonly state: Signal<StatusBarState> = this.window.state;\n\n /**\n * How tall it is, in points. Android reports it; iOS does not, and on iOS the number a layout\n * wants is the safe-area top inset, which `SafeArea` has.\n */\n readonly height: Signal<number> = signal(this.source.height ?? 0).asReadonly();\n\n /**\n * What a screen with no style or visibility of its own carries, so the claim is still what shows\n * when it appears. Empty but on Android, where a screen appearing sets the bar from its own props\n * and falls back to light text otherwise. The router passes it on.\n */\n readonly forScreens: Signal<{\n readonly style?: PlatformStatusBarStyle;\n readonly hidden?: boolean;\n }> = computed(() => {\n if (!this.source.screensSetBar) return {};\n const { style, hidden } = this.state();\n return { style: style && this.window.resolve(style), hidden };\n });\n\n constructor() {\n // Straight from the source rather than through an effect, so an `auto` bar changes in the same\n // turn as the scheme. The scheme is the listener's own: `ColorScheme.current` may not have\n // heard yet.\n const stop = inject(ColorScheme.SOURCE).subscribe((scheme) =>\n this.window.schemeChanged(this.owner, scheme),\n );\n inject(DestroyRef).onDestroy(() => {\n stop();\n // An app that goes takes its claims with it, and leaves the bar to the apps still here.\n this.window.claims.drop(this.owner);\n this.window.apply();\n });\n }\n\n /** The base claim, for an app that sets the bar once at startup. */\n set(state: StatusBarState): void {\n this.window.claims.setBase(this.owner, state);\n this.window.apply();\n }\n\n /** A claim on top of whatever is there. Call the returned function to drop it. */\n push(state: StatusBarState): () => void {\n const drop = this.window.claims.push(this.owner, { ...state });\n this.window.apply();\n return () => {\n drop();\n this.window.apply();\n };\n }\n}\n\ninterface Owner {\n readonly scheme: ColorScheme;\n}\n\n/** The bar, as every app on one source claims it. */\nclass StatusBarWindow {\n readonly claims = new WindowClaims<StatusBarState, Owner>();\n readonly state: Signal<StatusBarState> = computed(() =>\n mergeClaims(this.claims.all().map((claim) => claim.value)),\n );\n\n /** The properties a claim has had the platform change, which no claim names any more. */\n private readonly changed = new Set<'style' | 'hidden' | 'translucent'>();\n\n private readonly source: StatusBarSource;\n\n constructor(source: StatusBarSource) {\n this.source = source;\n // Lives as long as the source, which is the runtime's.\n source.onWindowFront?.(() => this.apply(true));\n }\n\n /** `style` for the platform, `auto` by the scheme of the app whose claim the style is. */\n resolve(style: StatusBarStyle, scheme?: Scheme): PlatformStatusBarStyle {\n return resolve(style, scheme ?? this.styleOwner()?.scheme.current() ?? 'light');\n }\n\n schemeChanged(owner: Owner, scheme: Scheme): void {\n const { style, animated } = untracked(this.state);\n if (style !== 'auto' || untracked(() => this.styleOwner()) !== owner) return;\n this.source.setStyle(this.resolve(style, scheme), animated);\n }\n\n /**\n * Push the merged state at the platform.\n *\n * Written whole rather than diffed: the platform's own setters are the cheap part. A property\n * the last claim to name it has dropped goes back to the platform's own, once. Not the\n * background color, whose own the theme decides. Read untracked, so an effect that sets the bar\n * does not also subscribe to it and run again on every later claim. A window come to the front\n * is given what is claimed, with nothing animated and nothing put back.\n */\n apply(front = false): void {\n const { style, hidden, animated, backgroundColor, translucent } = untracked(this.state);\n const animate = front ? undefined : animated;\n if (this.changes('style', style)) {\n this.source.setStyle(\n untracked(() => this.resolve(style ?? 'default')),\n animate,\n );\n }\n if (this.changes('hidden', hidden)) {\n this.source.setHidden(hidden ?? false, animate ? 'fade' : undefined);\n }\n if (backgroundColor !== undefined) this.source.setBackgroundColor(backgroundColor, animate);\n if (this.changes('translucent', translucent)) {\n this.source.setTranslucent(translucent ?? false);\n }\n }\n\n /** The app whose claim the style in force comes from. */\n private styleOwner(): Owner | undefined {\n return this.claims.last((state) => state.style !== undefined)?.owner;\n }\n\n /** Whether to tell the platform: a claim names `property`, or the last one to has dropped. */\n private changes(property: 'style' | 'hidden' | 'translucent', value: unknown): boolean {\n if (value === undefined) return this.changed.delete(property);\n this.changed.add(property);\n return true;\n }\n}\n\n/** Dark text on the light scheme's light background, light text on the dark one's. */\nfunction resolve(style: StatusBarStyle, scheme: Scheme): PlatformStatusBarStyle {\n if (style !== 'auto') return style;\n return scheme === 'dark' ? 'light' : 'dark';\n}\n"]}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What an app claims of the window: the status bar, the navigation bar, keep-awake, the orientation
|
|
3
|
+
* lock, the brightness, screen capture.
|
|
4
|
+
*
|
|
5
|
+
* The window is the runtime's, not an app's. Android recreates an activity after a configuration
|
|
6
|
+
* change it does not handle, a font size change among them: it mounts the new app on a new surface
|
|
7
|
+
* and only then stops the old one. Claims kept per app would let the old app, going after the new
|
|
8
|
+
* one has claimed, put the window back to the platform's own under the new app. So every app's
|
|
9
|
+
* claims for one native module are kept together, in one stack per module, as React Native keeps
|
|
10
|
+
* its own status bar's, and an app's claims leave with it.
|
|
11
|
+
*
|
|
12
|
+
* The window an app writes to can also be a new one: the recreated activity starts at the
|
|
13
|
+
* platform's own, and a call that comes while no activity is current is dropped. So a source tells
|
|
14
|
+
* its stack when a window comes to the front, and the stack writes the whole of it again.
|
|
15
|
+
*/
|
|
16
|
+
import { type Signal } from '@angular/core';
|
|
17
|
+
/** One claim, and the app it came from. */
|
|
18
|
+
export interface Claim<T, O = unknown> {
|
|
19
|
+
readonly value: T;
|
|
20
|
+
readonly owner: O;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Every app's claims on one native module. An app's base claim is under its own pushed ones, and
|
|
24
|
+
* an app's claims are under those of an app that claimed after it first did.
|
|
25
|
+
*/
|
|
26
|
+
export declare class WindowClaims<T, O extends object = object> {
|
|
27
|
+
private readonly groups;
|
|
28
|
+
/** Every claim, the one in force last. */
|
|
29
|
+
readonly all: Signal<readonly Claim<T, O>[]>;
|
|
30
|
+
/** The claim in force last that passes `test`. */
|
|
31
|
+
last(test: (value: T) => boolean): Claim<T, O> | undefined;
|
|
32
|
+
/** The apps with claims, the one that claimed first first. */
|
|
33
|
+
readonly owners: Signal<readonly O[]>;
|
|
34
|
+
/** `owner`'s base claim, replacing the one it had. */
|
|
35
|
+
setBase(owner: O, value: T): void;
|
|
36
|
+
/** A claim of `owner`'s on top of its others. Call the returned function to drop it. */
|
|
37
|
+
push(owner: O, value: T): () => void;
|
|
38
|
+
/** Every app's claims. */
|
|
39
|
+
clear(): void;
|
|
40
|
+
/** Every claim of `owner`'s, for an app that goes. */
|
|
41
|
+
drop(owner: O): void;
|
|
42
|
+
private update;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* What every app on `source` shares, made the first time one asks. `source` is the native module
|
|
46
|
+
* the app writes through, or null for one that is not there.
|
|
47
|
+
*/
|
|
48
|
+
export declare function sharedBySource<W>(source: object | null, create: () => W): W;
|
|
49
|
+
/**
|
|
50
|
+
* Android: calls `listener` each time an activity comes to the front, a recreated one included,
|
|
51
|
+
* which starts with the platform's own window. Answers the function that stops listening. Nothing
|
|
52
|
+
* on iOS, where a window keeps what it was given.
|
|
53
|
+
*/
|
|
54
|
+
export declare function onWindowFront(listener: () => void): () => void;
|
|
55
|
+
/**
|
|
56
|
+
* A window setting only the top claim decides, such as the orientation lock: every app's claims,
|
|
57
|
+
* the one claimed last in force, and the platform's own when none is left.
|
|
58
|
+
*/
|
|
59
|
+
export declare class TopClaim<T> {
|
|
60
|
+
readonly claims: WindowClaims<T, object>;
|
|
61
|
+
/** The claim the platform was last given, so a claim under it changes nothing. */
|
|
62
|
+
private sent;
|
|
63
|
+
private readonly put;
|
|
64
|
+
private readonly putBack;
|
|
65
|
+
constructor(put: (value: T) => void, putBack: () => void, onFront?: (listener: () => void) => () => void);
|
|
66
|
+
/** Tell the platform, if the claim in force is not the one it was last given. */
|
|
67
|
+
apply(): void;
|
|
68
|
+
/** Every app's claims, and the platform's own back. */
|
|
69
|
+
clear(): void;
|
|
70
|
+
}
|