@oxyhq/bloom 0.6.13 → 0.6.14
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/lib/commonjs/hooks/useControllableState.js +35 -0
- package/lib/commonjs/hooks/useControllableState.js.map +1 -0
- package/lib/commonjs/theme/BloomThemeProvider.js +134 -112
- package/lib/commonjs/theme/BloomThemeProvider.js.map +1 -1
- package/lib/commonjs/theme/build-theme.js +110 -0
- package/lib/commonjs/theme/build-theme.js.map +1 -0
- package/lib/commonjs/theme/color-presets.js +15 -0
- package/lib/commonjs/theme/color-presets.js.map +1 -1
- package/lib/commonjs/theme/index.js +15 -1
- package/lib/commonjs/theme/index.js.map +1 -1
- package/lib/commonjs/theme/persistence.js +127 -0
- package/lib/commonjs/theme/persistence.js.map +1 -0
- package/lib/commonjs/theme/use-isomorphic-layout-effect.js +15 -0
- package/lib/commonjs/theme/use-isomorphic-layout-effect.js.map +1 -0
- package/lib/module/hooks/useControllableState.js +31 -0
- package/lib/module/hooks/useControllableState.js.map +1 -0
- package/lib/module/theme/BloomThemeProvider.js +135 -112
- package/lib/module/theme/BloomThemeProvider.js.map +1 -1
- package/lib/module/theme/build-theme.js +105 -0
- package/lib/module/theme/build-theme.js.map +1 -0
- package/lib/module/theme/color-presets.js +15 -0
- package/lib/module/theme/color-presets.js.map +1 -1
- package/lib/module/theme/index.js +3 -1
- package/lib/module/theme/index.js.map +1 -1
- package/lib/module/theme/persistence.js +120 -0
- package/lib/module/theme/persistence.js.map +1 -0
- package/lib/module/theme/use-isomorphic-layout-effect.js +12 -0
- package/lib/module/theme/use-isomorphic-layout-effect.js.map +1 -0
- package/lib/typescript/commonjs/hooks/useControllableState.d.ts +19 -0
- package/lib/typescript/commonjs/hooks/useControllableState.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme/BloomThemeProvider.d.ts +29 -12
- package/lib/typescript/commonjs/theme/BloomThemeProvider.d.ts.map +1 -1
- package/lib/typescript/commonjs/theme/build-theme.d.ts +20 -0
- package/lib/typescript/commonjs/theme/build-theme.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme/color-presets.d.ts +18 -3
- package/lib/typescript/commonjs/theme/color-presets.d.ts.map +1 -1
- package/lib/typescript/commonjs/theme/index.d.ts +7 -4
- package/lib/typescript/commonjs/theme/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/theme/persistence.d.ts +48 -0
- package/lib/typescript/commonjs/theme/persistence.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme/use-isomorphic-layout-effect.d.ts +8 -0
- package/lib/typescript/commonjs/theme/use-isomorphic-layout-effect.d.ts.map +1 -0
- package/lib/typescript/module/hooks/useControllableState.d.ts +19 -0
- package/lib/typescript/module/hooks/useControllableState.d.ts.map +1 -0
- package/lib/typescript/module/theme/BloomThemeProvider.d.ts +29 -12
- package/lib/typescript/module/theme/BloomThemeProvider.d.ts.map +1 -1
- package/lib/typescript/module/theme/build-theme.d.ts +20 -0
- package/lib/typescript/module/theme/build-theme.d.ts.map +1 -0
- package/lib/typescript/module/theme/color-presets.d.ts +18 -3
- package/lib/typescript/module/theme/color-presets.d.ts.map +1 -1
- package/lib/typescript/module/theme/index.d.ts +7 -4
- package/lib/typescript/module/theme/index.d.ts.map +1 -1
- package/lib/typescript/module/theme/persistence.d.ts +48 -0
- package/lib/typescript/module/theme/persistence.d.ts.map +1 -0
- package/lib/typescript/module/theme/use-isomorphic-layout-effect.d.ts +8 -0
- package/lib/typescript/module/theme/use-isomorphic-layout-effect.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/BloomThemeProvider.modes.test.tsx +159 -0
- package/src/__tests__/BloomThemeProvider.persistence.test.tsx +217 -0
- package/src/__tests__/persistence.test.ts +155 -0
- package/src/__tests__/theme.test.ts +1 -1
- package/src/hooks/useControllableState.ts +44 -0
- package/src/theme/BloomThemeProvider.tsx +219 -157
- package/src/theme/build-theme.ts +128 -0
- package/src/theme/color-presets.ts +19 -3
- package/src/theme/index.ts +16 -4
- package/src/theme/persistence.ts +149 -0
- package/src/theme/use-isomorphic-layout-effect.ts +10 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
|
+
import { APP_COLOR_PRESETS, type AppColorName, type PresetTokens } from './color-presets';
|
|
3
|
+
import { getAdaptiveColors } from './adaptive-colors';
|
|
4
|
+
import type { Theme, ThemeColors } from './types';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Status colors used across the design system. Independent of the accent
|
|
8
|
+
* preset so semantic intent stays stable across themes.
|
|
9
|
+
*/
|
|
10
|
+
export const STATUS_COLORS = {
|
|
11
|
+
success: '#10B981',
|
|
12
|
+
error: '#EF4444',
|
|
13
|
+
warning: '#F59E0B',
|
|
14
|
+
info: '#3B82F6',
|
|
15
|
+
} as const;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Convert a shadcn-style HSL CSS variable (`'H S% L%'` or `'H S% L% / A'`)
|
|
19
|
+
* into a fully-resolved `hsl()` / `hsla()` color string consumable by both
|
|
20
|
+
* web `style` and React Native.
|
|
21
|
+
*/
|
|
22
|
+
function hslVarToColor(hslVar: string): string {
|
|
23
|
+
const parts = hslVar.split('/').map((p) => p.trim());
|
|
24
|
+
const triple = parts[0] ?? '0 0% 0%';
|
|
25
|
+
const components = triple.replace(/\s+/g, ', ');
|
|
26
|
+
|
|
27
|
+
if (parts.length === 2) {
|
|
28
|
+
const alpha = parseFloat(parts[1] ?? '100') / 100;
|
|
29
|
+
return `hsla(${components}, ${alpha})`;
|
|
30
|
+
}
|
|
31
|
+
return `hsl(${components})`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function extractHue(hslVar: string): number {
|
|
35
|
+
const first = hslVar.split(/\s+/)[0] ?? '0';
|
|
36
|
+
const hue = parseInt(first, 10);
|
|
37
|
+
return Number.isFinite(hue) ? hue : 0;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function hsl(h: number, s: number, l: number): string {
|
|
41
|
+
return `hsl(${h}, ${s}%, ${l}%)`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function readToken(tokens: PresetTokens, key: string, fallback = '0 0% 0%'): string {
|
|
45
|
+
return hslVarToColor(tokens[key] ?? fallback);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function buildColorsFromPreset(
|
|
49
|
+
preset: AppColorName,
|
|
50
|
+
resolved: 'light' | 'dark',
|
|
51
|
+
): ThemeColors {
|
|
52
|
+
const config = APP_COLOR_PRESETS[preset];
|
|
53
|
+
const tokens = resolved === 'dark' ? config.dark : config.light;
|
|
54
|
+
const isDark = resolved === 'dark';
|
|
55
|
+
|
|
56
|
+
const primaryHue = extractHue(tokens['--primary'] ?? '0 0% 50%');
|
|
57
|
+
const destructiveHue = extractHue(tokens['--destructive'] ?? '0 0% 0%');
|
|
58
|
+
|
|
59
|
+
const background = readToken(tokens, '--background');
|
|
60
|
+
const surface = readToken(tokens, '--surface');
|
|
61
|
+
const mutedForeground = readToken(tokens, '--muted-foreground', '0 0% 50%');
|
|
62
|
+
const primaryColor = readToken(tokens, '--primary', '0 0% 50%');
|
|
63
|
+
const primaryForeground = readToken(tokens, '--primary-foreground', '0 0% 100%');
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
background,
|
|
67
|
+
backgroundSecondary: surface,
|
|
68
|
+
backgroundTertiary: readToken(tokens, '--muted'),
|
|
69
|
+
|
|
70
|
+
text: readToken(tokens, '--foreground', '0 0% 100%'),
|
|
71
|
+
textSecondary: mutedForeground,
|
|
72
|
+
textTertiary: mutedForeground,
|
|
73
|
+
|
|
74
|
+
border: readToken(tokens, '--border', '0 0% 20%'),
|
|
75
|
+
borderLight: readToken(tokens, '--input', '0 0% 20%'),
|
|
76
|
+
|
|
77
|
+
primary: primaryColor,
|
|
78
|
+
primaryForeground,
|
|
79
|
+
// Legacy aliases retained for backwards compatibility with downstream
|
|
80
|
+
// consumers. `primaryLight` should be a brand tint, not the surface, but
|
|
81
|
+
// changing this is a breaking change handled in a separate major.
|
|
82
|
+
primaryLight: surface,
|
|
83
|
+
primaryDark: background,
|
|
84
|
+
|
|
85
|
+
// `secondary` historically mirrored `primary`. Retained for compatibility.
|
|
86
|
+
secondary: primaryColor,
|
|
87
|
+
|
|
88
|
+
tint: primaryColor,
|
|
89
|
+
icon: mutedForeground,
|
|
90
|
+
iconActive: primaryColor,
|
|
91
|
+
|
|
92
|
+
...STATUS_COLORS,
|
|
93
|
+
|
|
94
|
+
primarySubtle: isDark ? hsl(primaryHue, 50, 10) : hsl(primaryHue, 70, 93),
|
|
95
|
+
primarySubtleForeground: isDark ? hsl(primaryHue, 70, 65) : hsl(primaryHue, 90, 25),
|
|
96
|
+
negative: hsl(destructiveHue, 84, 45),
|
|
97
|
+
negativeForeground: '#FFFFFF',
|
|
98
|
+
negativeSubtle: isDark ? hsl(destructiveHue, 50, 10) : hsl(destructiveHue, 90, 95),
|
|
99
|
+
negativeSubtleForeground: isDark ? hsl(destructiveHue, 70, 65) : hsl(destructiveHue, 80, 40),
|
|
100
|
+
contrast50: isDark ? hsl(primaryHue, 15, 12) : hsl(primaryHue, 10, 93),
|
|
101
|
+
|
|
102
|
+
card: surface,
|
|
103
|
+
shadow: isDark ? 'rgba(0, 0, 0, 0.3)' : 'rgba(0, 0, 0, 0.1)',
|
|
104
|
+
overlay: 'rgba(0, 0, 0, 0.5)',
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Build a `Theme` from a color preset and a resolved light/dark mode.
|
|
110
|
+
*
|
|
111
|
+
* When `isAdaptive` is true and the platform exposes adaptive (Material You /
|
|
112
|
+
* iOS dynamic) colors, those override the preset-derived palette.
|
|
113
|
+
*/
|
|
114
|
+
export function buildTheme(
|
|
115
|
+
preset: AppColorName,
|
|
116
|
+
resolved: 'light' | 'dark',
|
|
117
|
+
isAdaptive: boolean = false,
|
|
118
|
+
): Theme {
|
|
119
|
+
const adaptive = isAdaptive && Platform.OS !== 'web' ? getAdaptiveColors() : undefined;
|
|
120
|
+
const colors = adaptive ?? buildColorsFromPreset(preset, resolved);
|
|
121
|
+
|
|
122
|
+
return {
|
|
123
|
+
mode: resolved,
|
|
124
|
+
colors,
|
|
125
|
+
isDark: resolved === 'dark',
|
|
126
|
+
isLight: resolved === 'light',
|
|
127
|
+
};
|
|
128
|
+
}
|
|
@@ -1,13 +1,29 @@
|
|
|
1
1
|
export type AppColorName = 'teal' | 'blue' | 'green' | 'amber' | 'yellow' | 'red' | 'purple' | 'pink' | 'sky' | 'orange' | 'mint' | 'oxy' | 'faircoin';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Palette tokens for a single mode (light or dark) of a color preset.
|
|
5
|
+
*
|
|
6
|
+
* Keys carry a leading `--` for historical reasons (shadcn-style CSS variable
|
|
7
|
+
* names) — keep in mind the values are platform-agnostic **raw HSL triples**
|
|
8
|
+
* (e.g. `'185 100% 20%'` or `'185 100% 20% / 0.5'`), not CSS-resolved colors.
|
|
9
|
+
* The same map drives both:
|
|
10
|
+
* - the web layer (written verbatim into `document.documentElement.style`
|
|
11
|
+
* so Tailwind's `hsl(var(--primary))` plumbing picks them up), and
|
|
12
|
+
* - the native layer (`buildTheme` resolves them into `hsl(...)` strings
|
|
13
|
+
* consumable by React Native styles).
|
|
14
|
+
*
|
|
15
|
+
* The `--` prefix is an implementation detail we will drop in a future major.
|
|
16
|
+
*/
|
|
17
|
+
export type PresetTokens = Record<string, string>;
|
|
18
|
+
|
|
3
19
|
export interface AppColorPreset {
|
|
4
20
|
name: AppColorName;
|
|
5
21
|
hex: string;
|
|
6
|
-
light:
|
|
7
|
-
dark:
|
|
22
|
+
light: PresetTokens;
|
|
23
|
+
dark: PresetTokens;
|
|
8
24
|
}
|
|
9
25
|
|
|
10
|
-
export const APP_COLOR_NAMES: AppColorName[] = ['teal', 'blue', 'green', 'amber', 'yellow', 'red', 'purple', 'pink', 'sky', 'orange', 'mint', 'oxy', 'faircoin'];
|
|
26
|
+
export const APP_COLOR_NAMES: readonly AppColorName[] = ['teal', 'blue', 'green', 'amber', 'yellow', 'red', 'purple', 'pink', 'sky', 'orange', 'mint', 'oxy', 'faircoin'];
|
|
11
27
|
|
|
12
28
|
export const HEX_TO_APP_COLOR: Record<string, AppColorName> = {
|
|
13
29
|
'#005c67': 'teal',
|
package/src/theme/index.ts
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
|
-
export { BloomThemeProvider, BloomColorScope
|
|
2
|
-
export type {
|
|
1
|
+
export { BloomThemeProvider, BloomColorScope } from './BloomThemeProvider';
|
|
2
|
+
export type {
|
|
3
|
+
BloomThemeProviderProps,
|
|
4
|
+
BloomThemeContextValue,
|
|
5
|
+
BloomColorScopeProps,
|
|
6
|
+
} from './BloomThemeProvider';
|
|
7
|
+
export { buildTheme, STATUS_COLORS } from './build-theme';
|
|
3
8
|
export { useTheme, useThemeColor, useBloomTheme } from './use-theme';
|
|
4
9
|
export type { Theme, ThemeColors, ThemeMode } from './types';
|
|
5
|
-
export type { AppColorName, AppColorPreset } from './color-presets';
|
|
6
|
-
export {
|
|
10
|
+
export type { AppColorName, AppColorPreset, PresetTokens } from './color-presets';
|
|
11
|
+
export {
|
|
12
|
+
APP_COLOR_NAMES,
|
|
13
|
+
APP_COLOR_PRESETS,
|
|
14
|
+
HEX_TO_APP_COLOR,
|
|
15
|
+
hexToAppColorName,
|
|
16
|
+
} from './color-presets';
|
|
7
17
|
export { applyDarkClass } from './apply-dark-class';
|
|
8
18
|
export { setColorSchemeSafe } from './set-color-scheme-safe';
|
|
9
19
|
export { initCssInteropDarkMode } from './init-css-interop';
|
|
20
|
+
export type { BloomThemeStorage, PersistedThemeState } from './persistence';
|
|
21
|
+
export { webLocalStorage } from './persistence';
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
|
+
import { APP_COLOR_NAMES, type AppColorName } from './color-presets';
|
|
3
|
+
import type { ThemeMode } from './types';
|
|
4
|
+
|
|
5
|
+
const VALID_PRESETS = new Set<string>(APP_COLOR_NAMES);
|
|
6
|
+
const VALID_MODES = new Set<string>(['light', 'dark', 'system', 'adaptive']);
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Storage adapter for persisting Bloom theme state.
|
|
10
|
+
*
|
|
11
|
+
* Methods may be synchronous or asynchronous. The provider awaits both, so
|
|
12
|
+
* `AsyncStorage`-compatible adapters on native and `localStorage`-backed
|
|
13
|
+
* adapters on web both work without consumer-side branching.
|
|
14
|
+
*
|
|
15
|
+
* On web, a synchronous adapter lets Bloom hydrate before the first paint —
|
|
16
|
+
* preventing a flash of the default palette. On native, the provider can
|
|
17
|
+
* gate `children` rendering until hydration completes (see
|
|
18
|
+
* `awaitHydration` on `BloomThemeProvider`).
|
|
19
|
+
*/
|
|
20
|
+
export interface BloomThemeStorage {
|
|
21
|
+
getItem(key: string): string | null | Promise<string | null>;
|
|
22
|
+
setItem(key: string, value: string): void | Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface PersistedThemeState {
|
|
26
|
+
mode?: ThemeMode;
|
|
27
|
+
colorPreset?: AppColorName;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const isValidMode = (value: unknown): value is ThemeMode =>
|
|
31
|
+
typeof value === 'string' && VALID_MODES.has(value);
|
|
32
|
+
|
|
33
|
+
const isValidPreset = (value: unknown): value is AppColorName =>
|
|
34
|
+
typeof value === 'string' && VALID_PRESETS.has(value);
|
|
35
|
+
|
|
36
|
+
function parsePersistedTheme(raw: unknown): PersistedThemeState | null {
|
|
37
|
+
if (typeof raw !== 'string') return null;
|
|
38
|
+
|
|
39
|
+
let parsed: unknown;
|
|
40
|
+
try {
|
|
41
|
+
parsed = JSON.parse(raw);
|
|
42
|
+
} catch {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!parsed || typeof parsed !== 'object') return null;
|
|
47
|
+
const obj = parsed as { mode?: unknown; colorPreset?: unknown };
|
|
48
|
+
|
|
49
|
+
const mode = isValidMode(obj.mode) ? obj.mode : undefined;
|
|
50
|
+
const colorPreset = isValidPreset(obj.colorPreset) ? obj.colorPreset : undefined;
|
|
51
|
+
|
|
52
|
+
if (!mode && !colorPreset) return null;
|
|
53
|
+
return { mode, colorPreset };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export type SyncReadResult =
|
|
57
|
+
| { kind: 'sync'; state: PersistedThemeState | null }
|
|
58
|
+
| { kind: 'async' }
|
|
59
|
+
| { kind: 'none' };
|
|
60
|
+
|
|
61
|
+
const isThenable = (value: unknown): value is Promise<unknown> =>
|
|
62
|
+
!!value && typeof (value as { then?: unknown }).then === 'function';
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Read persisted state during the first render. Returns a discriminated union
|
|
66
|
+
* so the provider can tell apart:
|
|
67
|
+
* - `none`: persistence not configured.
|
|
68
|
+
* - `sync`: adapter returned a value synchronously (web `localStorage`).
|
|
69
|
+
* Provider can render immediately with the resolved state.
|
|
70
|
+
* - `async`: adapter returned a Promise (native `AsyncStorage`). Provider
|
|
71
|
+
* must await `readPersistedTheme` before painting if gating is enabled.
|
|
72
|
+
*/
|
|
73
|
+
export function readPersistedThemeSync(
|
|
74
|
+
persistKey: string | undefined,
|
|
75
|
+
storage: BloomThemeStorage | undefined,
|
|
76
|
+
): SyncReadResult {
|
|
77
|
+
if (!persistKey || !storage) return { kind: 'none' };
|
|
78
|
+
|
|
79
|
+
let raw: string | null | Promise<string | null>;
|
|
80
|
+
try {
|
|
81
|
+
raw = storage.getItem(persistKey);
|
|
82
|
+
} catch {
|
|
83
|
+
return { kind: 'sync', state: null };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (isThenable(raw)) return { kind: 'async' };
|
|
87
|
+
return { kind: 'sync', state: parsePersistedTheme(raw) };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export async function readPersistedTheme(
|
|
91
|
+
persistKey: string | undefined,
|
|
92
|
+
storage: BloomThemeStorage | undefined,
|
|
93
|
+
): Promise<PersistedThemeState | null> {
|
|
94
|
+
if (!persistKey || !storage) return null;
|
|
95
|
+
|
|
96
|
+
try {
|
|
97
|
+
const raw = await storage.getItem(persistKey);
|
|
98
|
+
return parsePersistedTheme(raw);
|
|
99
|
+
} catch {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export async function writePersistedTheme(
|
|
105
|
+
persistKey: string | undefined,
|
|
106
|
+
storage: BloomThemeStorage | undefined,
|
|
107
|
+
state: PersistedThemeState,
|
|
108
|
+
): Promise<void> {
|
|
109
|
+
if (!persistKey || !storage) return;
|
|
110
|
+
|
|
111
|
+
const payload: PersistedThemeState = {};
|
|
112
|
+
if (state.mode !== undefined) payload.mode = state.mode;
|
|
113
|
+
if (state.colorPreset !== undefined) payload.colorPreset = state.colorPreset;
|
|
114
|
+
|
|
115
|
+
try {
|
|
116
|
+
await storage.setItem(persistKey, JSON.stringify(payload));
|
|
117
|
+
} catch {
|
|
118
|
+
// Persistence is best-effort: ignore quota and privacy-mode errors.
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* `localStorage`-backed storage adapter. Only defined on web; on native the
|
|
124
|
+
* export is `undefined` so consumers pass an `AsyncStorage` adapter explicitly.
|
|
125
|
+
*/
|
|
126
|
+
export const webLocalStorage: BloomThemeStorage | undefined = (() => {
|
|
127
|
+
if (Platform.OS !== 'web') return undefined;
|
|
128
|
+
if (typeof globalThis === 'undefined') return undefined;
|
|
129
|
+
if (!('localStorage' in globalThis)) return undefined;
|
|
130
|
+
|
|
131
|
+
const ls = (globalThis as { localStorage: Storage }).localStorage;
|
|
132
|
+
|
|
133
|
+
return {
|
|
134
|
+
getItem: (key) => {
|
|
135
|
+
try {
|
|
136
|
+
return ls.getItem(key);
|
|
137
|
+
} catch {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
setItem: (key, value) => {
|
|
142
|
+
try {
|
|
143
|
+
ls.setItem(key, value);
|
|
144
|
+
} catch {
|
|
145
|
+
// Swallow quota / privacy-mode errors.
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
})();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { useEffect, useLayoutEffect } from 'react';
|
|
2
|
+
import { Platform } from 'react-native';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* `useLayoutEffect` on web (and native — react-native polyfills it) but falls
|
|
6
|
+
* back to `useEffect` during SSR to avoid the React warning. Bloom apps are
|
|
7
|
+
* primarily Expo (no SSR), but Next.js consumers of the web bundle need this.
|
|
8
|
+
*/
|
|
9
|
+
export const useIsomorphicLayoutEffect =
|
|
10
|
+
Platform.OS === 'web' && typeof document === 'undefined' ? useEffect : useLayoutEffect;
|