@onlynative/inertia 0.0.1-alpha.7 → 0.0.1-alpha.8
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 +1 -1
- package/dist/gestureLayer/index.d.mts +119 -0
- package/dist/gestureLayer/index.d.ts +119 -0
- package/dist/gestureLayer/index.js +1745 -0
- package/dist/gestureLayer/index.js.map +1 -0
- package/dist/gestureLayer/index.mjs +1743 -0
- package/dist/gestureLayer/index.mjs.map +1 -0
- package/dist/index.d.mts +114 -74
- package/dist/index.d.ts +114 -74
- package/dist/index.js +279 -41
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +279 -44
- package/dist/index.mjs.map +1 -1
- package/dist/motion/Image.d.mts +1 -1
- package/dist/motion/Image.d.ts +1 -1
- package/dist/motion/Image.js +178 -4
- package/dist/motion/Image.js.map +1 -1
- package/dist/motion/Image.mjs +180 -6
- package/dist/motion/Image.mjs.map +1 -1
- package/dist/motion/Pressable.d.mts +1 -1
- package/dist/motion/Pressable.d.ts +1 -1
- package/dist/motion/Pressable.js +178 -4
- package/dist/motion/Pressable.js.map +1 -1
- package/dist/motion/Pressable.mjs +180 -6
- package/dist/motion/Pressable.mjs.map +1 -1
- package/dist/motion/ScrollView.d.mts +1 -1
- package/dist/motion/ScrollView.d.ts +1 -1
- package/dist/motion/ScrollView.js +178 -4
- package/dist/motion/ScrollView.js.map +1 -1
- package/dist/motion/ScrollView.mjs +180 -6
- package/dist/motion/ScrollView.mjs.map +1 -1
- package/dist/motion/Text.d.mts +1 -1
- package/dist/motion/Text.d.ts +1 -1
- package/dist/motion/Text.js +178 -4
- package/dist/motion/Text.js.map +1 -1
- package/dist/motion/Text.mjs +180 -6
- package/dist/motion/Text.mjs.map +1 -1
- package/dist/motion/View.d.mts +1 -1
- package/dist/motion/View.d.ts +1 -1
- package/dist/motion/View.js +178 -4
- package/dist/motion/View.js.map +1 -1
- package/dist/motion/View.mjs +180 -6
- package/dist/motion/View.mjs.map +1 -1
- package/dist/touch/index.d.mts +146 -0
- package/dist/touch/index.d.ts +146 -0
- package/dist/touch/index.js +166 -0
- package/dist/touch/index.js.map +1 -0
- package/dist/touch/index.mjs +164 -0
- package/dist/touch/index.mjs.map +1 -0
- package/dist/{types-NmNeJjo1.d.mts → types-BwyvoH2V.d.mts} +24 -4
- package/dist/{types-NmNeJjo1.d.ts → types-BwyvoH2V.d.ts} +24 -4
- package/dist/useGesture-BPPp9LhV.d.ts +84 -0
- package/dist/useGesture-BnBF4OtT.d.mts +84 -0
- package/llms.txt +12 -3
- package/package.json +15 -1
- package/src/gestureLayer/index.ts +21 -0
- package/src/gestureLayer/useGestureLayer.ts +285 -0
- package/src/index.ts +7 -0
- package/src/layout/index.ts +15 -0
- package/src/layout/sharedRegistry.ts +108 -0
- package/src/layout/useSharedLayout.ts +289 -0
- package/src/motion/createMotionComponent.tsx +60 -4
- package/src/touch/index.ts +18 -0
- package/src/touch/useTouchDrag.ts +289 -0
- package/src/types.ts +23 -3
- package/src/values/index.ts +11 -0
- package/src/values/useBooleanSpring.ts +33 -0
- package/src/values/useColorTransition.ts +72 -0
- package/src/values/useShadow.ts +116 -0
package/README.md
CHANGED
|
@@ -88,7 +88,7 @@ Plus, on any transition: `delay`, `repeat`. Per-property transitions take preced
|
|
|
88
88
|
|
|
89
89
|
Numeric: `opacity`, `translateX`, `translateY`, `scale`, `scaleX`, `scaleY`, `rotate`, `rotateX`, `rotateY`, `width`, `height`, `borderRadius`. Color: `backgroundColor`, `borderColor`, `color`, `tintColor` (Image only — `Motion.View` rejects it at compile time). Layout transforms via `transform: [...]`. Color targets are forwarded straight through `withSpring` / `withTiming`; Reanimated's value setter packs the string to RGBA and interpolates on the UI thread.
|
|
90
90
|
|
|
91
|
-
SVG path morphing ships in the [`@onlynative/inertia-svg`](../svg) adapter (`MotionPath`).
|
|
91
|
+
SVG path morphing ships in the [`@onlynative/inertia-svg`](../svg) adapter (`MotionPath`). Shared-element transitions across screens are wired through the `layoutId` prop — pair the same id on a source and target `Motion.*` and Inertia FLIPs between them on mount.
|
|
92
92
|
|
|
93
93
|
## When not to use the core package alone
|
|
94
94
|
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { AnimatedStyle } from 'react-native-reanimated';
|
|
2
|
+
import { U as UseGestureHandlers } from '../useGesture-BnBF4OtT.mjs';
|
|
3
|
+
import { T as TransitionConfig, h as GestureLayerTransitions } from '../types-BwyvoH2V.mjs';
|
|
4
|
+
import 'react';
|
|
5
|
+
import 'react-native';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A single gesture-layer style — a flat map of style keys to a value. Numeric
|
|
9
|
+
* values participate in clamped-max composition (the "strongest active layer
|
|
10
|
+
* wins" model used by MD3 state-layer haloes); string values are treated as
|
|
11
|
+
* colors and composed via priority cascade with `interpolateColor`.
|
|
12
|
+
*
|
|
13
|
+
* The hook does not validate that string values are valid colors — passing
|
|
14
|
+
* something like `borderStyle: 'solid'` will crash inside the worklet. Keep
|
|
15
|
+
* string values to color strings.
|
|
16
|
+
*/
|
|
17
|
+
type GestureLayerStyle = {
|
|
18
|
+
[key: string]: number | string | undefined;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Per-state style maps. Every key is optional; missing layers default to
|
|
22
|
+
* `rest` (or `0` / `'transparent'` if `rest` is also absent for that key).
|
|
23
|
+
*
|
|
24
|
+
* - `rest` — base values, applied when no other layer is active.
|
|
25
|
+
* - `hovered` / `focused` / `focusVisible` / `pressed` — gesture-driven
|
|
26
|
+
* states tracked via the underlying `useGesture` hook. Each owns an
|
|
27
|
+
* independent 0↔1 progress that fades the layer in/out per the configured
|
|
28
|
+
* transition.
|
|
29
|
+
* - `disabled` — gated by the JS-side `options.disabled` flag rather than a
|
|
30
|
+
* gesture. Sits at the top of the priority cascade and overrides every
|
|
31
|
+
* gesture layer when active.
|
|
32
|
+
*/
|
|
33
|
+
interface GestureLayerStates {
|
|
34
|
+
rest?: GestureLayerStyle;
|
|
35
|
+
hovered?: GestureLayerStyle;
|
|
36
|
+
focused?: GestureLayerStyle;
|
|
37
|
+
focusVisible?: GestureLayerStyle;
|
|
38
|
+
pressed?: GestureLayerStyle;
|
|
39
|
+
disabled?: GestureLayerStyle;
|
|
40
|
+
}
|
|
41
|
+
interface UseGestureLayerOptions {
|
|
42
|
+
/**
|
|
43
|
+
* When `true`, the `disabled` layer becomes active (or `rest` if `disabled`
|
|
44
|
+
* is undefined). Animates via the top-level transition or the library
|
|
45
|
+
* default spring; per-layer transitions (`GestureLayerTransitions`) do not
|
|
46
|
+
* apply to `disabled`.
|
|
47
|
+
*/
|
|
48
|
+
disabled?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Transition forwarded to the underlying `useGesture` hook. Either a single
|
|
51
|
+
* `TransitionConfig` for every gesture layer, or a `GestureLayerTransitions`
|
|
52
|
+
* map for per-layer fades. Reduced motion collapses every transition to
|
|
53
|
+
* `no-animation`.
|
|
54
|
+
*/
|
|
55
|
+
transition?: TransitionConfig | GestureLayerTransitions;
|
|
56
|
+
}
|
|
57
|
+
interface UseGestureLayerResult {
|
|
58
|
+
/**
|
|
59
|
+
* Animated style produced by `useAnimatedStyle` — spread on an
|
|
60
|
+
* `Animated.View` or pass through `<Motion.View style={...} />`.
|
|
61
|
+
*/
|
|
62
|
+
style: AnimatedStyle<Record<string, unknown>>;
|
|
63
|
+
/** Handlers to spread on the receiving `Pressable`. */
|
|
64
|
+
handlers: UseGestureHandlers;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* A "strongest active layer wins" interactive-feedback primitive. Sits one
|
|
68
|
+
* step above `useGesture()` — the consumer supplies the per-state target
|
|
69
|
+
* values, the hook handles the four gesture progress shared values, the
|
|
70
|
+
* disabled override, the worklet, and the transition.
|
|
71
|
+
*
|
|
72
|
+
* Composition model:
|
|
73
|
+
*
|
|
74
|
+
* - **Numeric keys** (opacity, scale, borderWidth, etc.) compose via
|
|
75
|
+
* clamped-max with `rest` as the floor:
|
|
76
|
+
* `out = max(rest, ...for each active gesture layer: lerp(rest, layer, progress))`.
|
|
77
|
+
* This matches the MD3 state-layer halo pattern — multiple states active
|
|
78
|
+
* simultaneously raise the value to the strongest, not the sum.
|
|
79
|
+
* - **Color keys** (any string value) compose via priority cascade with
|
|
80
|
+
* `interpolateColor`, lowest priority first: `hovered → focused →
|
|
81
|
+
* focusVisible → pressed`. Clamped-max doesn't apply to colors; this
|
|
82
|
+
* matches the cascade used by the declarative `gesture` prop.
|
|
83
|
+
* - **Disabled** sits at the top of the cascade for both numeric and color
|
|
84
|
+
* keys — when active, it lerps the composed value toward the `disabled`
|
|
85
|
+
* target.
|
|
86
|
+
*
|
|
87
|
+
* Reach for this when you want MD3 / iOS-translucent state-layer overlays
|
|
88
|
+
* without rewriting the worklet by hand for every consumer; reach for plain
|
|
89
|
+
* `useGesture()` when you need a composition model this hook doesn't
|
|
90
|
+
* express (additive, multiply, per-key custom blends).
|
|
91
|
+
*
|
|
92
|
+
* @example MD3 state-layer halo
|
|
93
|
+
* ```tsx
|
|
94
|
+
* import { useGestureLayer } from '@onlynative/inertia/gesture-layer'
|
|
95
|
+
* import Animated from 'react-native-reanimated'
|
|
96
|
+
* import { Pressable } from 'react-native'
|
|
97
|
+
*
|
|
98
|
+
* function SwitchHalo({ disabled }: { disabled?: boolean }) {
|
|
99
|
+
* const { style, handlers } = useGestureLayer(
|
|
100
|
+
* {
|
|
101
|
+
* rest: { opacity: 0, backgroundColor: 'transparent' },
|
|
102
|
+
* hovered: { opacity: 0.08, backgroundColor: '#000' },
|
|
103
|
+
* focused: { opacity: 0.10, backgroundColor: '#000' },
|
|
104
|
+
* pressed: { opacity: 0.12, backgroundColor: '#000' },
|
|
105
|
+
* },
|
|
106
|
+
* { disabled, transition: { type: 'timing', duration: 150 } },
|
|
107
|
+
* )
|
|
108
|
+
*
|
|
109
|
+
* return (
|
|
110
|
+
* <Pressable {...handlers}>
|
|
111
|
+
* <Animated.View style={style} />
|
|
112
|
+
* </Pressable>
|
|
113
|
+
* )
|
|
114
|
+
* }
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
declare function useGestureLayer(states: GestureLayerStates, options?: UseGestureLayerOptions): UseGestureLayerResult;
|
|
118
|
+
|
|
119
|
+
export { type GestureLayerStates, type GestureLayerStyle, type UseGestureLayerOptions, type UseGestureLayerResult, useGestureLayer };
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { AnimatedStyle } from 'react-native-reanimated';
|
|
2
|
+
import { U as UseGestureHandlers } from '../useGesture-BPPp9LhV.js';
|
|
3
|
+
import { T as TransitionConfig, h as GestureLayerTransitions } from '../types-BwyvoH2V.js';
|
|
4
|
+
import 'react';
|
|
5
|
+
import 'react-native';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A single gesture-layer style — a flat map of style keys to a value. Numeric
|
|
9
|
+
* values participate in clamped-max composition (the "strongest active layer
|
|
10
|
+
* wins" model used by MD3 state-layer haloes); string values are treated as
|
|
11
|
+
* colors and composed via priority cascade with `interpolateColor`.
|
|
12
|
+
*
|
|
13
|
+
* The hook does not validate that string values are valid colors — passing
|
|
14
|
+
* something like `borderStyle: 'solid'` will crash inside the worklet. Keep
|
|
15
|
+
* string values to color strings.
|
|
16
|
+
*/
|
|
17
|
+
type GestureLayerStyle = {
|
|
18
|
+
[key: string]: number | string | undefined;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Per-state style maps. Every key is optional; missing layers default to
|
|
22
|
+
* `rest` (or `0` / `'transparent'` if `rest` is also absent for that key).
|
|
23
|
+
*
|
|
24
|
+
* - `rest` — base values, applied when no other layer is active.
|
|
25
|
+
* - `hovered` / `focused` / `focusVisible` / `pressed` — gesture-driven
|
|
26
|
+
* states tracked via the underlying `useGesture` hook. Each owns an
|
|
27
|
+
* independent 0↔1 progress that fades the layer in/out per the configured
|
|
28
|
+
* transition.
|
|
29
|
+
* - `disabled` — gated by the JS-side `options.disabled` flag rather than a
|
|
30
|
+
* gesture. Sits at the top of the priority cascade and overrides every
|
|
31
|
+
* gesture layer when active.
|
|
32
|
+
*/
|
|
33
|
+
interface GestureLayerStates {
|
|
34
|
+
rest?: GestureLayerStyle;
|
|
35
|
+
hovered?: GestureLayerStyle;
|
|
36
|
+
focused?: GestureLayerStyle;
|
|
37
|
+
focusVisible?: GestureLayerStyle;
|
|
38
|
+
pressed?: GestureLayerStyle;
|
|
39
|
+
disabled?: GestureLayerStyle;
|
|
40
|
+
}
|
|
41
|
+
interface UseGestureLayerOptions {
|
|
42
|
+
/**
|
|
43
|
+
* When `true`, the `disabled` layer becomes active (or `rest` if `disabled`
|
|
44
|
+
* is undefined). Animates via the top-level transition or the library
|
|
45
|
+
* default spring; per-layer transitions (`GestureLayerTransitions`) do not
|
|
46
|
+
* apply to `disabled`.
|
|
47
|
+
*/
|
|
48
|
+
disabled?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Transition forwarded to the underlying `useGesture` hook. Either a single
|
|
51
|
+
* `TransitionConfig` for every gesture layer, or a `GestureLayerTransitions`
|
|
52
|
+
* map for per-layer fades. Reduced motion collapses every transition to
|
|
53
|
+
* `no-animation`.
|
|
54
|
+
*/
|
|
55
|
+
transition?: TransitionConfig | GestureLayerTransitions;
|
|
56
|
+
}
|
|
57
|
+
interface UseGestureLayerResult {
|
|
58
|
+
/**
|
|
59
|
+
* Animated style produced by `useAnimatedStyle` — spread on an
|
|
60
|
+
* `Animated.View` or pass through `<Motion.View style={...} />`.
|
|
61
|
+
*/
|
|
62
|
+
style: AnimatedStyle<Record<string, unknown>>;
|
|
63
|
+
/** Handlers to spread on the receiving `Pressable`. */
|
|
64
|
+
handlers: UseGestureHandlers;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* A "strongest active layer wins" interactive-feedback primitive. Sits one
|
|
68
|
+
* step above `useGesture()` — the consumer supplies the per-state target
|
|
69
|
+
* values, the hook handles the four gesture progress shared values, the
|
|
70
|
+
* disabled override, the worklet, and the transition.
|
|
71
|
+
*
|
|
72
|
+
* Composition model:
|
|
73
|
+
*
|
|
74
|
+
* - **Numeric keys** (opacity, scale, borderWidth, etc.) compose via
|
|
75
|
+
* clamped-max with `rest` as the floor:
|
|
76
|
+
* `out = max(rest, ...for each active gesture layer: lerp(rest, layer, progress))`.
|
|
77
|
+
* This matches the MD3 state-layer halo pattern — multiple states active
|
|
78
|
+
* simultaneously raise the value to the strongest, not the sum.
|
|
79
|
+
* - **Color keys** (any string value) compose via priority cascade with
|
|
80
|
+
* `interpolateColor`, lowest priority first: `hovered → focused →
|
|
81
|
+
* focusVisible → pressed`. Clamped-max doesn't apply to colors; this
|
|
82
|
+
* matches the cascade used by the declarative `gesture` prop.
|
|
83
|
+
* - **Disabled** sits at the top of the cascade for both numeric and color
|
|
84
|
+
* keys — when active, it lerps the composed value toward the `disabled`
|
|
85
|
+
* target.
|
|
86
|
+
*
|
|
87
|
+
* Reach for this when you want MD3 / iOS-translucent state-layer overlays
|
|
88
|
+
* without rewriting the worklet by hand for every consumer; reach for plain
|
|
89
|
+
* `useGesture()` when you need a composition model this hook doesn't
|
|
90
|
+
* express (additive, multiply, per-key custom blends).
|
|
91
|
+
*
|
|
92
|
+
* @example MD3 state-layer halo
|
|
93
|
+
* ```tsx
|
|
94
|
+
* import { useGestureLayer } from '@onlynative/inertia/gesture-layer'
|
|
95
|
+
* import Animated from 'react-native-reanimated'
|
|
96
|
+
* import { Pressable } from 'react-native'
|
|
97
|
+
*
|
|
98
|
+
* function SwitchHalo({ disabled }: { disabled?: boolean }) {
|
|
99
|
+
* const { style, handlers } = useGestureLayer(
|
|
100
|
+
* {
|
|
101
|
+
* rest: { opacity: 0, backgroundColor: 'transparent' },
|
|
102
|
+
* hovered: { opacity: 0.08, backgroundColor: '#000' },
|
|
103
|
+
* focused: { opacity: 0.10, backgroundColor: '#000' },
|
|
104
|
+
* pressed: { opacity: 0.12, backgroundColor: '#000' },
|
|
105
|
+
* },
|
|
106
|
+
* { disabled, transition: { type: 'timing', duration: 150 } },
|
|
107
|
+
* )
|
|
108
|
+
*
|
|
109
|
+
* return (
|
|
110
|
+
* <Pressable {...handlers}>
|
|
111
|
+
* <Animated.View style={style} />
|
|
112
|
+
* </Pressable>
|
|
113
|
+
* )
|
|
114
|
+
* }
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
declare function useGestureLayer(states: GestureLayerStates, options?: UseGestureLayerOptions): UseGestureLayerResult;
|
|
118
|
+
|
|
119
|
+
export { type GestureLayerStates, type GestureLayerStyle, type UseGestureLayerOptions, type UseGestureLayerResult, useGestureLayer };
|