react-native-theme-transition 1.0.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.
@@ -0,0 +1,363 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * Screenshot-overlay transition engine and provider.
4
+ *
5
+ * @module
6
+ */
7
+ import { createContext, useCallback, useEffect, useMemo, useRef, useState } from 'react';
8
+ import { Appearance, AppState, Image, View } from 'react-native';
9
+ import Animated, { useAnimatedProps, useSharedValue, withTiming, } from 'react-native-reanimated';
10
+ import { captureRef } from 'react-native-view-shot';
11
+ import { scheduleOnRN } from 'react-native-worklets';
12
+ import { TAG } from './constants';
13
+ const ABSOLUTE_FILL = { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 };
14
+ // Avoids layout clipping on certain Android API levels.
15
+ const ROOT_STYLE = { flex: 1 };
16
+ /** Calls `fn` and swallows errors with a console.warn tagged by `label`. */
17
+ function safeCall(label, fn, ...args) {
18
+ try {
19
+ fn?.(...args);
20
+ }
21
+ catch (e) {
22
+ console.warn(`${TAG} ${label} threw:`, e);
23
+ }
24
+ }
25
+ /**
26
+ * Waits for `n` native animation frames to complete.
27
+ *
28
+ * @remarks
29
+ * React Native's rendering pipeline spans three phases:
30
+ * 1. **JS thread** — React reconciliation produces a virtual tree.
31
+ * 2. **Shadow Tree** — Yoga calculates layout from the virtual tree.
32
+ * 3. **Native UI thread** — platform views are painted on screen.
33
+ *
34
+ * Each phase runs on its own frame cadence (~16.67 ms at 60 fps).
35
+ * Waiting 1 frame lets React flush pending state or the compositor
36
+ * paint a decoded image.
37
+ *
38
+ * @param n - Number of animation frames to wait.
39
+ */
40
+ function waitFrames(n) {
41
+ return new Promise((resolve) => {
42
+ let remaining = n;
43
+ const tick = () => {
44
+ if (--remaining <= 0)
45
+ resolve();
46
+ else
47
+ requestAnimationFrame(tick);
48
+ };
49
+ requestAnimationFrame(tick);
50
+ });
51
+ }
52
+ /**
53
+ * Normalizes an OS color scheme string to `'light'` or `'dark'`.
54
+ *
55
+ * @remarks
56
+ * Only accepts the two known values. Any other input — including `null`,
57
+ * `undefined`, and `'unspecified'` (returned by RN after
58
+ * `Appearance.setColorScheme('unspecified')`) — defaults to `'light'`.
59
+ *
60
+ * @internal
61
+ */
62
+ function normalizeScheme(colorScheme, fallback = 'light') {
63
+ if (colorScheme === 'dark')
64
+ return 'dark';
65
+ if (colorScheme === 'light')
66
+ return 'light';
67
+ return fallback;
68
+ }
69
+ /**
70
+ * Maps an OS color scheme to a theme name via `systemThemeMap`.
71
+ *
72
+ * @remarks
73
+ * The fallback `scheme as Names` is only safe when the themes are named `'light'` and
74
+ * `'dark'`. Callers that use custom theme names must validate the result against `themes` —
75
+ * both `ThemeTransitionProvider` (for `initialTheme="system"`) and `setTheme`
76
+ * (for `setTheme('system')`) perform this validation and throw a clear error if the
77
+ * resolved name is not a registered theme.
78
+ *
79
+ * @internal
80
+ */
81
+ function mapSchemeToTheme(scheme, mapping) {
82
+ return mapping?.[scheme] ?? scheme;
83
+ }
84
+ /**
85
+ * Reads the current OS appearance and maps it to a theme name.
86
+ *
87
+ * @internal Convenience wrapper combining {@link normalizeScheme} and {@link mapSchemeToTheme}.
88
+ */
89
+ function resolveSystemTheme(mapping, fallbackScheme) {
90
+ return mapSchemeToTheme(normalizeScheme(Appearance.getColorScheme(), fallbackScheme), mapping);
91
+ }
92
+ /**
93
+ * Creates the React Context and provider component for a given theme configuration.
94
+ *
95
+ * @internal Used by {@link createThemeTransition}; not part of the public API.
96
+ */
97
+ export function createProviderAndContext(config) {
98
+ const { themes, duration = 350, systemThemeMap, darkThemes: darkThemesConfig, onTransitionStart: configOnTransitionStart, onTransitionEnd: configOnTransitionEnd, onThemeChange, } = config;
99
+ const darkThemeSet = new Set(darkThemesConfig ?? (systemThemeMap ? [systemThemeMap.dark] : ['dark']));
100
+ const schemeOf = (name) => darkThemeSet.has(name) ? 'dark' : 'light';
101
+ const Context = createContext(null);
102
+ function getColors(name) {
103
+ return { ...themes[name] };
104
+ }
105
+ function ThemeTransitionProvider({ children, initialTheme, }) {
106
+ const [activeTheme, setActiveTheme] = useState(() => {
107
+ const isInitialSystem = initialTheme === 'system';
108
+ const startTheme = isInitialSystem
109
+ ? resolveSystemTheme(systemThemeMap)
110
+ : initialTheme;
111
+ if (!(startTheme in themes)) {
112
+ throw new Error(`${TAG} initialTheme resolved to "${startTheme}" which does not exist in themes.${isInitialSystem ? ' Provide `systemThemeMap` in the config to map OS appearance to your theme names.' : ''}`);
113
+ }
114
+ return { colors: getColors(startTheme), name: startTheme };
115
+ });
116
+ const targetThemeRef = useRef(activeTheme.name);
117
+ const rootRef = useRef(null);
118
+ const transitioningRef = useRef(false);
119
+ // Guards async callbacks against running after unmount.
120
+ const mountedRef = useRef(true);
121
+ const [isTransitioning, setIsTransitioning] = useState(false);
122
+ const systemModeRef = useRef(initialTheme === 'system');
123
+ // State mirror of systemModeRef — triggers the Appearance.setColorScheme effect.
124
+ const [isSystemMode, setIsSystemMode] = useState(initialTheme === 'system');
125
+ const appStateRef = useRef(AppState.currentState);
126
+ // Stores a pending OS scheme change that arrived while a transition was
127
+ // running (and setTheme was rejected). Read by finishTransition.
128
+ const pendingSchemeRef = useRef(null);
129
+ // Blocks touches within one native frame, without waiting for a React re-render.
130
+ const isBlocking = useSharedValue(false);
131
+ const blockerProps = useAnimatedProps(() => ({
132
+ pointerEvents: isBlocking.value ? 'auto' : 'none',
133
+ }));
134
+ // State (not ref) so unsetting it unmounts the Image, freeing the captured bitmap.
135
+ const [overlayUri, setOverlayUri] = useState(null);
136
+ const overlayOpacity = useSharedValue(0);
137
+ // Stable reference prevents Reanimated from re-processing the style on React re-renders.
138
+ const overlayStyle = useMemo(() => ({ opacity: overlayOpacity }), [overlayOpacity]);
139
+ // Settled when the overlay Image fires onLoad (resolve) or onError (reject).
140
+ const overlayDecodeRef = useRef(null);
141
+ const overlaySource = useMemo(() => overlayUri ? { uri: overlayUri } : undefined, [overlayUri]);
142
+ const onOverlayLoad = useCallback(() => {
143
+ overlayDecodeRef.current?.resolve();
144
+ }, []);
145
+ const onOverlayError = useCallback(() => {
146
+ overlayDecodeRef.current?.reject();
147
+ }, []);
148
+ useEffect(() => {
149
+ mountedRef.current = true;
150
+ return () => {
151
+ mountedRef.current = false;
152
+ };
153
+ }, []);
154
+ // Keep native UI elements (alerts, date pickers, keyboards) in sync.
155
+ // Only applies in manual mode — in system mode the OS drives native UI
156
+ // via 'unspecified' (set once by setTheme when entering system mode).
157
+ useEffect(() => {
158
+ if (isSystemMode)
159
+ return;
160
+ if (isTransitioning)
161
+ return;
162
+ Appearance.setColorScheme(schemeOf(activeTheme.name));
163
+ }, [isSystemMode, activeTheme.name, isTransitioning]);
164
+ const resetTransition = useCallback(() => {
165
+ transitioningRef.current = false;
166
+ isBlocking.value = false;
167
+ setIsTransitioning(false);
168
+ setOverlayUri(null);
169
+ }, [isBlocking]);
170
+ const runTransition = useCallback(async (name, options) => {
171
+ try {
172
+ // Two frames so the JS → Shadow Tree → Native UI pipeline fully paints
173
+ // any pending state changes before the screenshot. useTheme({ initialSelection })
174
+ // adds its own requestAnimationFrame before calling setTheme, giving 3
175
+ // total frames — enough for React commit + native paint on 120Hz displays.
176
+ await waitFrames(2);
177
+ if (!mountedRef.current)
178
+ return;
179
+ const uri = await captureRef(rootRef, { format: 'jpg', quality: 0.8 });
180
+ if (!mountedRef.current)
181
+ return;
182
+ overlayOpacity.set(1);
183
+ await new Promise((resolve, reject) => {
184
+ overlayDecodeRef.current = { resolve, reject };
185
+ setOverlayUri(uri);
186
+ });
187
+ if (!mountedRef.current)
188
+ return;
189
+ await waitFrames(1);
190
+ if (!mountedRef.current)
191
+ return;
192
+ // Deferred until the overlay covers the screen so the re-render
193
+ // doesn't flash state-dependent visuals before the screenshot hides them.
194
+ setIsTransitioning(true);
195
+ setActiveTheme({ colors: getColors(name), name });
196
+ // Wait for React to commit the new theme under the still-opaque overlay.
197
+ await waitFrames(1);
198
+ if (!mountedRef.current)
199
+ return;
200
+ const finishTransition = () => {
201
+ if (!mountedRef.current)
202
+ return;
203
+ resetTransition();
204
+ safeCall('config onTransitionEnd', configOnTransitionEnd, name);
205
+ safeCall('per-call onTransitionEnd', options?.onTransitionEnd, name);
206
+ safeCall('config onThemeChange', onThemeChange, name);
207
+ // Reconcile: if the OS appearance changed while the transition was
208
+ // running (stored in pendingSchemeRef by the listener), apply it now.
209
+ if (systemModeRef.current && pendingSchemeRef.current !== null) {
210
+ const resolved = mapSchemeToTheme(pendingSchemeRef.current, systemThemeMap);
211
+ pendingSchemeRef.current = null;
212
+ if (resolved in themes && resolved !== name) {
213
+ targetThemeRef.current = resolved;
214
+ setActiveTheme({ colors: getColors(resolved), name: resolved });
215
+ safeCall('config onThemeChange', onThemeChange, resolved);
216
+ }
217
+ }
218
+ };
219
+ overlayOpacity.set(withTiming(0, { duration }, (finished) => {
220
+ 'worklet';
221
+ if (finished)
222
+ scheduleOnRN(finishTransition);
223
+ }));
224
+ }
225
+ catch (error) {
226
+ // If capture fails, apply theme instantly — no animation beats a stuck overlay.
227
+ console.warn(`${TAG} Failed to capture screenshot. Falling back to instant theme switch.`, error);
228
+ if (!mountedRef.current)
229
+ return;
230
+ setActiveTheme({ colors: getColors(name), name });
231
+ overlayOpacity.set(0);
232
+ resetTransition();
233
+ safeCall('config onThemeChange', onThemeChange, name);
234
+ }
235
+ }, [overlayOpacity, resetTransition]);
236
+ const setTheme = useCallback((name, options) => {
237
+ // When transitioning from manual to system mode, Android's getColorScheme()
238
+ // returns stale values synchronously after setColorScheme('unspecified').
239
+ // Clear the override and defer resolution by one frame so native settles.
240
+ if (name === 'system' && !systemModeRef.current) {
241
+ if (transitioningRef.current)
242
+ return false;
243
+ // Don't set systemModeRef yet — while it's false the Appearance
244
+ // listener guard (`!systemModeRef.current`) naturally ignores
245
+ // stale events Android fires after setColorScheme('unspecified').
246
+ setIsSystemMode(true);
247
+ Appearance.setColorScheme('unspecified');
248
+ requestAnimationFrame(() => {
249
+ if (!mountedRef.current)
250
+ return;
251
+ systemModeRef.current = true;
252
+ setTheme('system', options);
253
+ });
254
+ return true;
255
+ }
256
+ const resolvedTheme = name === 'system'
257
+ // When Android returns 'unspecified' (override matched OS, no config change),
258
+ // infer the OS scheme from the current theme's darkness classification.
259
+ ? resolveSystemTheme(systemThemeMap, schemeOf(targetThemeRef.current))
260
+ : name;
261
+ if (!(resolvedTheme in themes)) {
262
+ const resolutionHint = name === 'system'
263
+ ? ' Provide `systemThemeMap` in the config to map OS appearance to your theme names.'
264
+ : '';
265
+ throw new Error(`${TAG} setTheme("${name}") resolved to "${resolvedTheme}" which does not exist in themes.${resolutionHint}`);
266
+ }
267
+ if (transitioningRef.current)
268
+ return false;
269
+ // Set system mode AFTER the transition guard so a rejected call during an ongoing
270
+ // transition doesn't silently activate system-following mode.
271
+ const wasSystemMode = systemModeRef.current;
272
+ systemModeRef.current = name === 'system';
273
+ // Sync state so the Appearance.setColorScheme effect re-runs.
274
+ if (systemModeRef.current !== wasSystemMode) {
275
+ setIsSystemMode(systemModeRef.current);
276
+ }
277
+ if (resolvedTheme === targetThemeRef.current) {
278
+ // Switching between manual and system mode is a valid change even when
279
+ // the resolved theme is the same — return true so select() keeps the
280
+ // new selection instead of reverting.
281
+ return wasSystemMode !== systemModeRef.current;
282
+ }
283
+ targetThemeRef.current = resolvedTheme;
284
+ if (options?.animated === false) {
285
+ setActiveTheme({ colors: getColors(resolvedTheme), name: resolvedTheme });
286
+ safeCall('config onThemeChange', onThemeChange, resolvedTheme);
287
+ return true;
288
+ }
289
+ // Block touches and mark as transitioning BEFORE firing user callbacks to prevent
290
+ // re-entrant setTheme calls from starting a concurrent transition.
291
+ transitioningRef.current = true;
292
+ isBlocking.value = true;
293
+ try {
294
+ configOnTransitionStart?.(resolvedTheme);
295
+ options?.onTransitionStart?.(resolvedTheme);
296
+ }
297
+ catch (e) {
298
+ // Reset guards so a callback error doesn't permanently block transitions.
299
+ resetTransition();
300
+ throw e;
301
+ }
302
+ // isTransitioning is set inside runTransition(), AFTER captureRef, so no React
303
+ // re-render can alter the native view before the screenshot is taken.
304
+ runTransition(resolvedTheme, options).catch(() => { });
305
+ return true;
306
+ }, [isBlocking, resetTransition, runTransition]);
307
+ useEffect(() => {
308
+ const appearanceSub = Appearance.addChangeListener(({ colorScheme }) => {
309
+ if (!systemModeRef.current)
310
+ return;
311
+ if (transitioningRef.current) {
312
+ // Can't start a new transition now; store for reconciliation.
313
+ pendingSchemeRef.current = normalizeScheme(colorScheme);
314
+ return;
315
+ }
316
+ if (appStateRef.current === 'active') {
317
+ setTheme('system');
318
+ }
319
+ else {
320
+ // Background: apply directly (works on Android where JS keeps running).
321
+ // On iOS the JS thread is suspended so this commit may be deferred —
322
+ // the AppState handler below re-applies on foreground return as a safety net.
323
+ const resolved = mapSchemeToTheme(normalizeScheme(colorScheme), systemThemeMap);
324
+ if (!(resolved in themes) || resolved === targetThemeRef.current)
325
+ return;
326
+ targetThemeRef.current = resolved;
327
+ setActiveTheme({ colors: getColors(resolved), name: resolved });
328
+ safeCall('config onThemeChange', onThemeChange, resolved);
329
+ }
330
+ });
331
+ // Re-read OS scheme on foreground return. Catches two cases:
332
+ // 1. iOS never delivered Appearance events while suspended.
333
+ // 2. The BG setActiveTheme commit was deferred by iOS suspension.
334
+ const appSub = AppState.addEventListener('change', (next) => {
335
+ if (appStateRef.current !== 'active' && next === 'active' && systemModeRef.current) {
336
+ // Re-read OS scheme and force setActiveTheme. Even if the BG path
337
+ // already set targetThemeRef, iOS may have deferred the React commit.
338
+ // Calling setActiveTheme again guarantees an immediate commit now
339
+ // that the app is active.
340
+ const resolved = resolveSystemTheme(systemThemeMap, schemeOf(targetThemeRef.current));
341
+ if (resolved in themes) {
342
+ const changed = resolved !== targetThemeRef.current;
343
+ targetThemeRef.current = resolved;
344
+ setActiveTheme({ colors: getColors(resolved), name: resolved });
345
+ if (changed)
346
+ safeCall('config onThemeChange', onThemeChange, resolved);
347
+ }
348
+ }
349
+ appStateRef.current = next;
350
+ });
351
+ return () => {
352
+ appearanceSub.remove();
353
+ appSub.remove();
354
+ };
355
+ }, [setTheme]);
356
+ const contextValue = useMemo(() => ({
357
+ colors: activeTheme.colors, name: activeTheme.name, setTheme, isTransitioning,
358
+ }), [activeTheme, setTheme, isTransitioning]);
359
+ return (_jsx(Context.Provider, { value: contextValue, children: _jsxs(View, { ref: rootRef, style: ROOT_STYLE, collapsable: false, children: [children, _jsx(Animated.View, { style: ABSOLUTE_FILL, animatedProps: blockerProps }), _jsx(Animated.View, { style: [ABSOLUTE_FILL, overlayStyle], pointerEvents: "none", children: overlayUri != null ? (_jsx(Image, { source: overlaySource, style: ABSOLUTE_FILL, resizeMode: "cover", fadeDuration: 0, onLoad: onOverlayLoad, onError: onOverlayError })) : null })] }) }));
360
+ }
361
+ return { Context, ThemeTransitionProvider };
362
+ }
363
+ //# sourceMappingURL=transitionEngine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transitionEngine.js","sourceRoot":"","sources":["../src/transitionEngine.tsx"],"names":[],"mappings":";AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACzF,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,QAAQ,EAAE,EACf,gBAAgB,EAChB,cAAc,EACd,UAAU,GACX,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAUrD,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,MAAM,aAAa,GAAG,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,E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,EAAE,WAAW,CAAC,MAAM,EAAE,IAAI,EAAE,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,eAAe;SAC9E,CAAC,EAAE,CAAC,WAAW,EAAE,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAC;QAE9C,OAAO,CACL,KAAC,OAAO,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,YAEnC,MAAC,IAAI,IAAC,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,KAAK,aACtD,QAAQ,EACT,KAAC,QAAQ,CAAC,IAAI,IAAC,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,YAAY,GAAI,EAEpE,KAAC,QAAQ,CAAC,IAAI,IAAC,KAAK,EAAE,CAAC,aAAa,EAAE,YAAY,CAAC,EAAE,aAAa,EAAC,MAAM,YACtE,UAAU,IAAI,IAAI,CAAC,CAAC,CAAC,CACpB,KAAC,KAAK,IAAC,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,aAAa,EAAE,UAAU,EAAC,OAAO,EAAC,YAAY,EAAE,CAAC,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,cAAc,GAAI,CAC3I,CAAC,CAAC,CAAC,IAAI,GACM,IACX,GACU,CACpB,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,uBAAuB,EAAE,CAAC;AAC9C,CAAC"}
@@ -0,0 +1,284 @@
1
+ /**
2
+ * Map of theme token names to color values.
3
+ *
4
+ * @remarks
5
+ * Each theme is a flat record where keys are token names (e.g. `"background"`,
6
+ * `"textPrimary"`) and values are color strings accepted by React Native
7
+ * (hex, rgb, rgba, named colors).
8
+ */
9
+ export type ThemeDefinition = Record<string, string>;
10
+ /**
11
+ * Union of theme names available in a theme configuration.
12
+ *
13
+ * @typeParam T - Your application's theme map, keyed by theme name.
14
+ */
15
+ export type ThemeNames<T extends Record<string, ThemeDefinition>> = keyof T & string;
16
+ /**
17
+ * Union of token names shared across all themes in a configuration.
18
+ *
19
+ * @typeParam T - Your application's theme map, keyed by theme name.
20
+ */
21
+ export type TokenNames<T extends Record<string, ThemeDefinition>> = keyof T[ThemeNames<T>] & string;
22
+ /**
23
+ * Maps OS color schemes (`'light'` / `'dark'`) to theme names.
24
+ *
25
+ * @remarks
26
+ * Required when your themes are not named `'light'` and `'dark'`.
27
+ * Both keys must be provided.
28
+ *
29
+ * @typeParam Names - Union of theme name strings.
30
+ */
31
+ export type SystemThemeMap<Names extends string> = Record<'light' | 'dark', Names>;
32
+ /**
33
+ * Configuration for {@link createThemeTransition}.
34
+ *
35
+ * @typeParam T - Your application's theme map, keyed by theme name.
36
+ */
37
+ export interface ThemeTransitionConfig<T extends Record<string, ThemeDefinition>> {
38
+ /**
39
+ * All available themes keyed by name.
40
+ *
41
+ * @remarks
42
+ * Every theme must share the exact same token keys. Mismatched keys
43
+ * cause a runtime error at initialization.
44
+ * The name `'system'` is reserved and cannot be used as a theme name.
45
+ */
46
+ themes: T;
47
+ /**
48
+ * Cross-fade duration in milliseconds.
49
+ * @default 350
50
+ */
51
+ duration?: number;
52
+ /**
53
+ * Maps OS appearance (`'light'` / `'dark'`) to theme names.
54
+ *
55
+ * @remarks
56
+ * Required when your themes are not named `'light'` and `'dark'`
57
+ * and you want to use `initialTheme="system"` or `setTheme('system')`.
58
+ * Both `light` and `dark` must be provided.
59
+ */
60
+ systemThemeMap?: SystemThemeMap<ThemeNames<T>>;
61
+ /**
62
+ * Theme names that use a dark color scheme.
63
+ *
64
+ * @remarks
65
+ * The library automatically calls `Appearance.setColorScheme` to keep
66
+ * native UI elements (alerts, date pickers, keyboards) in sync with
67
+ * the active theme. Themes listed here get `'dark'`; all others get `'light'`.
68
+ * In system mode, `'unspecified'` is used so the OS drives the appearance.
69
+ *
70
+ * **Do not call `Appearance.setColorScheme` yourself** — the library manages
71
+ * it internally. Calling it manually can corrupt state on Android.
72
+ *
73
+ * @default `[systemThemeMap.dark]` if `systemThemeMap` is provided, otherwise `['dark']`.
74
+ */
75
+ darkThemes?: ThemeNames<T>[];
76
+ /**
77
+ * Called when an animated transition begins, before the screenshot capture.
78
+ *
79
+ * @remarks
80
+ * Fires for all animated transitions, including system-driven ones.
81
+ * Does not fire for instant switches (`animated: false`).
82
+ *
83
+ * @param themeName - The target theme name.
84
+ */
85
+ onTransitionStart?: (themeName: ThemeNames<T>) => void;
86
+ /**
87
+ * Called after an animated transition completes and the overlay is removed.
88
+ *
89
+ * @remarks
90
+ * Fires for all animated transitions, including system-driven ones.
91
+ * Does not fire for instant switches (`animated: false`).
92
+ *
93
+ * Not called if the screenshot capture fails mid-transition, even when
94
+ * `onTransitionStart` has already fired. In that case the library falls back to an
95
+ * instant switch and only `onThemeChange` fires. Design `onTransitionStart` handlers
96
+ * to be resilient to a missing matching `onTransitionEnd`.
97
+ *
98
+ * @param themeName - The newly active theme name.
99
+ */
100
+ onTransitionEnd?: (themeName: ThemeNames<T>) => void;
101
+ /**
102
+ * Called whenever the active theme changes.
103
+ *
104
+ * @remarks
105
+ * Fires for all theme changes: animated transitions, instant switches,
106
+ * and system-driven appearance changes. For animated transitions,
107
+ * fires after `onTransitionEnd`.
108
+ *
109
+ * @param themeName - The newly active theme name.
110
+ */
111
+ onThemeChange?: (themeName: ThemeNames<T>) => void;
112
+ }
113
+ /**
114
+ * Options for {@link ThemeTransitionAPI.useTheme | setTheme}.
115
+ *
116
+ * @typeParam Names - Union of theme name strings.
117
+ */
118
+ export interface SetThemeOptions<Names extends string = string> {
119
+ /**
120
+ * Whether to use the screenshot-overlay cross-fade animation.
121
+ *
122
+ * @remarks
123
+ * When `false`, the theme switches instantly without capturing a screenshot
124
+ * or showing an overlay.
125
+ *
126
+ * @default true
127
+ */
128
+ animated?: boolean;
129
+ /**
130
+ * Called when the animated transition begins, before the screenshot capture.
131
+ *
132
+ * @remarks
133
+ * Only called when `animated` is `true` (the default).
134
+ * Fires after the config-level `onTransitionStart` (if provided).
135
+ *
136
+ * @param themeName - The target theme name.
137
+ */
138
+ onTransitionStart?: (themeName: Names) => void;
139
+ /**
140
+ * Called after the animated transition completes and the overlay is removed.
141
+ *
142
+ * @remarks
143
+ * Only called when `animated` is `true` (the default).
144
+ * Fires after the config-level `onTransitionEnd` (if provided).
145
+ *
146
+ * Not called if the screenshot capture fails mid-transition, even when
147
+ * `onTransitionStart` has already fired. In that case the library falls back to an
148
+ * instant switch and only `onThemeChange` fires.
149
+ *
150
+ * @param themeName - The newly active theme name.
151
+ */
152
+ onTransitionEnd?: (themeName: Names) => void;
153
+ }
154
+ /**
155
+ * Base return type of the {@link ThemeTransitionAPI.useTheme | useTheme} hook.
156
+ *
157
+ * @typeParam Tokens - Union of token name strings.
158
+ * @typeParam Names - Union of theme name strings.
159
+ */
160
+ export interface UseThemeResult<Tokens extends string, Names extends string> {
161
+ /** Current resolved color values for all tokens. */
162
+ colors: Record<Tokens, string>;
163
+ /** Name of the currently active theme (resolved, never `'system'`). */
164
+ name: Names;
165
+ /**
166
+ * Switch to a new theme or enter system mode.
167
+ *
168
+ * @param name - Target theme name or `'system'`.
169
+ * @param options - Optional transition configuration.
170
+ * @returns `true` if the theme change was accepted, `false` if rejected
171
+ * (already transitioning or same theme).
172
+ */
173
+ setTheme: (name: Names | 'system', options?: SetThemeOptions<Names>) => boolean;
174
+ /** `true` while a cross-fade transition overlay is visible. */
175
+ isTransitioning: boolean;
176
+ }
177
+ /**
178
+ * Selection state returned by {@link ThemeTransitionAPI.useTheme | useTheme}
179
+ * when called with `{ initialSelection }`.
180
+ *
181
+ * @typeParam Names - Union of theme name strings.
182
+ */
183
+ export interface ThemeSelectionResult<Names extends string> {
184
+ /** The currently selected option (may be `'system'`). */
185
+ selected: Names | 'system';
186
+ /**
187
+ * Select a theme with transition-safe timing.
188
+ *
189
+ * @remarks
190
+ * Updates the selection highlight immediately, then defers `setTheme`
191
+ * to the next animation frame so the selection is painted before
192
+ * the library captures the screenshot. Rapid presses during an
193
+ * ongoing transition are silently ignored.
194
+ *
195
+ * @param option - Theme name or `'system'`.
196
+ */
197
+ select: (option: Names | 'system') => void;
198
+ }
199
+ /**
200
+ * Public API returned by {@link createThemeTransition}.
201
+ *
202
+ * @typeParam T - Your application's theme map, keyed by theme name.
203
+ */
204
+ export interface ThemeTransitionAPI<T extends Record<string, ThemeDefinition>> {
205
+ /**
206
+ * Provider that supplies animated theme colors via context.
207
+ *
208
+ * @remarks
209
+ * Place this as high as possible in the component tree (ideally wrapping
210
+ * navigation) so the screenshot can capture the entire screen.
211
+ */
212
+ ThemeTransitionProvider: React.FC<{
213
+ children: React.ReactNode;
214
+ /**
215
+ * Theme to render on the first frame.
216
+ *
217
+ * @remarks
218
+ * Pass `'system'` to read the OS appearance synchronously (zero-flash)
219
+ * and subscribe to changes. For custom theme names, provide
220
+ * {@link ThemeTransitionConfig.systemThemeMap | systemThemeMap} in the config.
221
+ */
222
+ initialTheme: ThemeNames<T> | 'system';
223
+ }>;
224
+ /**
225
+ * Hook returning the current theme state and transition controls.
226
+ *
227
+ * @remarks
228
+ * **Without arguments** — returns theme colors, name, `setTheme`, and
229
+ * `isTransitioning`. Use this in any component that reads or changes the theme.
230
+ *
231
+ * **With `{ initialSelection }`** — also returns `selected` and `select` for
232
+ * building theme selection UIs (button groups, toggles, checkmark lists) with
233
+ * transition-safe timing. On iOS (especially 120Hz ProMotion), calling
234
+ * `setTheme` synchronously after a UI state update can cause the screenshot
235
+ * to capture the old state, producing visible flickering. The `select`
236
+ * function handles this automatically by deferring `setTheme` to the next
237
+ * animation frame.
238
+ *
239
+ * `initialSelection` sets the starting value of `selected` (read once, like
240
+ * `useState`). When omitted, defaults to the current theme name from context.
241
+ *
242
+ * @throws If called outside a `ThemeTransitionProvider`.
243
+ *
244
+ * @example
245
+ * ```tsx
246
+ * // Reading theme colors in any component
247
+ * const { colors, name } = useTheme();
248
+ * ```
249
+ *
250
+ * @example
251
+ * ```tsx
252
+ * // Building a theme selection UI
253
+ * function ThemePicker() {
254
+ * const { selected, select, colors, isTransitioning } = useTheme({ initialSelection: 'system' });
255
+ * return (
256
+ * <View style={{ flexDirection: 'row', gap: 8 }}>
257
+ * {(['system', 'light', 'dark'] as const).map((option) => (
258
+ * <Pressable
259
+ * key={option}
260
+ * onPress={() => select(option)}
261
+ * disabled={isTransitioning}
262
+ * style={{ backgroundColor: option === selected ? colors.primary : 'transparent' }}
263
+ * >
264
+ * <Text>{option}</Text>
265
+ * </Pressable>
266
+ * ))}
267
+ * </View>
268
+ * );
269
+ * }
270
+ * ```
271
+ */
272
+ useTheme: {
273
+ /** Returns current theme state and controls. */
274
+ (): UseThemeResult<TokenNames<T>, ThemeNames<T>>;
275
+ /**
276
+ * Returns theme state, controls, and selection tracking with transition-safe timing.
277
+ * @param options.initialSelection - Starting value for `selected`. Defaults to the current theme name.
278
+ */
279
+ (options: {
280
+ initialSelection?: ThemeNames<T> | 'system';
281
+ }): UseThemeResult<TokenNames<T>, ThemeNames<T>> & ThemeSelectionResult<ThemeNames<T>>;
282
+ };
283
+ }
284
+ //# sourceMappingURL=types.d.ts.map