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.
- package/README.md +55 -43
- package/README.npm.md +55 -43
- package/dist/constants.d.ts +1 -2
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +4 -0
- package/dist/constants.js.map +1 -1
- package/dist/createThemeTransition.d.ts +6 -18
- package/dist/createThemeTransition.d.ts.map +1 -1
- package/dist/createThemeTransition.js +37 -35
- package/dist/createThemeTransition.js.map +1 -1
- package/dist/index.d.ts +9 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -8
- package/dist/index.js.map +1 -1
- package/dist/overlay/SkiaOverlay.d.ts +17 -0
- package/dist/overlay/SkiaOverlay.d.ts.map +1 -0
- package/dist/overlay/SkiaOverlay.js +297 -0
- package/dist/overlay/SkiaOverlay.js.map +1 -0
- package/dist/overlay/captureView.d.ts +7 -0
- package/dist/overlay/captureView.d.ts.map +1 -0
- package/dist/overlay/captureView.js +31 -0
- package/dist/overlay/captureView.js.map +1 -0
- package/dist/overlay/resolveOrigin.d.ts +8 -0
- package/dist/overlay/resolveOrigin.d.ts.map +1 -0
- package/dist/overlay/resolveOrigin.js +68 -0
- package/dist/overlay/resolveOrigin.js.map +1 -0
- package/dist/overlay/types.d.ts +15 -0
- package/dist/overlay/types.d.ts.map +1 -0
- package/dist/overlay/types.js +61 -0
- package/dist/overlay/types.js.map +1 -0
- package/dist/setThemeDecision.d.ts +14 -0
- package/dist/setThemeDecision.d.ts.map +1 -0
- package/dist/setThemeDecision.js +27 -0
- package/dist/setThemeDecision.js.map +1 -0
- package/dist/transitionEngine.d.ts +48 -17
- package/dist/transitionEngine.d.ts.map +1 -1
- package/dist/transitionEngine.js +273 -210
- package/dist/transitionEngine.js.map +1 -1
- package/dist/transitionMeta.d.ts +136 -0
- package/dist/transitionMeta.d.ts.map +1 -0
- package/dist/transitionMeta.js +131 -0
- package/dist/transitionMeta.js.map +1 -0
- package/dist/types.d.ts +254 -193
- package/dist/types.d.ts.map +1 -1
- package/dist/validateSetThemeOptions.d.ts +15 -0
- package/dist/validateSetThemeOptions.d.ts.map +1 -0
- package/dist/validateSetThemeOptions.js +54 -0
- package/dist/validateSetThemeOptions.js.map +1 -0
- package/package.json +14 -6
- package/src/constants.ts +6 -0
- package/src/createThemeTransition.ts +57 -39
- package/src/index.ts +12 -9
- package/src/overlay/SkiaOverlay.tsx +629 -0
- package/src/overlay/captureView.ts +32 -0
- package/src/overlay/resolveOrigin.ts +81 -0
- package/src/overlay/types.ts +83 -0
- package/src/setThemeDecision.ts +48 -0
- package/src/transitionEngine.tsx +383 -249
- package/src/transitionMeta.ts +176 -0
- package/src/types.ts +272 -193
- package/src/validateSetThemeOptions.ts +76 -0
- package/dist/hooks/useTheme.d.ts +0 -14
- package/dist/hooks/useTheme.d.ts.map +0 -1
- package/dist/hooks/useTheme.js +0 -46
- package/dist/hooks/useTheme.js.map +0 -1
- 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": "
|
|
4
|
-
"description": "
|
|
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": ">=
|
|
77
|
-
"react-native": ">=0.
|
|
81
|
+
"react": ">=19.0.0",
|
|
82
|
+
"react-native": ">=0.78.0",
|
|
78
83
|
"react-native-reanimated": ">=4.0.0",
|
|
79
|
-
"react-native-
|
|
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-
|
|
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
|
|
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
|
-
*
|
|
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
|
-
* @
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
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'
|
|
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
|
|
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}"
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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 (
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
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
|
|
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'
|