react-native-theme-transition 1.0.7 → 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 +273 -210
  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 +383 -249
  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
@@ -0,0 +1,176 @@
1
+ /**
2
+ * Single source of truth for transition types and their per-type behavior.
3
+ *
4
+ * Adding a new transition here automatically propagates to the
5
+ * `TransitionType` union, the config validator, origin-requirement checks,
6
+ * and default durations.
7
+ *
8
+ * @module
9
+ */
10
+
11
+ /**
12
+ * @internal High-level grouping of transitions by how they render, used
13
+ * for shared defaults (e.g. all `'shape'` transitions share the 800ms
14
+ * default). Not part of the public API; consumers read `kind` directly
15
+ * from `TRANSITION_META[transition]` and let TypeScript infer the
16
+ * literal union.
17
+ *
18
+ * - `'fade'`: the overlay's opacity animates to zero.
19
+ * - `'reveal'`: a growing (or shrinking) circular shape clipped out of the overlay.
20
+ * - `'shape'`: a reveal that uses a custom path (`heart`, `star`).
21
+ * - `'shader'`: a runtime Skia shader effect (`pixelize`, `dissolve`).
22
+ * - `'strip'`: rectangular regions sliding or clearing across the screen
23
+ * (`wipe` edge, `slide` carousel push, `split` parting/shutters).
24
+ */
25
+ export type TransitionKind = 'fade' | 'reveal' | 'shape' | 'shader' | 'strip'
26
+
27
+ /** @internal Shape constraint for entries in {@link TRANSITION_META}. */
28
+ interface TransitionMeta {
29
+ kind: TransitionKind
30
+ needsOrigin: boolean
31
+ invertible: boolean
32
+ /**
33
+ * Whether the engine needs a second snapshot captured from the view
34
+ * AFTER the theme swap, so the transition can render both the old and
35
+ * new themes simultaneously (e.g. `slide`, `pixelize`).
36
+ */
37
+ capturesNew: boolean
38
+ defaultDuration: number
39
+ }
40
+
41
+ /**
42
+ * Per-transition metadata table.
43
+ *
44
+ * Every supported transition has an entry declaring:
45
+ * - `kind`: the rendering family (`'fade'`, `'reveal'`, `'shape'`, `'shader'`, `'strip'`).
46
+ * - `needsOrigin`: whether the engine should resolve an `origin` before
47
+ * running the transition (reveals and shape transitions do).
48
+ * - `invertible`: whether the transition accepts the `inverted` option.
49
+ * Flips reveal/shape transitions (shape shrinks instead of grows) and
50
+ * toggles `split` between parting and shutters.
51
+ * - `capturesNew`: whether the engine needs a second snapshot of the new
52
+ * theme captured after the color swap, so the transition can render both
53
+ * old and new simultaneously (`slide`, `pixelize`).
54
+ * - `defaultDuration`: milliseconds used when no per-call or config-level
55
+ * `duration` is set.
56
+ *
57
+ * Use this table to drive UIs that adapt to the selected transition, for
58
+ * example showing an "Inverted" toggle only when `invertible` is `true`.
59
+ *
60
+ * @example
61
+ * ```tsx
62
+ * import { TRANSITION_META, TRANSITION_TYPES } from 'react-native-theme-transition'
63
+ *
64
+ * // Build an options panel that adapts to the selected transition:
65
+ * const meta = TRANSITION_META[transition]
66
+ * return (
67
+ * <>
68
+ * {TRANSITION_TYPES.map((t) => <Chip key={t} label={t} />)}
69
+ * {meta.invertible && <Toggle label="Inverted" />}
70
+ * {meta.needsOrigin && <OriginPicker />}
71
+ * </>
72
+ * )
73
+ * ```
74
+ */
75
+ export const TRANSITION_META = {
76
+ fade: {
77
+ kind: 'fade',
78
+ needsOrigin: false,
79
+ invertible: false,
80
+ capturesNew: false,
81
+ defaultDuration: 350,
82
+ },
83
+ circularReveal: {
84
+ kind: 'reveal',
85
+ needsOrigin: true,
86
+ invertible: true,
87
+ capturesNew: false,
88
+ defaultDuration: 350,
89
+ },
90
+ wipe: {
91
+ kind: 'strip',
92
+ needsOrigin: false,
93
+ invertible: false,
94
+ capturesNew: false,
95
+ defaultDuration: 350,
96
+ },
97
+ slide: {
98
+ kind: 'strip',
99
+ needsOrigin: false,
100
+ invertible: false,
101
+ capturesNew: true,
102
+ defaultDuration: 350,
103
+ },
104
+ split: {
105
+ kind: 'strip',
106
+ needsOrigin: false,
107
+ invertible: true,
108
+ capturesNew: false,
109
+ defaultDuration: 350,
110
+ },
111
+ heart: {
112
+ kind: 'shape',
113
+ needsOrigin: true,
114
+ invertible: true,
115
+ capturesNew: false,
116
+ defaultDuration: 800,
117
+ },
118
+ star: {
119
+ kind: 'shape',
120
+ needsOrigin: true,
121
+ invertible: true,
122
+ capturesNew: false,
123
+ defaultDuration: 800,
124
+ },
125
+ pixelize: {
126
+ kind: 'shader',
127
+ needsOrigin: false,
128
+ invertible: false,
129
+ capturesNew: true,
130
+ defaultDuration: 750,
131
+ },
132
+ dissolve: {
133
+ kind: 'shader',
134
+ needsOrigin: false,
135
+ invertible: false,
136
+ capturesNew: false,
137
+ defaultDuration: 750,
138
+ },
139
+ } as const satisfies Record<string, TransitionMeta>
140
+
141
+ /**
142
+ * Union of every supported transition name. Derived automatically from the
143
+ * {@link TRANSITION_META} table. Adding an entry there also adds it here.
144
+ */
145
+ export type TransitionType = keyof typeof TRANSITION_META
146
+
147
+ /**
148
+ * Runtime list of every supported transition name. Use this to build
149
+ * pickers or validate user input without hardcoding the set.
150
+ *
151
+ * @remarks
152
+ * The array is `readonly` and frozen. Mutating it (e.g. `.sort()`, `.push()`)
153
+ * would corrupt the config validator in {@link createThemeTransition}, which
154
+ * treats this list as the authoritative set. Copy it with
155
+ * `[...TRANSITION_TYPES]` if a mutable version is needed.
156
+ *
157
+ * @example
158
+ * ```ts
159
+ * import { TRANSITION_TYPES } from 'react-native-theme-transition'
160
+ *
161
+ * TRANSITION_TYPES.map((type) => (
162
+ * <Button key={type} onPress={() => setTheme('dark', { transition: type })}>
163
+ * {type}
164
+ * </Button>
165
+ * ))
166
+ * ```
167
+ */
168
+ export const TRANSITION_TYPES: readonly TransitionType[] = Object.freeze(
169
+ Object.keys(TRANSITION_META) as TransitionType[],
170
+ )
171
+
172
+ /** @internal Direction for `wipe` and `slide` transitions. */
173
+ export type WipeDirection = 'left' | 'right' | 'up' | 'down'
174
+
175
+ /** @internal How the screen is divided by the `split` transition. */
176
+ export type SplitMode = 'top-bottom' | 'left-right'