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
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Origin resolution for transitions that emanate from a point
|
|
3
|
+
* (`circularReveal`, `heart`, `star`).
|
|
4
|
+
* @module
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { View } from 'react-native'
|
|
9
|
+
import type { OriginSpec, TransitionOrigin } from '../types'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Measures the center point of a View ref. Returns `null` if the ref is
|
|
13
|
+
* unmounted or `measure` throws.
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* `measure` invokes its callback asynchronously on Paper but synchronously on
|
|
17
|
+
* Fabric, because Fabric reaches the Shadow Tree without a bridge hop. v2's
|
|
18
|
+
* peer deps (`react-native >= 0.78.0`, `@shopify/react-native-skia >= 2.0.0`)
|
|
19
|
+
* both require Fabric, so the callback runs before `measure` returns and
|
|
20
|
+
* `result` is already set at the return site. Paper is not a supported target.
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export function measureCenter(ref: React.RefObject<View | null>): TransitionOrigin | null {
|
|
25
|
+
if (!ref.current) return null
|
|
26
|
+
try {
|
|
27
|
+
let result: TransitionOrigin | null = null
|
|
28
|
+
ref.current.measure(
|
|
29
|
+
(_x: number, _y: number, w: number, h: number, pageX: number, pageY: number) => {
|
|
30
|
+
result = { x: pageX + w / 2, y: pageY + h / 2 }
|
|
31
|
+
},
|
|
32
|
+
)
|
|
33
|
+
return result
|
|
34
|
+
} catch {
|
|
35
|
+
return null
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Type guard: is this `OriginSpec` a ref rather than a `{x,y}` point? @internal */
|
|
40
|
+
export function isOriginRef(value: OriginSpec): value is React.RefObject<View | null> {
|
|
41
|
+
return 'current' in value
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Resolves an {@link OriginSpec} (point or ref) to concrete coordinates.
|
|
46
|
+
* Falls back to the screen center if `origin` is missing or the ref
|
|
47
|
+
* measurement fails.
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
50
|
+
export function resolveOrigin(
|
|
51
|
+
origin: OriginSpec | undefined,
|
|
52
|
+
screenWidth: number,
|
|
53
|
+
screenHeight: number,
|
|
54
|
+
): TransitionOrigin {
|
|
55
|
+
if (origin) {
|
|
56
|
+
if (isOriginRef(origin)) {
|
|
57
|
+
const measured = measureCenter(origin)
|
|
58
|
+
if (measured) return measured
|
|
59
|
+
} else {
|
|
60
|
+
return origin
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return { x: screenWidth / 2, y: screenHeight / 2 }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Radius from `origin` to the farthest screen corner.
|
|
68
|
+
*
|
|
69
|
+
* @remarks
|
|
70
|
+
* A circular reveal with this radius is guaranteed to fully cover the
|
|
71
|
+
* screen at the end frame.
|
|
72
|
+
* @internal
|
|
73
|
+
*/
|
|
74
|
+
export function calculateMaxRadius(
|
|
75
|
+
ox: number,
|
|
76
|
+
oy: number,
|
|
77
|
+
screenWidth: number,
|
|
78
|
+
screenHeight: number,
|
|
79
|
+
): number {
|
|
80
|
+
return Math.hypot(Math.max(ox, screenWidth - ox), Math.max(oy, screenHeight - oy))
|
|
81
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal types and defaults for the Skia overlay pipeline.
|
|
3
|
+
*
|
|
4
|
+
* `OverlayParams` is the frozen snapshot of a single transition's
|
|
5
|
+
* parameters, constructed by the engine in `runTransition` and
|
|
6
|
+
* consumed by `SkiaOverlay`. Everything the overlay needs to render a
|
|
7
|
+
* single animation lives here, so rotation / orientation changes
|
|
8
|
+
* mid-transition can't drift between the engine's measurements and the
|
|
9
|
+
* overlay's render.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import type { SplitMode, TransitionType, WipeDirection } from '../transitionMeta'
|
|
16
|
+
|
|
17
|
+
/** @internal Render mode for the overlay. Distinct from `TransitionType`
|
|
18
|
+
* because the overlay speaks in "how to render", not "which user-facing
|
|
19
|
+
* transition was picked". Currently 1:1 with `TransitionType`. */
|
|
20
|
+
export interface OverlayParams {
|
|
21
|
+
mode: TransitionType
|
|
22
|
+
origin: { x: number; y: number }
|
|
23
|
+
maxRadius: number
|
|
24
|
+
screenWidth: number
|
|
25
|
+
screenHeight: number
|
|
26
|
+
inverted: boolean
|
|
27
|
+
direction: WipeDirection
|
|
28
|
+
splitMode: SplitMode
|
|
29
|
+
blockSize: number
|
|
30
|
+
noiseSize: number
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @internal Pixelize shader fallback block size in points. 52 tuned
|
|
35
|
+
* empirically on a 390pt-wide viewport: large enough to fully dissolve
|
|
36
|
+
* face-level detail at the peak of the animation, small enough to avoid
|
|
37
|
+
* obvious banding on smaller devices.
|
|
38
|
+
*/
|
|
39
|
+
export const DEFAULT_PIXELIZE_BLOCK_SIZE = 52
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @internal Dissolve shader fallback noise cell size in points. 5 reads
|
|
43
|
+
* as visible grain without collapsing into chunky tiles on hi-DPI
|
|
44
|
+
* screens. Smaller values approach per-pixel noise.
|
|
45
|
+
*/
|
|
46
|
+
export const DEFAULT_DISSOLVE_NOISE_SIZE = 5
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @internal Wipe/slide fallback direction. `'right'` matches the LTR
|
|
50
|
+
* reading order where new content flows in from the left and progresses
|
|
51
|
+
* rightward. The mental model: `setTheme(x, { direction: 'right' })`
|
|
52
|
+
* means the new theme enters from the left edge. RTL-aware flipping
|
|
53
|
+
* is left to the consumer.
|
|
54
|
+
*/
|
|
55
|
+
export const DEFAULT_DIRECTION: WipeDirection = 'right'
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @internal Split fallback mode. `'left-right'` splits the screen into
|
|
59
|
+
* left and right halves (split line runs vertically). Consistent with
|
|
60
|
+
* the wipe/slide rightward default: both strip transitions progress
|
|
61
|
+
* along the horizontal axis unless the consumer asks otherwise.
|
|
62
|
+
*/
|
|
63
|
+
export const DEFAULT_SPLIT_MODE: SplitMode = 'left-right'
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Initial overlay params used while no transition is active. The Canvas
|
|
67
|
+
* stays mounted with these defaults so that starting a transition doesn't
|
|
68
|
+
* need a native-view layout pass (which would cause a "new theme flash"
|
|
69
|
+
* on Android).
|
|
70
|
+
* @internal
|
|
71
|
+
*/
|
|
72
|
+
export const DEFAULT_OVERLAY_PARAMS: OverlayParams = {
|
|
73
|
+
mode: 'fade',
|
|
74
|
+
origin: { x: 0, y: 0 },
|
|
75
|
+
maxRadius: 0,
|
|
76
|
+
screenWidth: 0,
|
|
77
|
+
screenHeight: 0,
|
|
78
|
+
inverted: false,
|
|
79
|
+
direction: DEFAULT_DIRECTION,
|
|
80
|
+
splitMode: DEFAULT_SPLIT_MODE,
|
|
81
|
+
blockSize: DEFAULT_PIXELIZE_BLOCK_SIZE,
|
|
82
|
+
noiseSize: DEFAULT_DISSOLVE_NOISE_SIZE,
|
|
83
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure decision helper for `setTheme`. Given the current engine state
|
|
3
|
+
* and the requested change, returns what the engine should do: ignore
|
|
4
|
+
* the call, accept it as a no-op mode flip (only `preference` updates,
|
|
5
|
+
* no animated transition), or proceed with a real theme swap.
|
|
6
|
+
*
|
|
7
|
+
* Extracted from the `setTheme` closure in `transitionEngine.tsx` so
|
|
8
|
+
* the guard rules can be unit-tested without mounting the provider.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Outcome of calling `setTheme`. `'ignored'` means the engine should
|
|
16
|
+
* return `'ignored'` without touching any state. `'accepted'` splits
|
|
17
|
+
* into two sub-paths: `'mode-flip-noop'` means the resolved theme did
|
|
18
|
+
* not change but the user's `'system'` pick did (update `preference`
|
|
19
|
+
* and return `'accepted'`), and `'proceed'` means run the full
|
|
20
|
+
* transition pipeline.
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
export type SetThemeDecision =
|
|
24
|
+
| { status: 'ignored'; reason: 'transitioning' | 'same-theme' }
|
|
25
|
+
| { status: 'accepted'; path: 'mode-flip-noop' | 'proceed' }
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Pure guard logic for `setTheme`. No side effects, no refs, no React.
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
export function decideSetTheme(input: {
|
|
32
|
+
/** Whether a transition is currently running. */
|
|
33
|
+
transitioning: boolean
|
|
34
|
+
/** The theme the engine is currently painting or transitioning into. */
|
|
35
|
+
currentIntended: string
|
|
36
|
+
/** The concrete theme the `setTheme` call resolves to. */
|
|
37
|
+
resolvedTarget: string
|
|
38
|
+
/** Whether this call flips the `'system'` mode on or off. */
|
|
39
|
+
modeFlipped: boolean
|
|
40
|
+
}): SetThemeDecision {
|
|
41
|
+
if (input.transitioning) return { status: 'ignored', reason: 'transitioning' }
|
|
42
|
+
if (input.resolvedTarget === input.currentIntended) {
|
|
43
|
+
return input.modeFlipped
|
|
44
|
+
? { status: 'accepted', path: 'mode-flip-noop' }
|
|
45
|
+
: { status: 'ignored', reason: 'same-theme' }
|
|
46
|
+
}
|
|
47
|
+
return { status: 'accepted', path: 'proceed' }
|
|
48
|
+
}
|