@mrmeg/expo-ui 0.2.0 → 0.4.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/constants/fonts.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
import { Platform } from "react-native";
|
|
1
2
|
// Web font stack fallback
|
|
2
3
|
const WEB_FONT_STACK = "system-ui, \"Segoe UI\", Roboto, Helvetica, Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\"";
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
// IMPORTANT: do NOT key these on `typeof document` / `typeof navigator`.
|
|
5
|
+
// On a web bundle, Node SSR sees `undefined` for both and the client sees them,
|
|
6
|
+
// producing different snapshot values at module load -> hydration mismatch on
|
|
7
|
+
// every <StyledText>. `Platform.OS` (from react-native-web) returns "web" in
|
|
8
|
+
// both environments, so the value is stable.
|
|
9
|
+
const isWebRuntime = Platform.OS === "web";
|
|
10
|
+
const isReactNativeRuntime = Platform.OS !== "web";
|
|
5
11
|
const serifFamilies = isWebRuntime
|
|
6
12
|
? { regular: "Georgia, 'Times New Roman', serif", bold: "Georgia, 'Times New Roman', serif" }
|
|
7
13
|
: { regular: "Georgia", bold: "Georgia" };
|
|
@@ -11,3 +11,4 @@ export declare function resolveThemePreference(userTheme: ThemePreference, syste
|
|
|
11
11
|
export declare const useThemeStore: import("zustand").UseBoundStore<import("zustand").StoreApi<ThemeStore>>;
|
|
12
12
|
export declare function syncSystemTheme(): void;
|
|
13
13
|
export declare function startSystemThemeListener(): () => void;
|
|
14
|
+
export declare function syncThemeFromEnvironment(): () => void;
|
package/dist/state/themeStore.js
CHANGED
|
@@ -13,7 +13,9 @@ function getSystemTheme() {
|
|
|
13
13
|
}
|
|
14
14
|
export const useThemeStore = create((set) => ({
|
|
15
15
|
userTheme: "system",
|
|
16
|
-
|
|
16
|
+
// Always start with "light" so SSR and the first client render agree.
|
|
17
|
+
// Real values are populated by `syncThemeFromEnvironment()` after mount.
|
|
18
|
+
systemTheme: "light",
|
|
17
19
|
setTheme: (theme) => {
|
|
18
20
|
set({
|
|
19
21
|
userTheme: theme,
|
|
@@ -89,6 +91,18 @@ export function startSystemThemeListener() {
|
|
|
89
91
|
};
|
|
90
92
|
return stopSystemThemeListener;
|
|
91
93
|
}
|
|
92
|
-
//
|
|
93
|
-
|
|
94
|
-
startSystemThemeListener
|
|
94
|
+
// Single entry point for host apps to populate the store from the
|
|
95
|
+
// environment (persisted preference + OS color scheme listener). Safe to
|
|
96
|
+
// call multiple times — `startSystemThemeListener` is idempotent — and
|
|
97
|
+
// returns the unsubscribe so it can be used directly inside `useEffect`.
|
|
98
|
+
export function syncThemeFromEnvironment() {
|
|
99
|
+
useThemeStore.getState().loadTheme();
|
|
100
|
+
return startSystemThemeListener();
|
|
101
|
+
}
|
|
102
|
+
// Native has no SSR mismatch concern, so keep the historical auto-init
|
|
103
|
+
// behavior there. On web the host app must call `syncThemeFromEnvironment()`
|
|
104
|
+
// from a top-level `useEffect` to avoid hydration mismatches.
|
|
105
|
+
if (Platform.OS !== "web") {
|
|
106
|
+
useThemeStore.getState().loadTheme();
|
|
107
|
+
startSystemThemeListener();
|
|
108
|
+
}
|