react-native-theme-transition 1.0.7 → 2.0.1

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
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-native-theme-transition",
3
- "version": "1.0.7",
4
- "description": "Smooth, animated theme and dark mode transitions for React Native. Expo Go compatible, powered by Reanimated.",
3
+ "version": "2.0.1",
4
+ "description": "Animated theme transitions for React Native. Nine styles built on Skia, all running in Expo Go.",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",
@@ -31,6 +31,7 @@
31
31
  "prepack": "cp README.npm.md README.md",
32
32
  "postpack": "git checkout README.md",
33
33
  "prepublishOnly": "npm run build",
34
+ "test": "jest",
34
35
  "lint": "biome check .",
35
36
  "lint:fix": "biome check --write .",
36
37
  "release": "npm publish --provenance --access public",
@@ -56,6 +57,10 @@
56
57
  "reanimated",
57
58
  "screenshot",
58
59
  "overlay",
60
+ "circular-reveal",
61
+ "telegram",
62
+ "skia",
63
+ "react-native-skia",
59
64
  "expo",
60
65
  "expo-go",
61
66
  "fabric",
@@ -73,21 +78,24 @@
73
78
  "homepage": "https://react-native-theme-transition.vercel.app",
74
79
  "author": "Mario Prieta",
75
80
  "peerDependencies": {
76
- "react": ">=18.0.0",
77
- "react-native": ">=0.76.0",
81
+ "react": ">=19.0.0",
82
+ "react-native": ">=0.78.0",
78
83
  "react-native-reanimated": ">=4.0.0",
79
- "react-native-view-shot": ">=3.0.0",
84
+ "@shopify/react-native-skia": ">=2.0.0",
80
85
  "react-native-worklets": ">=0.5.0"
81
86
  },
82
87
  "devDependencies": {
83
88
  "@biomejs/biome": "^2.4.6",
84
89
  "@changesets/cli": "^2.30.0",
90
+ "@types/jest": "^30.0.0",
85
91
  "@types/react": "~19.2.2",
92
+ "jest": "^30.3.0",
86
93
  "react": "19.2.0",
87
94
  "react-native": "0.83.2",
88
95
  "react-native-reanimated": "4.2.1",
89
- "react-native-view-shot": "4.0.3",
96
+ "@shopify/react-native-skia": "2.4.18",
90
97
  "react-native-worklets": "0.7.2",
98
+ "ts-jest": "^29.4.6",
91
99
  "typescript": "~5.9.2"
92
100
  }
93
101
  }
package/src/constants.ts CHANGED
@@ -1,2 +1,8 @@
1
1
  /** Log/error prefix shared across the package. @internal */
2
2
  export const TAG = '[react-native-theme-transition]'
3
+
4
+ /** Absolute fill style for overlays. @internal */
5
+ export const ABSOLUTE_FILL = { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 } as const
6
+
7
+ /** Flex fill for the provider's root and inner wrappers. @internal */
8
+ export const FLEX_FILL = { flex: 1 } as const
@@ -1,38 +1,29 @@
1
1
  /**
2
- * Factory that wires the theme transition provider, context, and hooks.
3
- *
4
- * @remarks
5
- * Validates theme configuration at initialization: ensures at least one theme
6
- * exists and that all themes share identical token keys.
7
- * Returns a self-contained API ({@link ThemeTransitionAPI}) with no singletons,
8
- * so multiple theme scopes can coexist in the same app.
2
+ * Factory entry point for the theme transition system.
9
3
  *
10
4
  * @module
11
5
  */
12
6
 
7
+ import { use } from 'react'
13
8
  import { TAG } from './constants'
14
- import { createUseTheme } from './hooks/useTheme'
15
9
  import { createProviderAndContext } from './transitionEngine'
10
+ import { TRANSITION_TYPES } from './transitionMeta'
16
11
  import type {
17
12
  ThemeDefinition,
18
13
  ThemeNames,
19
14
  ThemeTransitionAPI,
20
15
  ThemeTransitionConfig,
16
+ TokenNames,
17
+ UseThemeResult,
21
18
  } from './types'
22
19
 
23
20
  /**
24
- * Creates a fully typed theme transition system.
25
- *
26
- * @typeParam T - Your application's theme map, keyed by theme name.
27
- * @param config - Theme configuration including available themes and defaults.
28
- * @returns A provider component and hooks scoped to the supplied themes.
21
+ * Builds a fully typed theme transition system from a map of themes.
29
22
  *
30
- * @example
31
- * ```tsx
32
- * const { ThemeTransitionProvider, useTheme } = createThemeTransition({
33
- * themes: { light: { bg: '#fff' }, dark: { bg: '#000' } },
34
- * });
35
- * ```
23
+ * @param config - Theme configuration.
24
+ * @returns A {@link ThemeTransitionAPI} bound to the supplied themes.
25
+ * @throws Error on invalid configuration.
26
+ * @see https://react-native-theme-transition.vercel.app/docs/api/create-theme-transition
36
27
  */
37
28
  export function createThemeTransition<T extends Record<string, ThemeDefinition>>(
38
29
  config: ThemeTransitionConfig<T>,
@@ -43,9 +34,9 @@ export function createThemeTransition<T extends Record<string, ThemeDefinition>>
43
34
  throw new Error(`${TAG} \`themes\` must contain at least one theme.`)
44
35
  }
45
36
 
46
- if ('system' in config.themes) {
37
+ if (Object.hasOwn(config.themes, 'system')) {
47
38
  throw new Error(
48
- `${TAG} \`"system"\` is a reserved name and cannot be used as a theme key. Rename the theme and use \`systemThemeMap\` to map OS appearance to it.`,
39
+ `${TAG} \`"system"\` is a reserved name and cannot be used as a theme key.\n Hint: rename the theme and use \`systemThemeMap\` to map OS appearance to it.`,
49
40
  )
50
41
  }
51
42
 
@@ -56,38 +47,65 @@ export function createThemeTransition<T extends Record<string, ThemeDefinition>>
56
47
  const keys = Object.keys(config.themes[name]).sort()
57
48
  if (keys.length !== referenceKeys.length || keys.some((k, i) => k !== referenceKeys[i])) {
58
49
  throw new Error(
59
- `${TAG} Theme "${name}" has different token keys than "${referenceTheme}". All themes must share identical keys.`,
50
+ `${TAG} Theme "${name}" has different token keys than "${referenceTheme}".\n Hint: every theme must share identical token keys.`,
60
51
  )
61
52
  }
62
53
  }
63
54
 
64
- if (
65
- config.duration != null &&
66
- (typeof config.duration !== 'number' ||
67
- !Number.isFinite(config.duration) ||
68
- config.duration < 0)
69
- ) {
70
- throw new Error(`${TAG} \`duration\` must be a finite non-negative number.`)
55
+ if (config.transition != null && !TRANSITION_TYPES.includes(config.transition)) {
56
+ throw new Error(
57
+ `${TAG} \`transition\` must be one of: ${TRANSITION_TYPES.join(', ')}. Got "${config.transition}".`,
58
+ )
59
+ }
60
+
61
+ const assertThemeExists = (name: string, source: string, hint: string) => {
62
+ if (!Object.hasOwn(config.themes, name)) {
63
+ throw new Error(
64
+ `${TAG} ${source} refers to "${name}" which does not exist in themes.\n Hint: ${hint}`,
65
+ )
66
+ }
71
67
  }
72
68
 
73
69
  if (config.systemThemeMap) {
74
- if (!('light' in config.systemThemeMap) || !('dark' in config.systemThemeMap)) {
70
+ if (
71
+ !Object.hasOwn(config.systemThemeMap, 'light') ||
72
+ !Object.hasOwn(config.systemThemeMap, 'dark')
73
+ ) {
75
74
  throw new Error(`${TAG} \`systemThemeMap\` must provide both \`light\` and \`dark\` keys.`)
76
75
  }
77
-
78
76
  for (const [scheme, name] of Object.entries(config.systemThemeMap)) {
79
- if (!(name in config.themes)) {
80
- throw new Error(
81
- `${TAG} \`systemThemeMap.${scheme}\` maps to "${name}" which does not exist in themes.`,
82
- )
83
- }
77
+ assertThemeExists(
78
+ name,
79
+ `\`systemThemeMap.${scheme}\``,
80
+ 'the value must match a key in `themes`.',
81
+ )
82
+ }
83
+ }
84
+
85
+ if (config.darkThemes) {
86
+ if (config.darkThemes.length === 0) {
87
+ throw new Error(
88
+ `${TAG} \`darkThemes\` cannot be an empty array.\n Hint: omit the field to use the default (\`['dark']\` or \`[systemThemeMap.dark]\`), or list at least one theme name.`,
89
+ )
90
+ }
91
+ for (const name of config.darkThemes) {
92
+ assertThemeExists(
93
+ name,
94
+ '`darkThemes`',
95
+ 'every entry in `darkThemes` must match a key in `themes`.',
96
+ )
84
97
  }
85
98
  }
86
99
 
87
100
  const { Context, ThemeTransitionProvider } = createProviderAndContext(config)
88
101
 
89
- return {
90
- ThemeTransitionProvider,
91
- useTheme: createUseTheme<T>(Context),
102
+ function useTheme(): UseThemeResult<TokenNames<T>, ThemeNames<T>> {
103
+ const ctx = use(Context)
104
+ if (!ctx) {
105
+ throw new Error(`${TAG} \`useTheme\` must be used inside a \`ThemeTransitionProvider\`.`)
106
+ }
107
+ return ctx
92
108
  }
109
+
110
+ return { ThemeTransitionProvider, useTheme }
93
111
  }
package/src/index.ts CHANGED
@@ -2,28 +2,31 @@
2
2
  * Public entry point for react-native-theme-transition.
3
3
  *
4
4
  * @remarks
5
- * The transition mechanism works in five steps:
6
- * 1. Blocks touch input via a Reanimated shared value (instant, no React re-render).
7
- * 2. Captures the current native view via `react-native-view-shot`.
8
- * 3. Overlays the snapshot as an absolute-positioned `Image` (`onLoad` confirms decode).
9
- * 4. Mutates context to inject new theme colors underneath.
10
- * 5. Fades the overlay to zero via `react-native-reanimated` — the native repaint
11
- * completes during the first frames while the overlay is still near-opaque.
5
+ * The transition engine snapshots the current native view into a Skia
6
+ * `SkImage`, swaps the theme tokens underneath, and animates the
7
+ * snapshot away with one of nine styles (fade, circular reveal, heart,
8
+ * star, wipe, slide, split, pixelize, dissolve). Touch input is blocked
9
+ * by a shared value on the UI thread so React never sees the blocking
10
+ * state change.
12
11
  *
13
- * @see {@link createThemeTransition} for the main API surface.
12
+ * @see {@link createThemeTransition} for the main API entry.
14
13
  * @packageDocumentation
15
14
  */
16
15
 
17
16
  export { createThemeTransition } from './createThemeTransition'
17
+ export { TRANSITION_META, TRANSITION_TYPES } from './transitionMeta'
18
18
 
19
19
  export type {
20
+ ColorScheme,
21
+ OriginSpec,
20
22
  SetThemeOptions,
21
23
  SystemThemeMap,
22
24
  ThemeDefinition,
23
25
  ThemeNames,
24
- ThemeSelectionResult,
25
26
  ThemeTransitionAPI,
26
27
  ThemeTransitionConfig,
27
28
  TokenNames,
29
+ TransitionOrigin,
30
+ TransitionType,
28
31
  UseThemeResult,
29
32
  } from './types'