react-native-theme-transition 1.0.3 → 1.0.4

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.
@@ -1 +1 @@
1
- {"version":3,"file":"useTheme.d.ts","sourceRoot":"","sources":["../../src/hooks/useTheme.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AACrC,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACpB,eAAe,EACf,UAAU,EACV,UAAU,EACX,MAAM,UAAU,CAAC;AAGlB;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,EACtE,GAAG,EAAE,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;;cAQtC;QAAE,gBAAgB,CAAC,EAAE,gBAAQ,QAAQ,CAAA;KAAE;EA8DnE"}
1
+ {"version":3,"file":"useTheme.d.ts","sourceRoot":"","sources":["../../src/hooks/useTheme.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AACrC,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACpB,eAAe,EACf,UAAU,EACV,UAAU,EACX,MAAM,UAAU,CAAC;AAGlB;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,EACtE,GAAG,EAAE,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;;cAQtC;QAAE,gBAAgB,CAAC,EAAE,gBAAQ,QAAQ,CAAA;KAAE;EAmDnE"}
@@ -12,12 +12,10 @@ export function createUseTheme(Ctx) {
12
12
  throw new Error(`${TAG} \`useTheme\` must be used inside a \`ThemeTransitionProvider\`.`);
13
13
  }
14
14
  const { setTheme, isTransitioning } = ctx;
15
- // Selection state — hooks are always called to satisfy React's rules of hooks.
16
- // Only exposed in the return value when options are provided.
15
+ // Always called (rules of hooks) — only exposed when options are provided.
17
16
  const [selected, setSelected] = useState(() => options?.initialSelection ?? ctx.name);
18
17
  const pressLockRef = useRef(false);
19
- // Ref tracks latest `selected` so the callback can read it without
20
- // `selected` being a dependency — avoids recreating `select` on every change.
18
+ // Ref avoids `selected` as a dependency — keeps `select` stable across renders.
21
19
  const selectedRef = useRef(selected);
22
20
  selectedRef.current = selected;
23
21
  useEffect(() => {
@@ -29,22 +27,14 @@ export function createUseTheme(Ctx) {
29
27
  return;
30
28
  pressLockRef.current = true;
31
29
  const previousSelected = selectedRef.current;
32
- // Paint the new highlight FIRST. Deferring setTheme to the next frame
33
- // guarantees React commits + native paint before the library captures.
30
+ // Paint highlight first — deferred setTheme lets React commit before capture.
34
31
  setSelected(option);
35
32
  requestAnimationFrame(() => {
36
- if (!setTheme(option)) {
37
- // Rejected (same theme or already transitioning) — restore the prior selection.
33
+ if (!setTheme(option))
38
34
  setSelected(previousSelected);
39
- }
40
- // Always release: the blocker view (isBlocking) handles touch
41
- // prevention during transitions at the native level.
42
35
  pressLockRef.current = false;
43
36
  });
44
37
  }, [setTheme]);
45
- // Memoize the extended result so consumers using selection tracking
46
- // don't get a new object reference on every render (which would defeat
47
- // the context-level useMemo in the provider).
48
38
  const selectionResult = useMemo(() => ({ ...ctx, selected, select }), [ctx, selected, select]);
49
39
  if (options != null) {
50
40
  return selectionResult;
@@ -1 +1 @@
1
- {"version":3,"file":"useTheme.js","sourceRoot":"","sources":["../../src/hooks/useTheme.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAStF,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAEnC;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,MAAM,CAAC,KAAK,CAAC,CAAC;QACnC,gFAAgF;QAChF,MAAM,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;QACrC,WAAW,CAAC,OAAO,GAAG,QAAQ,CAAC;QAE/B,SAAS,CAAC,GAAG,EAAE;YACb,IAAI,CAAC,eAAe;gBAAE,YAAY,CAAC,OAAO,GAAG,KAAK,CAAC;QACrD,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC;QAEtB,MAAM,MAAM,GAAG,WAAW,CACxB,CAAC,MAAwB,EAAE,EAAE;YAC3B,IAAI,YAAY,CAAC,OAAO;gBAAE,OAAO;YACjC,YAAY,CAAC,OAAO,GAAG,IAAI,CAAC;YAC5B,MAAM,gBAAgB,GAAG,WAAW,CAAC,OAAO,CAAC;YAC7C,8EAA8E;YAC9E,WAAW,CAAC,MAAM,CAAC,CAAC;YACpB,qBAAqB,CAAC,GAAG,EAAE;gBACzB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;oBAAE,WAAW,CAAC,gBAAgB,CAAC,CAAC;gBACrD,YAAY,CAAC,OAAO,GAAG,KAAK,CAAC;YAC/B,CAAC,CAAC,CAAC;QACL,CAAC,EACD,CAAC,QAAQ,CAAC,CACX,CAAC;QAEF,MAAM,eAAe,GAAG,OAAO,CAC7B,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,EACpC,CAAC,GAAG,EAAE,QAAQ,EAAE,MAAM,CAAC,CACxB,CAAC;QAEF,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;YACpB,OAAO,eAAe,CAAC;QACzB,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -1,6 +1,11 @@
1
1
  /**
2
2
  * Screenshot-overlay transition engine and provider.
3
3
  *
4
+ * @remarks
5
+ * View hierarchy: content root → shared-value touch blocker → animated overlay
6
+ * with decoded screenshot `Image`. The overlay is always mounted (no mount-time
7
+ * race with the shared opacity value); only the `Image` inside is conditional.
8
+ *
4
9
  * @module
5
10
  */
6
11
  import type { ThemeTransitionConfig, UseThemeResult, ThemeDefinition, ThemeNames, TokenNames } from './types';
@@ -1 +1 @@
1
- {"version":3,"file":"transitionEngine.d.ts","sourceRoot":"","sources":["../src/transitionEngine.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAWH,OAAO,KAAK,EACV,qBAAqB,EACrB,cAAc,EAGd,eAAe,EACf,UAAU,EACV,UAAU,EACX,MAAM,SAAS,CAAC;AAqFjB;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,EACzC,MAAM,EAAE,qBAAqB,CAAC,CAAC,CAAC;;2DA0B7B;QACD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;QAC1B,YAAY,EAAE,gBAAQ,QAAQ,CAAC;KAChC;EA4SF"}
1
+ {"version":3,"file":"transitionEngine.d.ts","sourceRoot":"","sources":["../src/transitionEngine.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAWH,OAAO,KAAK,EACV,qBAAqB,EACrB,cAAc,EAGd,eAAe,EACf,UAAU,EACV,UAAU,EACX,MAAM,SAAS,CAAC;AAqFjB;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,EACzC,MAAM,EAAE,qBAAqB,CAAC,CAAC,CAAC;;2DA0B7B;QACD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;QAC1B,YAAY,EAAE,gBAAQ,QAAQ,CAAC;KAChC;EA4TF"}
@@ -2,6 +2,11 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  /**
3
3
  * Screenshot-overlay transition engine and provider.
4
4
  *
5
+ * @remarks
6
+ * View hierarchy: content root → shared-value touch blocker → animated overlay
7
+ * with decoded screenshot `Image`. The overlay is always mounted (no mount-time
8
+ * race with the shared opacity value); only the `Image` inside is conditional.
9
+ *
5
10
  * @module
6
11
  */
7
12
  import { createContext, useCallback, useEffect, useMemo, useRef, useState } from 'react';
@@ -120,13 +125,19 @@ export function createProviderAndContext(config) {
120
125
  const mountedRef = useRef(true);
121
126
  const [isTransitioning, setIsTransitioning] = useState(false);
122
127
  const systemModeRef = useRef(initialTheme === 'system');
123
- // State mirror of systemModeRef — triggers the Appearance.setColorScheme effect.
128
+ // State mirror of systemModeRef — drives the Appearance.setColorScheme effect.
124
129
  const [isSystemMode, setIsSystemMode] = useState(initialTheme === 'system');
125
130
  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.
131
+ // Pending OS scheme change that arrived mid-transition. Applied by finishTransition.
128
132
  const pendingSchemeRef = useRef(null);
129
- // Blocks touches within one native frame, without waiting for a React re-render.
133
+ // Last observed OS scheme — lets manual→system resolve without calling
134
+ // setColorScheme('unspecified') (which flashes the Android status bar).
135
+ const lastKnownOsSchemeRef = useRef(normalizeScheme(Appearance.getColorScheme()));
136
+ // Manual override scheme while a deferred setColorScheme('unspecified') is pending.
137
+ // finishTransition uses this to correct the theme if the OS scheme diverged.
138
+ const deferredSystemRestoreRef = useRef(null);
139
+ // SharedValue (not state) so touch blocking takes effect on the native thread
140
+ // within one frame, without waiting for a React re-render cycle.
130
141
  const isBlocking = useSharedValue(false);
131
142
  const blockerProps = useAnimatedProps(() => ({
132
143
  pointerEvents: isBlocking.value ? 'auto' : 'none',
@@ -134,9 +145,8 @@ export function createProviderAndContext(config) {
134
145
  // State (not ref) so unsetting it unmounts the Image, freeing the captured bitmap.
135
146
  const [overlayUri, setOverlayUri] = useState(null);
136
147
  const overlayOpacity = useSharedValue(0);
137
- // Stable reference prevents Reanimated from re-processing the style on React re-renders.
148
+ // Stable ref so Reanimated doesn't re-process the style on every render.
138
149
  const overlayStyle = useMemo(() => ({ opacity: overlayOpacity }), [overlayOpacity]);
139
- // Settled when the overlay Image fires onLoad (resolve) or onError (reject).
140
150
  const overlayDecodeRef = useRef(null);
141
151
  const overlaySource = useMemo(() => overlayUri ? { uri: overlayUri } : undefined, [overlayUri]);
142
152
  const onOverlayLoad = useCallback(() => {
@@ -151,9 +161,8 @@ export function createProviderAndContext(config) {
151
161
  mountedRef.current = false;
152
162
  };
153
163
  }, []);
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).
164
+ // Sync native UI (alerts, keyboards) with theme. Skipped in system mode
165
+ // where the OS drives appearance via 'unspecified'.
157
166
  useEffect(() => {
158
167
  if (isSystemMode)
159
168
  return;
@@ -167,15 +176,15 @@ export function createProviderAndContext(config) {
167
176
  setIsTransitioning(false);
168
177
  setOverlayUri(null);
169
178
  }, [isBlocking]);
170
- const runTransition = useCallback(async (name, options) => {
179
+ const runTransition = useCallback(async (initialName, options) => {
180
+ let name = initialName;
171
181
  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.
182
+ // 2 frames for JS → Shadow Tree → Native UI to paint before capture.
183
+ // useTheme's requestAnimationFrame adds a 3rd — enough for 120Hz.
176
184
  await waitFrames(2);
177
185
  if (!mountedRef.current)
178
186
  return;
187
+ // jpg 0.8: ~30% smaller than png, no visible degradation during a cross-fade.
179
188
  const uri = await captureRef(rootRef, { format: 'jpg', quality: 0.8 });
180
189
  if (!mountedRef.current)
181
190
  return;
@@ -189,11 +198,44 @@ export function createProviderAndContext(config) {
189
198
  await waitFrames(1);
190
199
  if (!mountedRef.current)
191
200
  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.
201
+ // Deferred: setting this earlier would re-render under the overlay,
202
+ // flashing state-dependent visuals before the screenshot hides them.
194
203
  setIsTransitioning(true);
195
204
  setActiveTheme({ colors: getColors(name), name });
196
- // Wait for React to commit the new theme under the still-opaque overlay.
205
+ // Deferred setColorScheme('unspecified') — done now while the overlay is
206
+ // opaque so any theme correction (OS scheme diverged) is invisible to the user.
207
+ if (deferredSystemRestoreRef.current !== null) {
208
+ const manualScheme = deferredSystemRestoreRef.current;
209
+ let resolved = false;
210
+ const realScheme = await new Promise((resolve) => {
211
+ const sub = Appearance.addChangeListener(({ colorScheme }) => {
212
+ if (resolved)
213
+ return;
214
+ resolved = true;
215
+ sub.remove();
216
+ resolve(normalizeScheme(colorScheme));
217
+ });
218
+ Appearance.setColorScheme('unspecified');
219
+ // No event → OS scheme already matches the manual override.
220
+ requestAnimationFrame(() => {
221
+ if (resolved)
222
+ return;
223
+ resolved = true;
224
+ sub.remove();
225
+ resolve(manualScheme);
226
+ });
227
+ });
228
+ if (!mountedRef.current)
229
+ return;
230
+ deferredSystemRestoreRef.current = null;
231
+ lastKnownOsSchemeRef.current = realScheme;
232
+ const corrected = mapSchemeToTheme(realScheme, systemThemeMap);
233
+ if (corrected in themes && corrected !== name) {
234
+ name = corrected;
235
+ targetThemeRef.current = corrected;
236
+ setActiveTheme({ colors: getColors(corrected), name: corrected });
237
+ }
238
+ }
197
239
  await waitFrames(1);
198
240
  if (!mountedRef.current)
199
241
  return;
@@ -204,8 +246,7 @@ export function createProviderAndContext(config) {
204
246
  safeCall('config onTransitionEnd', configOnTransitionEnd, name);
205
247
  safeCall('per-call onTransitionEnd', options?.onTransitionEnd, name);
206
248
  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.
249
+ // Apply any OS scheme change that arrived mid-transition.
209
250
  if (systemModeRef.current && pendingSchemeRef.current !== null) {
210
251
  const resolved = mapSchemeToTheme(pendingSchemeRef.current, systemThemeMap);
211
252
  pendingSchemeRef.current = null;
@@ -234,29 +275,18 @@ export function createProviderAndContext(config) {
234
275
  }
235
276
  }, [overlayOpacity, resetTransition]);
236
277
  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.
278
+ // Manual→system: resolve from cached OS scheme to avoid the Android
279
+ // status bar flash that setColorScheme('unspecified') causes pre-overlay.
240
280
  if (name === 'system' && !systemModeRef.current) {
241
281
  if (transitioningRef.current)
242
282
  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
283
  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;
284
+ systemModeRef.current = true;
285
+ deferredSystemRestoreRef.current = schemeOf(targetThemeRef.current);
286
+ return setTheme('system', options);
255
287
  }
256
288
  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))
289
+ ? mapSchemeToTheme(lastKnownOsSchemeRef.current, systemThemeMap)
260
290
  : name;
261
291
  if (!(resolvedTheme in themes)) {
262
292
  const resolutionHint = name === 'system'
@@ -266,18 +296,15 @@ export function createProviderAndContext(config) {
266
296
  }
267
297
  if (transitioningRef.current)
268
298
  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.
299
+ // After transition guard — a rejected call must not activate system mode.
271
300
  const wasSystemMode = systemModeRef.current;
272
301
  systemModeRef.current = name === 'system';
273
- // Sync state so the Appearance.setColorScheme effect re-runs.
274
302
  if (systemModeRef.current !== wasSystemMode) {
275
303
  setIsSystemMode(systemModeRef.current);
276
304
  }
277
305
  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.
306
+ // Manual↔system mode switch is valid even when the resolved theme matches —
307
+ // returning true prevents select() from reverting the user's selection.
281
308
  return wasSystemMode !== systemModeRef.current;
282
309
  }
283
310
  targetThemeRef.current = resolvedTheme;
@@ -286,8 +313,7 @@ export function createProviderAndContext(config) {
286
313
  safeCall('config onThemeChange', onThemeChange, resolvedTheme);
287
314
  return true;
288
315
  }
289
- // Block touches and mark as transitioning BEFORE firing user callbacks to prevent
290
- // re-entrant setTheme calls from starting a concurrent transition.
316
+ // Block before user callbacks to prevent re-entrant setTheme.
291
317
  transitioningRef.current = true;
292
318
  isBlocking.value = true;
293
319
  try {
@@ -299,8 +325,6 @@ export function createProviderAndContext(config) {
299
325
  resetTransition();
300
326
  throw e;
301
327
  }
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
328
  runTransition(resolvedTheme, options).catch(() => { });
305
329
  return true;
306
330
  }, [isBlocking, resetTransition, runTransition]);
@@ -308,8 +332,11 @@ export function createProviderAndContext(config) {
308
332
  const appearanceSub = Appearance.addChangeListener(({ colorScheme }) => {
309
333
  if (!systemModeRef.current)
310
334
  return;
335
+ lastKnownOsSchemeRef.current = normalizeScheme(colorScheme);
336
+ // Deferred restore listener in runTransition handles these.
337
+ if (deferredSystemRestoreRef.current !== null)
338
+ return;
311
339
  if (transitioningRef.current) {
312
- // Can't start a new transition now; store for reconciliation.
313
340
  pendingSchemeRef.current = normalizeScheme(colorScheme);
314
341
  return;
315
342
  }
@@ -317,9 +344,7 @@ export function createProviderAndContext(config) {
317
344
  setTheme('system');
318
345
  }
319
346
  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.
347
+ // Background: apply directly. iOS may defer — AppState handler re-applies on foreground.
323
348
  const resolved = mapSchemeToTheme(normalizeScheme(colorScheme), systemThemeMap);
324
349
  if (!(resolved in themes) || resolved === targetThemeRef.current)
325
350
  return;
@@ -328,15 +353,10 @@ export function createProviderAndContext(config) {
328
353
  safeCall('config onThemeChange', onThemeChange, resolved);
329
354
  }
330
355
  });
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.
356
+ // Re-read OS scheme on foreground return — iOS may not deliver
357
+ // Appearance events while suspended, or may defer the React commit.
334
358
  const appSub = AppState.addEventListener('change', (next) => {
335
359
  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
360
  const resolved = resolveSystemTheme(systemThemeMap, schemeOf(targetThemeRef.current));
341
361
  if (resolved in themes) {
342
362
  const changed = resolved !== targetThemeRef.current;
@@ -1 +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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HANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-theme-transition",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Smooth, animated theme and dark mode transitions for React Native. Expo Go compatible, powered by Reanimated.",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./dist/index.js",
@@ -34,14 +34,12 @@ export function createUseTheme<T extends Record<string, ThemeDefinition>>(
34
34
 
35
35
  const { setTheme, isTransitioning } = ctx;
36
36
 
37
- // Selection state — hooks are always called to satisfy React's rules of hooks.
38
- // Only exposed in the return value when options are provided.
37
+ // Always called (rules of hooks) — only exposed when options are provided.
39
38
  const [selected, setSelected] = useState<Names | 'system'>(
40
39
  () => options?.initialSelection ?? ctx.name,
41
40
  );
42
41
  const pressLockRef = useRef(false);
43
- // Ref tracks latest `selected` so the callback can read it without
44
- // `selected` being a dependency — avoids recreating `select` on every change.
42
+ // Ref avoids `selected` as a dependency — keeps `select` stable across renders.
45
43
  const selectedRef = useRef(selected);
46
44
  selectedRef.current = selected;
47
45
 
@@ -54,25 +52,16 @@ export function createUseTheme<T extends Record<string, ThemeDefinition>>(
54
52
  if (pressLockRef.current) return;
55
53
  pressLockRef.current = true;
56
54
  const previousSelected = selectedRef.current;
57
- // Paint the new highlight FIRST. Deferring setTheme to the next frame
58
- // guarantees React commits + native paint before the library captures.
55
+ // Paint highlight first — deferred setTheme lets React commit before capture.
59
56
  setSelected(option);
60
57
  requestAnimationFrame(() => {
61
- if (!setTheme(option)) {
62
- // Rejected (same theme or already transitioning) — restore the prior selection.
63
- setSelected(previousSelected);
64
- }
65
- // Always release: the blocker view (isBlocking) handles touch
66
- // prevention during transitions at the native level.
58
+ if (!setTheme(option)) setSelected(previousSelected);
67
59
  pressLockRef.current = false;
68
60
  });
69
61
  },
70
62
  [setTheme],
71
63
  );
72
64
 
73
- // Memoize the extended result so consumers using selection tracking
74
- // don't get a new object reference on every render (which would defeat
75
- // the context-level useMemo in the provider).
76
65
  const selectionResult = useMemo(
77
66
  () => ({ ...ctx, selected, select }),
78
67
  [ctx, selected, select],
@@ -1,6 +1,11 @@
1
1
  /**
2
2
  * Screenshot-overlay transition engine and provider.
3
3
  *
4
+ * @remarks
5
+ * View hierarchy: content root → shared-value touch blocker → animated overlay
6
+ * with decoded screenshot `Image`. The overlay is always mounted (no mount-time
7
+ * race with the shared opacity value); only the `Image` inside is conditional.
8
+ *
4
9
  * @module
5
10
  */
6
11
 
@@ -168,14 +173,22 @@ export function createProviderAndContext<
168
173
  const [isTransitioning, setIsTransitioning] = useState(false);
169
174
 
170
175
  const systemModeRef = useRef(initialTheme === 'system');
171
- // State mirror of systemModeRef — triggers the Appearance.setColorScheme effect.
176
+ // State mirror of systemModeRef — drives the Appearance.setColorScheme effect.
172
177
  const [isSystemMode, setIsSystemMode] = useState(initialTheme === 'system');
173
178
  const appStateRef = useRef(AppState.currentState);
174
- // Stores a pending OS scheme change that arrived while a transition was
175
- // running (and setTheme was rejected). Read by finishTransition.
179
+ // Pending OS scheme change that arrived mid-transition. Applied by finishTransition.
176
180
  const pendingSchemeRef = useRef<'light' | 'dark' | null>(null);
181
+ // Last observed OS scheme — lets manual→system resolve without calling
182
+ // setColorScheme('unspecified') (which flashes the Android status bar).
183
+ const lastKnownOsSchemeRef = useRef<'light' | 'dark'>(
184
+ normalizeScheme(Appearance.getColorScheme()),
185
+ );
186
+ // Manual override scheme while a deferred setColorScheme('unspecified') is pending.
187
+ // finishTransition uses this to correct the theme if the OS scheme diverged.
188
+ const deferredSystemRestoreRef = useRef<'light' | 'dark' | null>(null);
177
189
 
178
- // Blocks touches within one native frame, without waiting for a React re-render.
190
+ // SharedValue (not state) so touch blocking takes effect on the native thread
191
+ // within one frame, without waiting for a React re-render cycle.
179
192
  const isBlocking = useSharedValue(false);
180
193
  const blockerProps = useAnimatedProps(() => ({
181
194
  pointerEvents: isBlocking.value ? 'auto' as const : 'none' as const,
@@ -184,9 +197,8 @@ export function createProviderAndContext<
184
197
  // State (not ref) so unsetting it unmounts the Image, freeing the captured bitmap.
185
198
  const [overlayUri, setOverlayUri] = useState<string | null>(null);
186
199
  const overlayOpacity = useSharedValue(0);
187
- // Stable reference prevents Reanimated from re-processing the style on React re-renders.
200
+ // Stable ref so Reanimated doesn't re-process the style on every render.
188
201
  const overlayStyle = useMemo(() => ({ opacity: overlayOpacity }), [overlayOpacity]);
189
- // Settled when the overlay Image fires onLoad (resolve) or onError (reject).
190
202
  const overlayDecodeRef = useRef<{ resolve: () => void; reject: () => void } | null>(null);
191
203
  const overlaySource = useMemo(() => overlayUri ? { uri: overlayUri } : undefined, [overlayUri]);
192
204
  const onOverlayLoad = useCallback(() => {
@@ -203,9 +215,8 @@ export function createProviderAndContext<
203
215
  };
204
216
  }, []);
205
217
 
206
- // Keep native UI elements (alerts, date pickers, keyboards) in sync.
207
- // Only applies in manual mode — in system mode the OS drives native UI
208
- // via 'unspecified' (set once by setTheme when entering system mode).
218
+ // Sync native UI (alerts, keyboards) with theme. Skipped in system mode
219
+ // where the OS drives appearance via 'unspecified'.
209
220
  useEffect(() => {
210
221
  if (isSystemMode) return;
211
222
  if (isTransitioning) return;
@@ -219,15 +230,15 @@ export function createProviderAndContext<
219
230
  setOverlayUri(null);
220
231
  }, [isBlocking]);
221
232
 
222
- const runTransition = useCallback(async (name: Names, options?: SetThemeOptions<Names>) => {
233
+ const runTransition = useCallback(async (initialName: Names, options?: SetThemeOptions<Names>) => {
234
+ let name: Names = initialName;
223
235
  try {
224
- // Two frames so the JS → Shadow Tree → Native UI pipeline fully paints
225
- // any pending state changes before the screenshot. useTheme({ initialSelection })
226
- // adds its own requestAnimationFrame before calling setTheme, giving 3
227
- // total frames — enough for React commit + native paint on 120Hz displays.
236
+ // 2 frames for JS → Shadow Tree → Native UI to paint before capture.
237
+ // useTheme's requestAnimationFrame adds a 3rd — enough for 120Hz.
228
238
  await waitFrames(2);
229
239
  if (!mountedRef.current) return;
230
240
 
241
+ // jpg 0.8: ~30% smaller than png, no visible degradation during a cross-fade.
231
242
  const uri = await captureRef(rootRef, { format: 'jpg', quality: 0.8 });
232
243
  if (!mountedRef.current) return;
233
244
 
@@ -242,13 +253,47 @@ export function createProviderAndContext<
242
253
  await waitFrames(1);
243
254
  if (!mountedRef.current) return;
244
255
 
245
- // Deferred until the overlay covers the screen so the re-render
246
- // doesn't flash state-dependent visuals before the screenshot hides them.
256
+ // Deferred: setting this earlier would re-render under the overlay,
257
+ // flashing state-dependent visuals before the screenshot hides them.
247
258
  setIsTransitioning(true);
248
259
 
249
260
  setActiveTheme({ colors: getColors(name), name });
250
261
 
251
- // Wait for React to commit the new theme under the still-opaque overlay.
262
+ // Deferred setColorScheme('unspecified') — done now while the overlay is
263
+ // opaque so any theme correction (OS scheme diverged) is invisible to the user.
264
+ if (deferredSystemRestoreRef.current !== null) {
265
+ const manualScheme = deferredSystemRestoreRef.current;
266
+
267
+ let resolved = false;
268
+ const realScheme = await new Promise<'light' | 'dark'>((resolve) => {
269
+ const sub = Appearance.addChangeListener(({ colorScheme }) => {
270
+ if (resolved) return;
271
+ resolved = true;
272
+ sub.remove();
273
+ resolve(normalizeScheme(colorScheme));
274
+ });
275
+ Appearance.setColorScheme('unspecified');
276
+ // No event → OS scheme already matches the manual override.
277
+ requestAnimationFrame(() => {
278
+ if (resolved) return;
279
+ resolved = true;
280
+ sub.remove();
281
+ resolve(manualScheme);
282
+ });
283
+ });
284
+ if (!mountedRef.current) return;
285
+
286
+ deferredSystemRestoreRef.current = null;
287
+ lastKnownOsSchemeRef.current = realScheme;
288
+
289
+ const corrected = mapSchemeToTheme<Names>(realScheme, systemThemeMap);
290
+ if (corrected in themes && corrected !== name) {
291
+ name = corrected as Names;
292
+ targetThemeRef.current = corrected;
293
+ setActiveTheme({ colors: getColors(corrected), name: corrected });
294
+ }
295
+ }
296
+
252
297
  await waitFrames(1);
253
298
  if (!mountedRef.current) return;
254
299
 
@@ -259,8 +304,7 @@ export function createProviderAndContext<
259
304
  safeCall('per-call onTransitionEnd', options?.onTransitionEnd, name);
260
305
  safeCall('config onThemeChange', onThemeChange, name);
261
306
 
262
- // Reconcile: if the OS appearance changed while the transition was
263
- // running (stored in pendingSchemeRef by the listener), apply it now.
307
+ // Apply any OS scheme change that arrived mid-transition.
264
308
  if (systemModeRef.current && pendingSchemeRef.current !== null) {
265
309
  const resolved = mapSchemeToTheme<Names>(pendingSchemeRef.current, systemThemeMap);
266
310
  pendingSchemeRef.current = null;
@@ -291,32 +335,20 @@ export function createProviderAndContext<
291
335
  }, [overlayOpacity, resetTransition]);
292
336
 
293
337
  const setTheme = useCallback((name: Names | 'system', options?: SetThemeOptions<Names>): boolean => {
294
- // When transitioning from manual to system mode, Android's getColorScheme()
295
- // returns stale values synchronously after setColorScheme('unspecified').
296
- // Clear the override and defer resolution by one frame so native settles.
338
+ // Manual→system: resolve from cached OS scheme to avoid the Android
339
+ // status bar flash that setColorScheme('unspecified') causes pre-overlay.
297
340
  if (name === 'system' && !systemModeRef.current) {
298
341
  if (transitioningRef.current) return false;
299
342
 
300
- // Don't set systemModeRef yet — while it's false the Appearance
301
- // listener guard (`!systemModeRef.current`) naturally ignores
302
- // stale events Android fires after setColorScheme('unspecified').
303
343
  setIsSystemMode(true);
304
- Appearance.setColorScheme('unspecified');
305
-
306
- requestAnimationFrame(() => {
307
- if (!mountedRef.current) return;
308
- systemModeRef.current = true;
309
- setTheme('system', options);
310
- });
311
- return true;
344
+ systemModeRef.current = true;
345
+ deferredSystemRestoreRef.current = schemeOf(targetThemeRef.current);
346
+ return setTheme('system', options);
312
347
  }
313
348
 
314
349
  const resolvedTheme = name === 'system'
315
- // When Android returns 'unspecified' (override matched OS, no config change),
316
- // infer the OS scheme from the current theme's darkness classification.
317
- ? resolveSystemTheme<Names>(systemThemeMap, schemeOf(targetThemeRef.current))
350
+ ? mapSchemeToTheme<Names>(lastKnownOsSchemeRef.current, systemThemeMap)
318
351
  : name;
319
-
320
352
  if (!(resolvedTheme in themes)) {
321
353
  const resolutionHint = name === 'system'
322
354
  ? ' Provide `systemThemeMap` in the config to map OS appearance to your theme names.'
@@ -328,20 +360,17 @@ export function createProviderAndContext<
328
360
 
329
361
  if (transitioningRef.current) return false;
330
362
 
331
- // Set system mode AFTER the transition guard so a rejected call during an ongoing
332
- // transition doesn't silently activate system-following mode.
363
+ // After transition guard — a rejected call must not activate system mode.
333
364
  const wasSystemMode = systemModeRef.current;
334
365
  systemModeRef.current = name === 'system';
335
366
 
336
- // Sync state so the Appearance.setColorScheme effect re-runs.
337
367
  if (systemModeRef.current !== wasSystemMode) {
338
368
  setIsSystemMode(systemModeRef.current);
339
369
  }
340
370
 
341
371
  if (resolvedTheme === targetThemeRef.current) {
342
- // Switching between manual and system mode is a valid change even when
343
- // the resolved theme is the same — return true so select() keeps the
344
- // new selection instead of reverting.
372
+ // Manual↔system mode switch is valid even when the resolved theme matches —
373
+ // returning true prevents select() from reverting the user's selection.
345
374
  return wasSystemMode !== systemModeRef.current;
346
375
  }
347
376
 
@@ -353,8 +382,7 @@ export function createProviderAndContext<
353
382
  return true;
354
383
  }
355
384
 
356
- // Block touches and mark as transitioning BEFORE firing user callbacks to prevent
357
- // re-entrant setTheme calls from starting a concurrent transition.
385
+ // Block before user callbacks to prevent re-entrant setTheme.
358
386
  transitioningRef.current = true;
359
387
  isBlocking.value = true;
360
388
 
@@ -366,8 +394,6 @@ export function createProviderAndContext<
366
394
  resetTransition();
367
395
  throw e;
368
396
  }
369
- // isTransitioning is set inside runTransition(), AFTER captureRef, so no React
370
- // re-render can alter the native view before the screenshot is taken.
371
397
  runTransition(resolvedTheme, options).catch(() => {});
372
398
  return true;
373
399
  }, [isBlocking, resetTransition, runTransition]);
@@ -375,17 +401,17 @@ export function createProviderAndContext<
375
401
  useEffect(() => {
376
402
  const appearanceSub = Appearance.addChangeListener(({ colorScheme }) => {
377
403
  if (!systemModeRef.current) return;
404
+ lastKnownOsSchemeRef.current = normalizeScheme(colorScheme);
405
+ // Deferred restore listener in runTransition handles these.
406
+ if (deferredSystemRestoreRef.current !== null) return;
378
407
  if (transitioningRef.current) {
379
- // Can't start a new transition now; store for reconciliation.
380
408
  pendingSchemeRef.current = normalizeScheme(colorScheme);
381
409
  return;
382
410
  }
383
411
  if (appStateRef.current === 'active') {
384
412
  setTheme('system');
385
413
  } else {
386
- // Background: apply directly (works on Android where JS keeps running).
387
- // On iOS the JS thread is suspended so this commit may be deferred —
388
- // the AppState handler below re-applies on foreground return as a safety net.
414
+ // Background: apply directly. iOS may defer — AppState handler re-applies on foreground.
389
415
  const resolved = mapSchemeToTheme<Names>(normalizeScheme(colorScheme), systemThemeMap);
390
416
  if (!(resolved in themes) || resolved === targetThemeRef.current) return;
391
417
  targetThemeRef.current = resolved;
@@ -394,15 +420,10 @@ export function createProviderAndContext<
394
420
  }
395
421
  });
396
422
 
397
- // Re-read OS scheme on foreground return. Catches two cases:
398
- // 1. iOS never delivered Appearance events while suspended.
399
- // 2. The BG setActiveTheme commit was deferred by iOS suspension.
423
+ // Re-read OS scheme on foreground return — iOS may not deliver
424
+ // Appearance events while suspended, or may defer the React commit.
400
425
  const appSub = AppState.addEventListener('change', (next) => {
401
426
  if (appStateRef.current !== 'active' && next === 'active' && systemModeRef.current) {
402
- // Re-read OS scheme and force setActiveTheme. Even if the BG path
403
- // already set targetThemeRef, iOS may have deferred the React commit.
404
- // Calling setActiveTheme again guarantees an immediate commit now
405
- // that the app is active.
406
427
  const resolved = resolveSystemTheme<Names>(systemThemeMap, schemeOf(targetThemeRef.current));
407
428
  if (resolved in themes) {
408
429
  const changed = resolved !== targetThemeRef.current;
@@ -426,11 +447,11 @@ export function createProviderAndContext<
426
447
 
427
448
  return (
428
449
  <Context.Provider value={contextValue}>
429
- {/* collapsable={false} prevents Android from flattening the view, which breaks captureRef. */}
450
+ {/* collapsable={false}: Android flattens views by default, breaking captureRef. */}
430
451
  <View ref={rootRef} style={ROOT_STYLE} collapsable={false}>
431
452
  {children}
432
453
  <Animated.View style={ABSOLUTE_FILL} animatedProps={blockerProps} />
433
- {/* Always mounted so the shared value is permanently connected — no mount-time race. */}
454
+ {/* Always mounted — avoids shared-value race on conditional mount. */}
434
455
  <Animated.View style={[ABSOLUTE_FILL, overlayStyle]} pointerEvents="none">
435
456
  {overlayUri != null ? (
436
457
  <Image source={overlaySource} style={ABSOLUTE_FILL} resizeMode="cover" fadeDuration={0} onLoad={onOverlayLoad} onError={onOverlayError} />