@sigx/lynx-appearance 0.4.1 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +93 -0
- package/package.json +6 -6
package/README.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# @sigx/lynx-appearance
|
|
2
|
+
|
|
3
|
+
System color-scheme observer + status-bar / navigation-bar tint setters for sigx-lynx. The native publisher writes `lynx.__globalProps.appearance` before MT first paint, so the initial light/dark value is available on cold start with no flash; subsequent system flips publish through `GlobalEventEmitter` and update a BG signal.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @sigx/lynx-appearance
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
`sigx prebuild` auto-discovers the package, registers `AppearanceModule` / `AppearancePublisher` on both platforms, and wires the iOS host VC to forward `preferredStatusBarStyle` to the module so `setStatusBarStyle(...)` actually takes effect.
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
Mount the provider once near the root, then read the color scheme reactively from any component:
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import { component, effect } from '@sigx/lynx';
|
|
19
|
+
import {
|
|
20
|
+
AppearanceProvider,
|
|
21
|
+
useSystemColorScheme,
|
|
22
|
+
setSystemBarsStyle,
|
|
23
|
+
} from '@sigx/lynx-appearance';
|
|
24
|
+
|
|
25
|
+
const Root = component(() => () => (
|
|
26
|
+
<AppearanceProvider>
|
|
27
|
+
<App />
|
|
28
|
+
</AppearanceProvider>
|
|
29
|
+
));
|
|
30
|
+
|
|
31
|
+
const App = component(() => {
|
|
32
|
+
const scheme = useSystemColorScheme();
|
|
33
|
+
|
|
34
|
+
// Keep the system bars in sync with the current scheme.
|
|
35
|
+
effect(() => {
|
|
36
|
+
void setSystemBarsStyle({
|
|
37
|
+
statusBar: scheme.value === 'dark' ? 'light' : 'dark',
|
|
38
|
+
statusBarBackground: scheme.value === 'dark' ? '#000' : '#fff',
|
|
39
|
+
navigationBar: { style: scheme.value === 'dark' ? 'light' : 'dark' },
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
return () => (
|
|
44
|
+
<text>System is {scheme.value} mode</text>
|
|
45
|
+
);
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
From inside a `'main thread'` worklet, use the sync variant — no subscription, reads `lynx.__globalProps` directly:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import { useSystemColorSchemeMT } from '@sigx/lynx-appearance';
|
|
53
|
+
// inside a main-thread worklet body:
|
|
54
|
+
const isDark = useSystemColorSchemeMT() === 'dark';
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## API
|
|
58
|
+
|
|
59
|
+
| Surface | Use for |
|
|
60
|
+
|---|---|
|
|
61
|
+
| `AppearanceProvider` | Mount once near the root. Provides the live color-scheme signal to descendants. |
|
|
62
|
+
| `useSystemColorScheme()` | BG-side reactive read. Returns a signal of `'light' \| 'dark'`. Re-runs effects when the user flips dark mode in system settings. |
|
|
63
|
+
| `useSystemColorSchemeMT()` | MT-side sync read. Returns `'light' \| 'dark'` from `lynx.__globalProps`. For use inside `'main thread'` worklet bodies. |
|
|
64
|
+
| `setStatusBarStyle(style)` | Set status-bar *content* tint. `'light'` = light icons (legible on dark bg). |
|
|
65
|
+
| `setStatusBarBackgroundColor(color)` | **Android only** — status-bar background color (`null` clears). iOS resolves `{ ok: false, reason: 'unsupported' }`. |
|
|
66
|
+
| `setNavigationBarStyle({ style, color? })` | **Android only** — navigation-bar tint + optional background. iOS resolves `{ ok: false, reason: 'unsupported' }`. |
|
|
67
|
+
| `setSystemBarsStyle({ statusBar?, statusBarBackground?, navigationBar? })` | Convenience — apply all three in one deterministic call. Returns first non-`unsupported` failure, or `{ ok: true }`. |
|
|
68
|
+
| `isAvailable()` | Whether the native Appearance module is registered in the current build. |
|
|
69
|
+
| `APPEARANCE_EVENT` | The event name (`'appearanceChanged'`) fired by the native publishers. Exported so iOS / Android / JS agree on a single string. |
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
type ColorScheme = 'light' | 'dark';
|
|
73
|
+
type SystemBarStyle = 'light' | 'dark';
|
|
74
|
+
interface SetterResult {
|
|
75
|
+
ok: boolean;
|
|
76
|
+
/** Present when `ok === false` — e.g. `'unsupported'` on iOS for
|
|
77
|
+
* nav-bar / status-bar-background calls. */
|
|
78
|
+
reason?: string;
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
All setters return `Promise<SetterResult>` and **never reject** — unwired platforms, web preview, SSR, and test runs all resolve to `{ ok: false, reason: 'unsupported' }`. You can therefore `void setSystemBarsStyle(...)` without risking unhandled rejections.
|
|
83
|
+
|
|
84
|
+
## Gotchas
|
|
85
|
+
|
|
86
|
+
- **iOS status-bar style needs host VC forwarding.** `setStatusBarStyle(...)` resolves successfully but won't visibly change anything unless the host view controller forwards `preferredStatusBarStyle` to `AppearanceModule.preferredStatusBarStyle`. The lynx-cli iOS template does this automatically; if you're integrating into an existing UIViewController, copy the forwarding pattern.
|
|
87
|
+
- **Android 15+ (API 35) edge-to-edge.** `setStatusBarBackgroundColor` is a no-op at the system level on API 35+ because edge-to-edge is enforced. Render your own background view inside the safe-area top padding instead — pairs naturally with [`@sigx/lynx-safe-area`](https://github.com/signalxjs/lynx/tree/main/packages/lynx-safe-area).
|
|
88
|
+
- **`'light'` vs `'dark'` is the *content* tint, not the background.** `style: 'light'` means "light-colored icons" (so a dark background behind them is legible). Easy to flip the wrong way the first time.
|
|
89
|
+
- **Cold-start value.** `readGlobalColorScheme()` reads the value the native publisher wrote before first paint. If it returns `null` (e.g. running on a host that didn't link the publisher), the hook seeds `'light'` as a safe default.
|
|
90
|
+
|
|
91
|
+
## License
|
|
92
|
+
|
|
93
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sigx/lynx-appearance",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "System appearance (color scheme observation + status/navigation bar tint setters) for sigx-lynx",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -31,15 +31,15 @@
|
|
|
31
31
|
"license": "MIT",
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@sigx/reactivity": "^0.4.8",
|
|
34
|
-
"@sigx/lynx": "^0.4.
|
|
35
|
-
"@sigx/lynx-core": "^0.4.
|
|
34
|
+
"@sigx/lynx": "^0.4.3",
|
|
35
|
+
"@sigx/lynx-core": "^0.4.3"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@typescript/native-preview": "7.0.0-dev.20260521.1",
|
|
39
39
|
"typescript": "^6.0.3",
|
|
40
|
-
"@sigx/lynx-plugin": "^0.4.
|
|
41
|
-
"@sigx/lynx-testing": "^0.4.
|
|
42
|
-
"@sigx/lynx-runtime-main": "^0.4.
|
|
40
|
+
"@sigx/lynx-plugin": "^0.4.3",
|
|
41
|
+
"@sigx/lynx-testing": "^0.4.3",
|
|
42
|
+
"@sigx/lynx-runtime-main": "^0.4.3"
|
|
43
43
|
},
|
|
44
44
|
"repository": {
|
|
45
45
|
"type": "git",
|