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.
- 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/README.md
CHANGED
|
@@ -1,110 +1,122 @@
|
|
|
1
1
|
<h1 align="center">React Native Theme Transition</h1>
|
|
2
2
|
|
|
3
3
|
<p align="center">
|
|
4
|
-
|
|
4
|
+
Nine animated theme transitions for React Native. Skia-powered, runs in Expo Go.
|
|
5
5
|
</p>
|
|
6
6
|
|
|
7
7
|
<p align="center">
|
|
8
8
|
<a href="https://www.npmjs.com/package/react-native-theme-transition"><img src="https://img.shields.io/npm/v/react-native-theme-transition.svg?t=1" alt="npm version" /></a>
|
|
9
|
-
<a href="https://bundlephobia.com/package/react-native-theme-transition"><img src="https://img.shields.io/
|
|
9
|
+
<a href="https://bundlephobia.com/package/react-native-theme-transition"><img src="https://img.shields.io/bundlephobia/minzip/react-native-theme-transition" alt="bundle size" /></a>
|
|
10
10
|
<img src="https://img.shields.io/badge/Expo_Go-compatible-000.svg?logo=expo&logoColor=white" alt="expo compatible" />
|
|
11
11
|
<img src="https://img.shields.io/badge/React_Compiler-compatible-blueviolet.svg" alt="react compiler" />
|
|
12
12
|
<a href="https://github.com/marioprieta/react-native-theme-transition/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/react-native-theme-transition?t=1" alt="license" /></a>
|
|
13
13
|
</p>
|
|
14
14
|
|
|
15
|
-
<
|
|
16
|
-
<
|
|
17
|
-
|
|
18
|
-
<td align="center"><b>Android</b></td>
|
|
19
|
-
</tr>
|
|
20
|
-
<tr>
|
|
21
|
-
<td>
|
|
22
|
-
<img src="https://raw.githubusercontent.com/marioprieta/react-native-theme-transition/main/assets/videos/iOS_demo.gif" width="260" alt="iOS demo" />
|
|
23
|
-
</td>
|
|
24
|
-
<td>
|
|
25
|
-
<img src="https://raw.githubusercontent.com/marioprieta/react-native-theme-transition/main/assets/videos/Android_demo.gif" width="260" alt="Android demo" />
|
|
26
|
-
</td>
|
|
27
|
-
</tr>
|
|
28
|
-
</table>
|
|
15
|
+
<p align="center">
|
|
16
|
+
<img src="https://github.com/user-attachments/assets/32cdd33a-2c79-42f6-b70a-4a4644100683" width="400" alt="React Native Theme Transition demo" />
|
|
17
|
+
</p>
|
|
29
18
|
|
|
30
19
|
## Features
|
|
31
20
|
|
|
32
|
-
- **
|
|
33
|
-
- **Expo Go
|
|
34
|
-
- **
|
|
35
|
-
- **System theme
|
|
36
|
-
- **
|
|
37
|
-
- **
|
|
38
|
-
|
|
39
|
-
|
|
21
|
+
- **Nine transition styles.** `fade`, `circularReveal`, `heart`, `star`, `wipe`, `slide`, `split`, `pixelize`, `dissolve`.
|
|
22
|
+
- **Expo Go ready.** Works on Expo SDK 54+ out of the box. Bare React Native CLI also supported.
|
|
23
|
+
- **Full TypeScript inference.** `useTheme()` and `setTheme()` know your theme names and color tokens without manual generics.
|
|
24
|
+
- **System theme built in.** Follows OS appearance with zero-flash startup.
|
|
25
|
+
- **Strict runtime validation.** Invalid options throw immediately with clear error messages.
|
|
26
|
+
- **React Compiler compatible.** All hooks follow the [Rules of React](https://react.dev/reference/rules).
|
|
27
|
+
|
|
28
|
+
## Requirements
|
|
29
|
+
|
|
30
|
+
- React **19.0.0+** and React Native **0.78.0+**
|
|
31
|
+
- `@shopify/react-native-skia` **2.0.0+**
|
|
32
|
+
- `react-native-reanimated` **4.0.0+**
|
|
33
|
+
- `react-native-worklets` **0.5.0+**
|
|
40
34
|
|
|
41
|
-
##
|
|
35
|
+
## Try it
|
|
42
36
|
|
|
43
|
-
|
|
37
|
+
- [Snack](https://snack.expo.dev/@mariops03/react-native-theme-transition) Live playground with the 9 transitions in a browser phone preview.
|
|
38
|
+
- [Docs](https://react-native-theme-transition.vercel.app) API reference, recipes, migration guide.
|
|
44
39
|
|
|
45
40
|
## Installation
|
|
46
41
|
|
|
47
42
|
```bash
|
|
48
|
-
# Expo (SDK 54+
|
|
49
|
-
npx expo install react-native-theme-transition react-native-worklets
|
|
43
|
+
# Expo (SDK 54+)
|
|
44
|
+
npx expo install react-native-theme-transition @shopify/react-native-skia react-native-worklets
|
|
50
45
|
|
|
51
46
|
# React Native CLI
|
|
52
|
-
npm install react-native-theme-transition react-native-
|
|
47
|
+
npm install react-native-theme-transition @shopify/react-native-skia react-native-reanimated react-native-worklets
|
|
53
48
|
```
|
|
54
49
|
|
|
55
|
-
Add `react-native-worklets/plugin` as the **last plugin** in your `babel.config.js`.
|
|
50
|
+
Add `react-native-worklets/plugin` as the **last plugin** in your `babel.config.js`. On Expo SDK 55+, do NOT add `react-native-reanimated/plugin`, since `babel-preset-expo` already includes it.
|
|
56
51
|
|
|
57
|
-
|
|
52
|
+
> Using Claude Code, Cursor, or Codex? Install the [AI-assisted setup](#ai-assisted-setup) skill first and the agent can run the installation from the v2 API reference.
|
|
53
|
+
|
|
54
|
+
## Quick Start
|
|
58
55
|
|
|
59
56
|
```ts
|
|
60
57
|
// theme.ts
|
|
61
|
-
import { createThemeTransition } from 'react-native-theme-transition'
|
|
58
|
+
import { createThemeTransition } from 'react-native-theme-transition'
|
|
62
59
|
|
|
63
60
|
export const { ThemeTransitionProvider, useTheme } = createThemeTransition({
|
|
64
61
|
themes: {
|
|
65
62
|
light: { background: '#ffffff', text: '#000000', primary: '#007AFF' },
|
|
66
63
|
dark: { background: '#000000', text: '#ffffff', primary: '#0A84FF' },
|
|
67
64
|
},
|
|
68
|
-
})
|
|
65
|
+
})
|
|
69
66
|
```
|
|
70
67
|
|
|
71
68
|
```tsx
|
|
72
69
|
// App.tsx
|
|
73
|
-
import { ThemeTransitionProvider } from './theme'
|
|
70
|
+
import { ThemeTransitionProvider } from './theme'
|
|
74
71
|
|
|
75
72
|
export default function App() {
|
|
76
73
|
return (
|
|
77
74
|
<ThemeTransitionProvider initialTheme="system">
|
|
78
75
|
<MyApp />
|
|
79
76
|
</ThemeTransitionProvider>
|
|
80
|
-
)
|
|
77
|
+
)
|
|
81
78
|
}
|
|
82
79
|
```
|
|
83
80
|
|
|
84
81
|
```tsx
|
|
85
82
|
// MyScreen.tsx
|
|
86
|
-
import {
|
|
83
|
+
import { Pressable, Text, View } from 'react-native'
|
|
84
|
+
import { useTheme } from './theme'
|
|
87
85
|
|
|
88
86
|
function MyScreen() {
|
|
89
|
-
const {
|
|
87
|
+
const { theme, setTheme, isTransitioning } = useTheme()
|
|
90
88
|
|
|
91
89
|
return (
|
|
92
|
-
<View style={{ flex: 1, backgroundColor: colors.background }}>
|
|
93
|
-
<Text style={{ color: colors.text }}>Current: {name}</Text>
|
|
90
|
+
<View style={{ flex: 1, backgroundColor: theme.colors.background }}>
|
|
91
|
+
<Text style={{ color: theme.colors.text }}>Current: {theme.name}</Text>
|
|
94
92
|
<Pressable
|
|
95
|
-
onPress={() => setTheme(name === '
|
|
93
|
+
onPress={() => setTheme(theme.name === 'dark' ? 'light' : 'dark', { transition: 'circularReveal' })}
|
|
96
94
|
disabled={isTransitioning}
|
|
97
95
|
>
|
|
98
|
-
<Text style={{ color: colors.primary }}>Toggle
|
|
96
|
+
<Text style={{ color: theme.colors.primary }}>Toggle</Text>
|
|
99
97
|
</Pressable>
|
|
100
98
|
</View>
|
|
101
|
-
)
|
|
99
|
+
)
|
|
102
100
|
}
|
|
103
101
|
```
|
|
104
102
|
|
|
103
|
+
`useTheme()` returns `theme`, `preference`, `setTheme`, and `isTransitioning`. See the [useTheme reference](https://react-native-theme-transition.vercel.app/docs/api/use-theme) for the full API.
|
|
104
|
+
|
|
105
|
+
> Want the agent to write all three files? With the [AI-assisted setup](#ai-assisted-setup) skill installed, Claude Code or Cursor has these steps as a recipe and applies them to your project directly.
|
|
106
|
+
|
|
107
|
+
## AI-assisted setup
|
|
108
|
+
|
|
109
|
+
For agentic coding with Claude Code, Cursor, or Codex, the library ships a skill:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
npx skills add https://skills.sh/marioprieta/skills/react-native-theme-transition
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
It's the same content as the docs site, split into files so the agent can pull the relevant one (api, guides, recipes, examples) instead of loading everything.
|
|
116
|
+
|
|
105
117
|
## Contributing
|
|
106
118
|
|
|
107
|
-
Contributions are welcome
|
|
119
|
+
Contributions are welcome. Please read the [contributing guide](./CONTRIBUTING.md) and open an issue first to discuss what you'd like to change.
|
|
108
120
|
|
|
109
121
|
## License
|
|
110
122
|
|
package/README.npm.md
CHANGED
|
@@ -1,110 +1,122 @@
|
|
|
1
1
|
<h1 align="center">React Native Theme Transition</h1>
|
|
2
2
|
|
|
3
3
|
<p align="center">
|
|
4
|
-
|
|
4
|
+
Nine animated theme transitions for React Native. Skia-powered, runs in Expo Go.
|
|
5
5
|
</p>
|
|
6
6
|
|
|
7
7
|
<p align="center">
|
|
8
8
|
<a href="https://www.npmjs.com/package/react-native-theme-transition"><img src="https://img.shields.io/npm/v/react-native-theme-transition.svg?t=1" alt="npm version" /></a>
|
|
9
|
-
<a href="https://bundlephobia.com/package/react-native-theme-transition"><img src="https://img.shields.io/
|
|
9
|
+
<a href="https://bundlephobia.com/package/react-native-theme-transition"><img src="https://img.shields.io/bundlephobia/minzip/react-native-theme-transition" alt="bundle size" /></a>
|
|
10
10
|
<img src="https://img.shields.io/badge/Expo_Go-compatible-000.svg?logo=expo&logoColor=white" alt="expo compatible" />
|
|
11
11
|
<img src="https://img.shields.io/badge/React_Compiler-compatible-blueviolet.svg" alt="react compiler" />
|
|
12
12
|
<a href="https://github.com/marioprieta/react-native-theme-transition/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/react-native-theme-transition?t=1" alt="license" /></a>
|
|
13
13
|
</p>
|
|
14
14
|
|
|
15
|
-
<
|
|
16
|
-
<
|
|
17
|
-
|
|
18
|
-
<td align="center"><b>Android</b></td>
|
|
19
|
-
</tr>
|
|
20
|
-
<tr>
|
|
21
|
-
<td>
|
|
22
|
-
<img src="https://raw.githubusercontent.com/marioprieta/react-native-theme-transition/main/assets/videos/iOS_demo.gif" width="260" alt="iOS demo" />
|
|
23
|
-
</td>
|
|
24
|
-
<td>
|
|
25
|
-
<img src="https://raw.githubusercontent.com/marioprieta/react-native-theme-transition/main/assets/videos/Android_demo.gif" width="260" alt="Android demo" />
|
|
26
|
-
</td>
|
|
27
|
-
</tr>
|
|
28
|
-
</table>
|
|
15
|
+
<p align="center">
|
|
16
|
+
<img src="https://github.com/user-attachments/assets/32cdd33a-2c79-42f6-b70a-4a4644100683" width="400" alt="React Native Theme Transition demo" />
|
|
17
|
+
</p>
|
|
29
18
|
|
|
30
19
|
## Features
|
|
31
20
|
|
|
32
|
-
- **
|
|
33
|
-
- **Expo Go
|
|
34
|
-
- **
|
|
35
|
-
- **System theme
|
|
36
|
-
- **
|
|
37
|
-
- **
|
|
38
|
-
|
|
39
|
-
|
|
21
|
+
- **Nine transition styles.** `fade`, `circularReveal`, `heart`, `star`, `wipe`, `slide`, `split`, `pixelize`, `dissolve`.
|
|
22
|
+
- **Expo Go ready.** Works on Expo SDK 54+ out of the box. Bare React Native CLI also supported.
|
|
23
|
+
- **Full TypeScript inference.** `useTheme()` and `setTheme()` know your theme names and color tokens without manual generics.
|
|
24
|
+
- **System theme built in.** Follows OS appearance with zero-flash startup.
|
|
25
|
+
- **Strict runtime validation.** Invalid options throw immediately with clear error messages.
|
|
26
|
+
- **React Compiler compatible.** All hooks follow the [Rules of React](https://react.dev/reference/rules).
|
|
27
|
+
|
|
28
|
+
## Requirements
|
|
29
|
+
|
|
30
|
+
- React **19.0.0+** and React Native **0.78.0+**
|
|
31
|
+
- `@shopify/react-native-skia` **2.0.0+**
|
|
32
|
+
- `react-native-reanimated` **4.0.0+**
|
|
33
|
+
- `react-native-worklets` **0.5.0+**
|
|
40
34
|
|
|
41
|
-
##
|
|
35
|
+
## Try it
|
|
42
36
|
|
|
43
|
-
|
|
37
|
+
- [Snack](https://snack.expo.dev/@mariops03/react-native-theme-transition) Live playground with the 9 transitions in a browser phone preview.
|
|
38
|
+
- [Docs](https://react-native-theme-transition.vercel.app) API reference, recipes, migration guide.
|
|
44
39
|
|
|
45
40
|
## Installation
|
|
46
41
|
|
|
47
42
|
```bash
|
|
48
|
-
# Expo (SDK 54+
|
|
49
|
-
npx expo install react-native-theme-transition react-native-worklets
|
|
43
|
+
# Expo (SDK 54+)
|
|
44
|
+
npx expo install react-native-theme-transition @shopify/react-native-skia react-native-worklets
|
|
50
45
|
|
|
51
46
|
# React Native CLI
|
|
52
|
-
npm install react-native-theme-transition react-native-
|
|
47
|
+
npm install react-native-theme-transition @shopify/react-native-skia react-native-reanimated react-native-worklets
|
|
53
48
|
```
|
|
54
49
|
|
|
55
|
-
Add `react-native-worklets/plugin` as the **last plugin** in your `babel.config.js`.
|
|
50
|
+
Add `react-native-worklets/plugin` as the **last plugin** in your `babel.config.js`. On Expo SDK 55+, do NOT add `react-native-reanimated/plugin`, since `babel-preset-expo` already includes it.
|
|
56
51
|
|
|
57
|
-
|
|
52
|
+
> Using Claude Code, Cursor, or Codex? Install the [AI-assisted setup](#ai-assisted-setup) skill first and the agent can run the installation from the v2 API reference.
|
|
53
|
+
|
|
54
|
+
## Quick Start
|
|
58
55
|
|
|
59
56
|
```ts
|
|
60
57
|
// theme.ts
|
|
61
|
-
import { createThemeTransition } from 'react-native-theme-transition'
|
|
58
|
+
import { createThemeTransition } from 'react-native-theme-transition'
|
|
62
59
|
|
|
63
60
|
export const { ThemeTransitionProvider, useTheme } = createThemeTransition({
|
|
64
61
|
themes: {
|
|
65
62
|
light: { background: '#ffffff', text: '#000000', primary: '#007AFF' },
|
|
66
63
|
dark: { background: '#000000', text: '#ffffff', primary: '#0A84FF' },
|
|
67
64
|
},
|
|
68
|
-
})
|
|
65
|
+
})
|
|
69
66
|
```
|
|
70
67
|
|
|
71
68
|
```tsx
|
|
72
69
|
// App.tsx
|
|
73
|
-
import { ThemeTransitionProvider } from './theme'
|
|
70
|
+
import { ThemeTransitionProvider } from './theme'
|
|
74
71
|
|
|
75
72
|
export default function App() {
|
|
76
73
|
return (
|
|
77
74
|
<ThemeTransitionProvider initialTheme="system">
|
|
78
75
|
<MyApp />
|
|
79
76
|
</ThemeTransitionProvider>
|
|
80
|
-
)
|
|
77
|
+
)
|
|
81
78
|
}
|
|
82
79
|
```
|
|
83
80
|
|
|
84
81
|
```tsx
|
|
85
82
|
// MyScreen.tsx
|
|
86
|
-
import {
|
|
83
|
+
import { Pressable, Text, View } from 'react-native'
|
|
84
|
+
import { useTheme } from './theme'
|
|
87
85
|
|
|
88
86
|
function MyScreen() {
|
|
89
|
-
const {
|
|
87
|
+
const { theme, setTheme, isTransitioning } = useTheme()
|
|
90
88
|
|
|
91
89
|
return (
|
|
92
|
-
<View style={{ flex: 1, backgroundColor: colors.background }}>
|
|
93
|
-
<Text style={{ color: colors.text }}>Current: {name}</Text>
|
|
90
|
+
<View style={{ flex: 1, backgroundColor: theme.colors.background }}>
|
|
91
|
+
<Text style={{ color: theme.colors.text }}>Current: {theme.name}</Text>
|
|
94
92
|
<Pressable
|
|
95
|
-
onPress={() => setTheme(name === '
|
|
93
|
+
onPress={() => setTheme(theme.name === 'dark' ? 'light' : 'dark', { transition: 'circularReveal' })}
|
|
96
94
|
disabled={isTransitioning}
|
|
97
95
|
>
|
|
98
|
-
<Text style={{ color: colors.primary }}>Toggle
|
|
96
|
+
<Text style={{ color: theme.colors.primary }}>Toggle</Text>
|
|
99
97
|
</Pressable>
|
|
100
98
|
</View>
|
|
101
|
-
)
|
|
99
|
+
)
|
|
102
100
|
}
|
|
103
101
|
```
|
|
104
102
|
|
|
103
|
+
`useTheme()` returns `theme`, `preference`, `setTheme`, and `isTransitioning`. See the [useTheme reference](https://react-native-theme-transition.vercel.app/docs/api/use-theme) for the full API.
|
|
104
|
+
|
|
105
|
+
> Want the agent to write all three files? With the [AI-assisted setup](#ai-assisted-setup) skill installed, Claude Code or Cursor has these steps as a recipe and applies them to your project directly.
|
|
106
|
+
|
|
107
|
+
## AI-assisted setup
|
|
108
|
+
|
|
109
|
+
For agentic coding with Claude Code, Cursor, or Codex, the library ships a skill:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
npx skills add https://skills.sh/marioprieta/skills/react-native-theme-transition
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
It's the same content as the docs site, split into files so the agent can pull the relevant one (api, guides, recipes, examples) instead of loading everything.
|
|
116
|
+
|
|
105
117
|
## Contributing
|
|
106
118
|
|
|
107
|
-
Contributions are welcome
|
|
119
|
+
Contributions are welcome. Please read the [contributing guide](./CONTRIBUTING.md) and open an issue first to discuss what you'd like to change.
|
|
108
120
|
|
|
109
121
|
## License
|
|
110
122
|
|
package/dist/constants.d.ts
CHANGED
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":""}
|
package/dist/constants.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
/** Log/error prefix shared across the package. @internal */
|
|
2
2
|
export const TAG = '[react-native-theme-transition]';
|
|
3
|
+
/** Absolute fill style for overlays. @internal */
|
|
4
|
+
export const ABSOLUTE_FILL = { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 };
|
|
5
|
+
/** Flex fill for the provider's root and inner wrappers. @internal */
|
|
6
|
+
export const FLEX_FILL = { flex: 1 };
|
|
3
7
|
//# sourceMappingURL=constants.js.map
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,MAAM,CAAC,MAAM,GAAG,GAAG,iCAAiC,CAAA"}
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,MAAM,CAAC,MAAM,GAAG,GAAG,iCAAiC,CAAA;AAEpD,kDAAkD;AAClD,MAAM,CAAC,MAAM,aAAa,GAAG,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAW,CAAA;AAEpG,sEAAsE;AACtE,MAAM,CAAC,MAAM,SAAS,GAAG,EAAE,IAAI,EAAE,CAAC,EAAW,CAAA"}
|
|
@@ -1,28 +1,16 @@
|
|
|
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
|
import type { ThemeDefinition, ThemeTransitionAPI, ThemeTransitionConfig } from './types';
|
|
13
7
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* @typeParam T - Your application's theme map, keyed by theme name.
|
|
17
|
-
* @param config - Theme configuration including available themes and defaults.
|
|
18
|
-
* @returns A provider component and hooks scoped to the supplied themes.
|
|
8
|
+
* Builds a fully typed theme transition system from a map of themes.
|
|
19
9
|
*
|
|
20
|
-
* @
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* });
|
|
25
|
-
* ```
|
|
10
|
+
* @param config - Theme configuration.
|
|
11
|
+
* @returns A {@link ThemeTransitionAPI} bound to the supplied themes.
|
|
12
|
+
* @throws Error on invalid configuration.
|
|
13
|
+
* @see https://react-native-theme-transition.vercel.app/docs/api/create-theme-transition
|
|
26
14
|
*/
|
|
27
15
|
export declare function createThemeTransition<T extends Record<string, ThemeDefinition>>(config: ThemeTransitionConfig<T>): ThemeTransitionAPI<T>;
|
|
28
16
|
//# sourceMappingURL=createThemeTransition.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createThemeTransition.d.ts","sourceRoot":"","sources":["../src/createThemeTransition.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"createThemeTransition.d.ts","sourceRoot":"","sources":["../src/createThemeTransition.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,OAAO,KAAK,EACV,eAAe,EAEf,kBAAkB,EAClB,qBAAqB,EAGtB,MAAM,SAAS,CAAA;AAEhB;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,EAC7E,MAAM,EAAE,qBAAqB,CAAC,CAAC,CAAC,GAC/B,kBAAkB,CAAC,CAAC,CAAC,CAiFvB"}
|
|
@@ -1,38 +1,27 @@
|
|
|
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
|
*/
|
|
6
|
+
import { use } from 'react';
|
|
12
7
|
import { TAG } from './constants';
|
|
13
|
-
import { createUseTheme } from './hooks/useTheme';
|
|
14
8
|
import { createProviderAndContext } from './transitionEngine';
|
|
9
|
+
import { TRANSITION_TYPES } from './transitionMeta';
|
|
15
10
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* @typeParam T - Your application's theme map, keyed by theme name.
|
|
19
|
-
* @param config - Theme configuration including available themes and defaults.
|
|
20
|
-
* @returns A provider component and hooks scoped to the supplied themes.
|
|
11
|
+
* Builds a fully typed theme transition system from a map of themes.
|
|
21
12
|
*
|
|
22
|
-
* @
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* });
|
|
27
|
-
* ```
|
|
13
|
+
* @param config - Theme configuration.
|
|
14
|
+
* @returns A {@link ThemeTransitionAPI} bound to the supplied themes.
|
|
15
|
+
* @throws Error on invalid configuration.
|
|
16
|
+
* @see https://react-native-theme-transition.vercel.app/docs/api/create-theme-transition
|
|
28
17
|
*/
|
|
29
18
|
export function createThemeTransition(config) {
|
|
30
19
|
const themeNames = Object.keys(config.themes);
|
|
31
20
|
if (themeNames.length === 0) {
|
|
32
21
|
throw new Error(`${TAG} \`themes\` must contain at least one theme.`);
|
|
33
22
|
}
|
|
34
|
-
if ('system'
|
|
35
|
-
throw new Error(`${TAG} \`"system"\` is a reserved name and cannot be used as a theme key
|
|
23
|
+
if (Object.hasOwn(config.themes, 'system')) {
|
|
24
|
+
throw new Error(`${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.`);
|
|
36
25
|
}
|
|
37
26
|
const referenceTheme = themeNames[0];
|
|
38
27
|
const referenceKeys = Object.keys(config.themes[referenceTheme]).sort();
|
|
@@ -41,29 +30,42 @@ export function createThemeTransition(config) {
|
|
|
41
30
|
continue;
|
|
42
31
|
const keys = Object.keys(config.themes[name]).sort();
|
|
43
32
|
if (keys.length !== referenceKeys.length || keys.some((k, i) => k !== referenceKeys[i])) {
|
|
44
|
-
throw new Error(`${TAG} Theme "${name}" has different token keys than "${referenceTheme}"
|
|
33
|
+
throw new Error(`${TAG} Theme "${name}" has different token keys than "${referenceTheme}".\n Hint: every theme must share identical token keys.`);
|
|
45
34
|
}
|
|
46
35
|
}
|
|
47
|
-
if (config.
|
|
48
|
-
(
|
|
49
|
-
!Number.isFinite(config.duration) ||
|
|
50
|
-
config.duration < 0)) {
|
|
51
|
-
throw new Error(`${TAG} \`duration\` must be a finite non-negative number.`);
|
|
36
|
+
if (config.transition != null && !TRANSITION_TYPES.includes(config.transition)) {
|
|
37
|
+
throw new Error(`${TAG} \`transition\` must be one of: ${TRANSITION_TYPES.join(', ')}. Got "${config.transition}".`);
|
|
52
38
|
}
|
|
39
|
+
const assertThemeExists = (name, source, hint) => {
|
|
40
|
+
if (!Object.hasOwn(config.themes, name)) {
|
|
41
|
+
throw new Error(`${TAG} ${source} refers to "${name}" which does not exist in themes.\n Hint: ${hint}`);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
53
44
|
if (config.systemThemeMap) {
|
|
54
|
-
if (!(
|
|
45
|
+
if (!Object.hasOwn(config.systemThemeMap, 'light') ||
|
|
46
|
+
!Object.hasOwn(config.systemThemeMap, 'dark')) {
|
|
55
47
|
throw new Error(`${TAG} \`systemThemeMap\` must provide both \`light\` and \`dark\` keys.`);
|
|
56
48
|
}
|
|
57
49
|
for (const [scheme, name] of Object.entries(config.systemThemeMap)) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
50
|
+
assertThemeExists(name, `\`systemThemeMap.${scheme}\``, 'the value must match a key in `themes`.');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (config.darkThemes) {
|
|
54
|
+
if (config.darkThemes.length === 0) {
|
|
55
|
+
throw new Error(`${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.`);
|
|
56
|
+
}
|
|
57
|
+
for (const name of config.darkThemes) {
|
|
58
|
+
assertThemeExists(name, '`darkThemes`', 'every entry in `darkThemes` must match a key in `themes`.');
|
|
61
59
|
}
|
|
62
60
|
}
|
|
63
61
|
const { Context, ThemeTransitionProvider } = createProviderAndContext(config);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
function useTheme() {
|
|
63
|
+
const ctx = use(Context);
|
|
64
|
+
if (!ctx) {
|
|
65
|
+
throw new Error(`${TAG} \`useTheme\` must be used inside a \`ThemeTransitionProvider\`.`);
|
|
66
|
+
}
|
|
67
|
+
return ctx;
|
|
68
|
+
}
|
|
69
|
+
return { ThemeTransitionProvider, useTheme };
|
|
68
70
|
}
|
|
69
71
|
//# sourceMappingURL=createThemeTransition.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createThemeTransition.js","sourceRoot":"","sources":["../src/createThemeTransition.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"createThemeTransition.js","sourceRoot":"","sources":["../src/createThemeTransition.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAC3B,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACjC,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAA;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAUnD;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CACnC,MAAgC;IAEhC,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAoB,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C,OAAO,CAAC,CAAA;QACxB,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,MAAM,IAAI,KAAK,CAAC,GAAG,GAAG,kEAAkE,CAAC,CAAA;QAC3F,CAAC;QACD,OAAO,GAAG,CAAA;IACZ,CAAC;IAED,OAAO,EAAE,uBAAuB,EAAE,QAAQ,EAAE,CAAA;AAC9C,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,17 +2,17 @@
|
|
|
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
|
export { createThemeTransition } from './createThemeTransition';
|
|
17
|
-
export
|
|
16
|
+
export { TRANSITION_META, TRANSITION_TYPES } from './transitionMeta';
|
|
17
|
+
export type { ColorScheme, OriginSpec, SetThemeOptions, SystemThemeMap, ThemeDefinition, ThemeNames, ThemeTransitionAPI, ThemeTransitionConfig, TokenNames, TransitionOrigin, TransitionType, UseThemeResult, } from './types';
|
|
18
18
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAC/D,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAEpE,YAAY,EACV,WAAW,EACX,UAAU,EACV,eAAe,EACf,cAAc,EACd,eAAe,EACf,UAAU,EACV,kBAAkB,EAClB,qBAAqB,EACrB,UAAU,EACV,gBAAgB,EAChB,cAAc,EACd,cAAc,GACf,MAAM,SAAS,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -2,16 +2,16 @@
|
|
|
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
|
export { createThemeTransition } from './createThemeTransition';
|
|
16
|
+
export { TRANSITION_META, TRANSITION_TYPES } from './transitionMeta';
|
|
17
17
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAC/D,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skia-powered overlay for theme transitions.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Top-level `SkiaOverlay` keeps a `<Canvas>` permanently mounted (so
|
|
6
|
+
* starting a transition never pays for a native-view layout pass on
|
|
7
|
+
* Android) and dispatches to a per-mode component that owns the
|
|
8
|
+
* `useDerivedValue` hooks for that mode only. The active mode's hooks
|
|
9
|
+
* mount when the transition starts and unmount when it ends. `fade`
|
|
10
|
+
* never pays for `slide`'s slot machine, `pixelize` never pays for
|
|
11
|
+
* `heart`'s path interpolation, etc.
|
|
12
|
+
*
|
|
13
|
+
* @module
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=SkiaOverlay.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SkiaOverlay.d.ts","sourceRoot":"","sources":["../../src/overlay/SkiaOverlay.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG"}
|