react-native-theme-transition 1.0.4 → 1.0.6

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/src/types.ts CHANGED
@@ -6,23 +6,21 @@
6
6
  * `"textPrimary"`) and values are color strings accepted by React Native
7
7
  * (hex, rgb, rgba, named colors).
8
8
  */
9
- export type ThemeDefinition = Record<string, string>;
9
+ export type ThemeDefinition = Record<string, string>
10
10
 
11
11
  /**
12
12
  * Union of theme names available in a theme configuration.
13
13
  *
14
14
  * @typeParam T - Your application's theme map, keyed by theme name.
15
15
  */
16
- export type ThemeNames<T extends Record<string, ThemeDefinition>> =
17
- keyof T & string;
16
+ export type ThemeNames<T extends Record<string, ThemeDefinition>> = keyof T & string
18
17
 
19
18
  /**
20
19
  * Union of token names shared across all themes in a configuration.
21
20
  *
22
21
  * @typeParam T - Your application's theme map, keyed by theme name.
23
22
  */
24
- export type TokenNames<T extends Record<string, ThemeDefinition>> =
25
- keyof T[ThemeNames<T>] & string;
23
+ export type TokenNames<T extends Record<string, ThemeDefinition>> = keyof T[ThemeNames<T>] & string
26
24
 
27
25
  /**
28
26
  * Maps OS color schemes (`'light'` / `'dark'`) to theme names.
@@ -33,8 +31,7 @@ export type TokenNames<T extends Record<string, ThemeDefinition>> =
33
31
  *
34
32
  * @typeParam Names - Union of theme name strings.
35
33
  */
36
- export type SystemThemeMap<Names extends string> =
37
- Record<'light' | 'dark', Names>;
34
+ export type SystemThemeMap<Names extends string> = Record<'light' | 'dark', Names>
38
35
 
39
36
  /**
40
37
  * Configuration for {@link createThemeTransition}.
@@ -50,13 +47,13 @@ export interface ThemeTransitionConfig<T extends Record<string, ThemeDefinition>
50
47
  * cause a runtime error at initialization.
51
48
  * The name `'system'` is reserved and cannot be used as a theme name.
52
49
  */
53
- themes: T;
50
+ themes: T
54
51
 
55
52
  /**
56
53
  * Cross-fade duration in milliseconds.
57
54
  * @default 350
58
55
  */
59
- duration?: number;
56
+ duration?: number
60
57
 
61
58
  /**
62
59
  * Maps OS appearance (`'light'` / `'dark'`) to theme names.
@@ -66,7 +63,7 @@ export interface ThemeTransitionConfig<T extends Record<string, ThemeDefinition>
66
63
  * and you want to use `initialTheme="system"` or `setTheme('system')`.
67
64
  * Both `light` and `dark` must be provided.
68
65
  */
69
- systemThemeMap?: SystemThemeMap<ThemeNames<T>>;
66
+ systemThemeMap?: SystemThemeMap<ThemeNames<T>>
70
67
 
71
68
  /**
72
69
  * Theme names that use a dark color scheme.
@@ -82,7 +79,7 @@ export interface ThemeTransitionConfig<T extends Record<string, ThemeDefinition>
82
79
  *
83
80
  * @default `[systemThemeMap.dark]` if `systemThemeMap` is provided, otherwise `['dark']`.
84
81
  */
85
- darkThemes?: ThemeNames<T>[];
82
+ darkThemes?: ThemeNames<T>[]
86
83
 
87
84
  /**
88
85
  * Called when an animated transition begins, before the screenshot capture.
@@ -93,7 +90,7 @@ export interface ThemeTransitionConfig<T extends Record<string, ThemeDefinition>
93
90
  *
94
91
  * @param themeName - The target theme name.
95
92
  */
96
- onTransitionStart?: (themeName: ThemeNames<T>) => void;
93
+ onTransitionStart?: (themeName: ThemeNames<T>) => void
97
94
 
98
95
  /**
99
96
  * Called after an animated transition completes and the overlay is removed.
@@ -109,7 +106,7 @@ export interface ThemeTransitionConfig<T extends Record<string, ThemeDefinition>
109
106
  *
110
107
  * @param themeName - The newly active theme name.
111
108
  */
112
- onTransitionEnd?: (themeName: ThemeNames<T>) => void;
109
+ onTransitionEnd?: (themeName: ThemeNames<T>) => void
113
110
 
114
111
  /**
115
112
  * Called whenever the active theme changes.
@@ -121,7 +118,7 @@ export interface ThemeTransitionConfig<T extends Record<string, ThemeDefinition>
121
118
  *
122
119
  * @param themeName - The newly active theme name.
123
120
  */
124
- onThemeChange?: (themeName: ThemeNames<T>) => void;
121
+ onThemeChange?: (themeName: ThemeNames<T>) => void
125
122
  }
126
123
 
127
124
  /**
@@ -139,7 +136,7 @@ export interface SetThemeOptions<Names extends string = string> {
139
136
  *
140
137
  * @default true
141
138
  */
142
- animated?: boolean;
139
+ animated?: boolean
143
140
 
144
141
  /**
145
142
  * Called when the animated transition begins, before the screenshot capture.
@@ -150,7 +147,7 @@ export interface SetThemeOptions<Names extends string = string> {
150
147
  *
151
148
  * @param themeName - The target theme name.
152
149
  */
153
- onTransitionStart?: (themeName: Names) => void;
150
+ onTransitionStart?: (themeName: Names) => void
154
151
 
155
152
  /**
156
153
  * Called after the animated transition completes and the overlay is removed.
@@ -165,7 +162,7 @@ export interface SetThemeOptions<Names extends string = string> {
165
162
  *
166
163
  * @param themeName - The newly active theme name.
167
164
  */
168
- onTransitionEnd?: (themeName: Names) => void;
165
+ onTransitionEnd?: (themeName: Names) => void
169
166
  }
170
167
 
171
168
  /**
@@ -174,14 +171,11 @@ export interface SetThemeOptions<Names extends string = string> {
174
171
  * @typeParam Tokens - Union of token name strings.
175
172
  * @typeParam Names - Union of theme name strings.
176
173
  */
177
- export interface UseThemeResult<
178
- Tokens extends string,
179
- Names extends string,
180
- > {
174
+ export interface UseThemeResult<Tokens extends string, Names extends string> {
181
175
  /** Current resolved color values for all tokens. */
182
- colors: Record<Tokens, string>;
176
+ colors: Record<Tokens, string>
183
177
  /** Name of the currently active theme (resolved, never `'system'`). */
184
- name: Names;
178
+ name: Names
185
179
  /**
186
180
  * Switch to a new theme or enter system mode.
187
181
  *
@@ -190,9 +184,9 @@ export interface UseThemeResult<
190
184
  * @returns `true` if the theme change was accepted, `false` if rejected
191
185
  * (already transitioning or same theme).
192
186
  */
193
- setTheme: (name: Names | 'system', options?: SetThemeOptions<Names>) => boolean;
187
+ setTheme: (name: Names | 'system', options?: SetThemeOptions<Names>) => boolean
194
188
  /** `true` while a cross-fade transition overlay is visible. */
195
- isTransitioning: boolean;
189
+ isTransitioning: boolean
196
190
  }
197
191
 
198
192
  /**
@@ -203,7 +197,7 @@ export interface UseThemeResult<
203
197
  */
204
198
  export interface ThemeSelectionResult<Names extends string> {
205
199
  /** The currently selected option (may be `'system'`). */
206
- selected: Names | 'system';
200
+ selected: Names | 'system'
207
201
  /**
208
202
  * Select a theme with transition-safe timing.
209
203
  *
@@ -215,7 +209,7 @@ export interface ThemeSelectionResult<Names extends string> {
215
209
  *
216
210
  * @param option - Theme name or `'system'`.
217
211
  */
218
- select: (option: Names | 'system') => void;
212
+ select: (option: Names | 'system') => void
219
213
  }
220
214
 
221
215
  /**
@@ -232,7 +226,7 @@ export interface ThemeTransitionAPI<T extends Record<string, ThemeDefinition>> {
232
226
  * navigation) so the screenshot can capture the entire screen.
233
227
  */
234
228
  ThemeTransitionProvider: React.FC<{
235
- children: React.ReactNode;
229
+ children: React.ReactNode
236
230
  /**
237
231
  * Theme to render on the first frame.
238
232
  *
@@ -241,8 +235,8 @@ export interface ThemeTransitionAPI<T extends Record<string, ThemeDefinition>> {
241
235
  * and subscribe to changes. For custom theme names, provide
242
236
  * {@link ThemeTransitionConfig.systemThemeMap | systemThemeMap} in the config.
243
237
  */
244
- initialTheme: ThemeNames<T> | 'system';
245
- }>;
238
+ initialTheme: ThemeNames<T> | 'system'
239
+ }>
246
240
 
247
241
  /**
248
242
  * Hook returning the current theme state and transition controls.
@@ -294,11 +288,13 @@ export interface ThemeTransitionAPI<T extends Record<string, ThemeDefinition>> {
294
288
  */
295
289
  useTheme: {
296
290
  /** Returns current theme state and controls. */
297
- (): UseThemeResult<TokenNames<T>, ThemeNames<T>>;
291
+ (): UseThemeResult<TokenNames<T>, ThemeNames<T>>
298
292
  /**
299
293
  * Returns theme state, controls, and selection tracking with transition-safe timing.
300
294
  * @param options.initialSelection - Starting value for `selected`. Defaults to the current theme name.
301
295
  */
302
- (options: { initialSelection?: ThemeNames<T> | 'system' }): UseThemeResult<TokenNames<T>, ThemeNames<T>> & ThemeSelectionResult<ThemeNames<T>>;
303
- };
296
+ (options: {
297
+ initialSelection?: ThemeNames<T> | 'system'
298
+ }): UseThemeResult<TokenNames<T>, ThemeNames<T>> & ThemeSelectionResult<ThemeNames<T>>
299
+ }
304
300
  }