react-native-theme-transition 1.0.6 → 2.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.
Files changed (66) hide show
  1. package/README.md +55 -43
  2. package/README.npm.md +55 -43
  3. package/dist/constants.d.ts +1 -2
  4. package/dist/constants.d.ts.map +1 -1
  5. package/dist/constants.js +4 -0
  6. package/dist/constants.js.map +1 -1
  7. package/dist/createThemeTransition.d.ts +6 -18
  8. package/dist/createThemeTransition.d.ts.map +1 -1
  9. package/dist/createThemeTransition.js +37 -35
  10. package/dist/createThemeTransition.js.map +1 -1
  11. package/dist/index.d.ts +9 -9
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +8 -8
  14. package/dist/index.js.map +1 -1
  15. package/dist/overlay/SkiaOverlay.d.ts +17 -0
  16. package/dist/overlay/SkiaOverlay.d.ts.map +1 -0
  17. package/dist/overlay/SkiaOverlay.js +297 -0
  18. package/dist/overlay/SkiaOverlay.js.map +1 -0
  19. package/dist/overlay/captureView.d.ts +7 -0
  20. package/dist/overlay/captureView.d.ts.map +1 -0
  21. package/dist/overlay/captureView.js +31 -0
  22. package/dist/overlay/captureView.js.map +1 -0
  23. package/dist/overlay/resolveOrigin.d.ts +8 -0
  24. package/dist/overlay/resolveOrigin.d.ts.map +1 -0
  25. package/dist/overlay/resolveOrigin.js +68 -0
  26. package/dist/overlay/resolveOrigin.js.map +1 -0
  27. package/dist/overlay/types.d.ts +15 -0
  28. package/dist/overlay/types.d.ts.map +1 -0
  29. package/dist/overlay/types.js +61 -0
  30. package/dist/overlay/types.js.map +1 -0
  31. package/dist/setThemeDecision.d.ts +14 -0
  32. package/dist/setThemeDecision.d.ts.map +1 -0
  33. package/dist/setThemeDecision.js +27 -0
  34. package/dist/setThemeDecision.js.map +1 -0
  35. package/dist/transitionEngine.d.ts +48 -17
  36. package/dist/transitionEngine.d.ts.map +1 -1
  37. package/dist/transitionEngine.js +279 -208
  38. package/dist/transitionEngine.js.map +1 -1
  39. package/dist/transitionMeta.d.ts +136 -0
  40. package/dist/transitionMeta.d.ts.map +1 -0
  41. package/dist/transitionMeta.js +131 -0
  42. package/dist/transitionMeta.js.map +1 -0
  43. package/dist/types.d.ts +254 -193
  44. package/dist/types.d.ts.map +1 -1
  45. package/dist/validateSetThemeOptions.d.ts +15 -0
  46. package/dist/validateSetThemeOptions.d.ts.map +1 -0
  47. package/dist/validateSetThemeOptions.js +54 -0
  48. package/dist/validateSetThemeOptions.js.map +1 -0
  49. package/package.json +14 -6
  50. package/src/constants.ts +6 -0
  51. package/src/createThemeTransition.ts +57 -39
  52. package/src/index.ts +12 -9
  53. package/src/overlay/SkiaOverlay.tsx +629 -0
  54. package/src/overlay/captureView.ts +32 -0
  55. package/src/overlay/resolveOrigin.ts +81 -0
  56. package/src/overlay/types.ts +83 -0
  57. package/src/setThemeDecision.ts +48 -0
  58. package/src/transitionEngine.tsx +390 -247
  59. package/src/transitionMeta.ts +176 -0
  60. package/src/types.ts +272 -193
  61. package/src/validateSetThemeOptions.ts +76 -0
  62. package/dist/hooks/useTheme.d.ts +0 -14
  63. package/dist/hooks/useTheme.d.ts.map +0 -1
  64. package/dist/hooks/useTheme.js +0 -46
  65. package/dist/hooks/useTheme.js.map +0 -1
  66. package/src/hooks/useTheme.ts +0 -72
@@ -1,24 +1,55 @@
1
1
  /**
2
- * Screenshot-overlay transition engine and provider.
2
+ * Provider and context for the theme transition engine.
3
3
  *
4
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.
5
+ * Capture and overlay both use `@shopify/react-native-skia`; a single
6
+ * 0 → 1 `progress` shared value drives every transition kind. The
7
+ * library is policy-free about OS Reduce Motion. Consumers who want
8
+ * to honor it pass `animated: false` per call.
8
9
  *
9
- * @module
10
- */
11
- import type { ThemeDefinition, ThemeNames, ThemeTransitionConfig, TokenNames, UseThemeResult } from './types';
12
- /**
13
- * Creates the React Context and provider component for a given theme configuration.
10
+ * **State machine.** Each animated transition runs the following steps
11
+ * in order:
14
12
  *
15
- * @internal Used by {@link createThemeTransition}; not part of the public API.
13
+ * 1. `setTheme`: sync writes (`transitioningRef`, `isBlocking`,
14
+ * `intendedThemeRef`, `preference`) so picker UIs repaint before
15
+ * capture. `runTransition` is kicked off async and the config and
16
+ * per-call `onTransitionStart` callbacks fire.
17
+ * 2. **`SETTLE.beforeCapture`**: wait one frame so React has flushed
18
+ * the sync writes and any pressed-state repaints made it to screen
19
+ * before the snapshot is taken.
20
+ * 3. **Capture old**: `captureView` grabs a CPU-backed `SkImage` of the
21
+ * inner tree. If capture fails, the engine falls back to an instant
22
+ * swap (no overlay, only `onThemeChange` fires).
23
+ * 4. **Commit 1**: `setOverlayParams` + `setSkImage` mount the snapshot
24
+ * on the pre-mounted Canvas.
25
+ * 5. **`SETTLE.skiaPaint`**: wait so Skia paints the snapshot before
26
+ * the inner tree swaps its colors. Otherwise the new theme flashes
27
+ * through on Android.
28
+ * 6. **Commit 2**: `setIsTransitioning(true)` + `setActiveTheme(new)`
29
+ * swap the inner tree underneath the now-covering overlay.
30
+ * 7. **`SETTLE.treeRepaint` (conditional)**: for reveal, shape, and
31
+ * dual-image transitions, wait an extra frame so the inner tree
32
+ * has repainted in the new theme before the second capture.
33
+ * 8. **Capture new (conditional)**: for `slide` and `pixelize`
34
+ * (`TRANSITION_META[kind].capturesNew === true`), capture a second
35
+ * snapshot of the inner tree in the new theme and mount it as
36
+ * `imageNew` on the overlay.
37
+ * 9. **Animate**: Reanimated animates `progress` 0 → 1 and a
38
+ * `setTimeout(duration)` fires the `finish` cleanup, which resets
39
+ * the overlay and fires `onTransitionEnd` (config and per-call) and
40
+ * `onThemeChange`. If the OS appearance changed while in `'system'`
41
+ * mode during the transition, the pending correction fires a
42
+ * second `onThemeChange`.
43
+ *
44
+ * **Why the SkiaOverlay stays permanently mounted:** Android paints a
45
+ * fresh native view at the same commit it gains content; if the Canvas
46
+ * mounted at commit 1, its first paint would be empty and the
47
+ * already-swapped inner tree would flash the new theme through for one
48
+ * frame. Keeping the Canvas mounted with `image={null}` between
49
+ * transitions avoids the layout pass entirely.
50
+ *
51
+ * @module
52
+ * @internal
16
53
  */
17
- export declare function createProviderAndContext<T extends Record<string, ThemeDefinition>>(config: ThemeTransitionConfig<T>): {
18
- Context: import("react").Context<UseThemeResult<TokenNames<T>, ThemeNames<T>> | null>;
19
- ThemeTransitionProvider: ({ children, initialTheme, }: {
20
- children: React.ReactNode;
21
- initialTheme: ThemeNames<T> | "system";
22
- }) => import("react/jsx-runtime").JSX.Element;
23
- };
54
+ export {};
24
55
  //# sourceMappingURL=transitionEngine.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"transitionEngine.d.ts","sourceRoot":"","sources":["../src/transitionEngine.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAQH,OAAO,KAAK,EAGV,eAAe,EACf,UAAU,EACV,qBAAqB,EACrB,UAAU,EACV,cAAc,EACf,MAAM,SAAS,CAAA;AAkGhB;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,EAChF,MAAM,EAAE,qBAAqB,CAAC,CAAC,CAAC;;2DA8B7B;QACD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;QACzB,YAAY,EAAE,gBAAQ,QAAQ,CAAA;KAC/B;EA6VF"}
1
+ {"version":3,"file":"transitionEngine.d.ts","sourceRoot":"","sources":["../src/transitionEngine.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG"}