react-native-theme-transition 1.0.6 → 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 +279 -208
- 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 +390 -247
- 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
|
@@ -1,24 +1,55 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Provider and context for the theme transition engine.
|
|
3
3
|
*
|
|
4
4
|
* @remarks
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Capture and overlay both use `@shopify/react-native-skia`; a single
|
|
6
|
+
* 0 → 1 `progress` shared value drives every transition kind. The
|
|
7
|
+
* library is policy-free about OS Reduce Motion. Consumers who want
|
|
8
|
+
* to honor it pass `animated: false` per call.
|
|
8
9
|
*
|
|
9
|
-
*
|
|
10
|
-
|
|
11
|
-
import type { ThemeDefinition, ThemeNames, ThemeTransitionConfig, TokenNames, UseThemeResult } from './types';
|
|
12
|
-
/**
|
|
13
|
-
* Creates the React Context and provider component for a given theme configuration.
|
|
10
|
+
* **State machine.** Each animated transition runs the following steps
|
|
11
|
+
* in order:
|
|
14
12
|
*
|
|
15
|
-
*
|
|
13
|
+
* 1. `setTheme`: sync writes (`transitioningRef`, `isBlocking`,
|
|
14
|
+
* `intendedThemeRef`, `preference`) so picker UIs repaint before
|
|
15
|
+
* capture. `runTransition` is kicked off async and the config and
|
|
16
|
+
* per-call `onTransitionStart` callbacks fire.
|
|
17
|
+
* 2. **`SETTLE.beforeCapture`**: wait one frame so React has flushed
|
|
18
|
+
* the sync writes and any pressed-state repaints made it to screen
|
|
19
|
+
* before the snapshot is taken.
|
|
20
|
+
* 3. **Capture old**: `captureView` grabs a CPU-backed `SkImage` of the
|
|
21
|
+
* inner tree. If capture fails, the engine falls back to an instant
|
|
22
|
+
* swap (no overlay, only `onThemeChange` fires).
|
|
23
|
+
* 4. **Commit 1**: `setOverlayParams` + `setSkImage` mount the snapshot
|
|
24
|
+
* on the pre-mounted Canvas.
|
|
25
|
+
* 5. **`SETTLE.skiaPaint`**: wait so Skia paints the snapshot before
|
|
26
|
+
* the inner tree swaps its colors. Otherwise the new theme flashes
|
|
27
|
+
* through on Android.
|
|
28
|
+
* 6. **Commit 2**: `setIsTransitioning(true)` + `setActiveTheme(new)`
|
|
29
|
+
* swap the inner tree underneath the now-covering overlay.
|
|
30
|
+
* 7. **`SETTLE.treeRepaint` (conditional)**: for reveal, shape, and
|
|
31
|
+
* dual-image transitions, wait an extra frame so the inner tree
|
|
32
|
+
* has repainted in the new theme before the second capture.
|
|
33
|
+
* 8. **Capture new (conditional)**: for `slide` and `pixelize`
|
|
34
|
+
* (`TRANSITION_META[kind].capturesNew === true`), capture a second
|
|
35
|
+
* snapshot of the inner tree in the new theme and mount it as
|
|
36
|
+
* `imageNew` on the overlay.
|
|
37
|
+
* 9. **Animate**: Reanimated animates `progress` 0 → 1 and a
|
|
38
|
+
* `setTimeout(duration)` fires the `finish` cleanup, which resets
|
|
39
|
+
* the overlay and fires `onTransitionEnd` (config and per-call) and
|
|
40
|
+
* `onThemeChange`. If the OS appearance changed while in `'system'`
|
|
41
|
+
* mode during the transition, the pending correction fires a
|
|
42
|
+
* second `onThemeChange`.
|
|
43
|
+
*
|
|
44
|
+
* **Why the SkiaOverlay stays permanently mounted:** Android paints a
|
|
45
|
+
* fresh native view at the same commit it gains content; if the Canvas
|
|
46
|
+
* mounted at commit 1, its first paint would be empty and the
|
|
47
|
+
* already-swapped inner tree would flash the new theme through for one
|
|
48
|
+
* frame. Keeping the Canvas mounted with `image={null}` between
|
|
49
|
+
* transitions avoids the layout pass entirely.
|
|
50
|
+
*
|
|
51
|
+
* @module
|
|
52
|
+
* @internal
|
|
16
53
|
*/
|
|
17
|
-
export
|
|
18
|
-
Context: import("react").Context<UseThemeResult<TokenNames<T>, ThemeNames<T>> | null>;
|
|
19
|
-
ThemeTransitionProvider: ({ children, initialTheme, }: {
|
|
20
|
-
children: React.ReactNode;
|
|
21
|
-
initialTheme: ThemeNames<T> | "system";
|
|
22
|
-
}) => import("react/jsx-runtime").JSX.Element;
|
|
23
|
-
};
|
|
54
|
+
export {};
|
|
24
55
|
//# sourceMappingURL=transitionEngine.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transitionEngine.d.ts","sourceRoot":"","sources":["../src/transitionEngine.tsx"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"transitionEngine.d.ts","sourceRoot":"","sources":["../src/transitionEngine.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG"}
|