@onlynative/inertia 0.0.1-alpha.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/CHANGELOG.md +33 -0
- package/LICENSE +21 -0
- package/README.md +90 -0
- package/dist/index.d.mts +185 -0
- package/dist/index.d.ts +185 -0
- package/dist/index.js +817 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +796 -0
- package/dist/index.mjs.map +1 -0
- package/dist/motion/Image.d.mts +12 -0
- package/dist/motion/Image.d.ts +12 -0
- package/dist/motion/Image.js +656 -0
- package/dist/motion/Image.js.map +1 -0
- package/dist/motion/Image.mjs +650 -0
- package/dist/motion/Image.mjs.map +1 -0
- package/dist/motion/Pressable.d.mts +15 -0
- package/dist/motion/Pressable.d.ts +15 -0
- package/dist/motion/Pressable.js +656 -0
- package/dist/motion/Pressable.js.map +1 -0
- package/dist/motion/Pressable.mjs +650 -0
- package/dist/motion/Pressable.mjs.map +1 -0
- package/dist/motion/ScrollView.d.mts +12 -0
- package/dist/motion/ScrollView.d.ts +12 -0
- package/dist/motion/ScrollView.js +656 -0
- package/dist/motion/ScrollView.js.map +1 -0
- package/dist/motion/ScrollView.mjs +650 -0
- package/dist/motion/ScrollView.mjs.map +1 -0
- package/dist/motion/Text.d.mts +11 -0
- package/dist/motion/Text.d.ts +11 -0
- package/dist/motion/Text.js +656 -0
- package/dist/motion/Text.js.map +1 -0
- package/dist/motion/Text.mjs +650 -0
- package/dist/motion/Text.mjs.map +1 -0
- package/dist/motion/View.d.mts +11 -0
- package/dist/motion/View.d.ts +11 -0
- package/dist/motion/View.js +656 -0
- package/dist/motion/View.js.map +1 -0
- package/dist/motion/View.mjs +650 -0
- package/dist/motion/View.mjs.map +1 -0
- package/dist/types-CmbXx-G3.d.mts +185 -0
- package/dist/types-CmbXx-G3.d.ts +185 -0
- package/llms.txt +78 -0
- package/package.json +120 -0
- package/src/config/MotionConfig.tsx +30 -0
- package/src/config/MotionConfigContext.ts +53 -0
- package/src/config/index.ts +9 -0
- package/src/index.ts +49 -0
- package/src/motion/Image.tsx +9 -0
- package/src/motion/Pressable.tsx +12 -0
- package/src/motion/ScrollView.tsx +9 -0
- package/src/motion/Text.tsx +8 -0
- package/src/motion/View.tsx +8 -0
- package/src/motion/createMotionComponent.tsx +850 -0
- package/src/motion/index.ts +26 -0
- package/src/presence/Presence.tsx +165 -0
- package/src/presence/PresenceContext.ts +28 -0
- package/src/presence/index.ts +6 -0
- package/src/transitions/easing.ts +29 -0
- package/src/transitions/index.ts +2 -0
- package/src/transitions/resolve.ts +265 -0
- package/src/types.ts +207 -0
- package/src/values/index.ts +1 -0
- package/src/values/useVariants.ts +60 -0
|
@@ -0,0 +1,656 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var reactNative = require('react-native');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
var Animated = require('react-native-reanimated');
|
|
6
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
7
|
+
|
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var Animated__default = /*#__PURE__*/_interopDefault(Animated);
|
|
11
|
+
|
|
12
|
+
// src/motion/Pressable.tsx
|
|
13
|
+
var DEFAULT_MOTION_CONFIG = {
|
|
14
|
+
reducedMotion: "user"
|
|
15
|
+
};
|
|
16
|
+
var MotionConfigContext = react.createContext(
|
|
17
|
+
DEFAULT_MOTION_CONFIG
|
|
18
|
+
);
|
|
19
|
+
function useMotionConfig() {
|
|
20
|
+
return react.useContext(MotionConfigContext);
|
|
21
|
+
}
|
|
22
|
+
function useShouldReduceMotion() {
|
|
23
|
+
const { reducedMotion } = useMotionConfig();
|
|
24
|
+
const osReduced = Animated.useReducedMotion();
|
|
25
|
+
if (reducedMotion === "never") return false;
|
|
26
|
+
if (reducedMotion === "always") return true;
|
|
27
|
+
return osReduced;
|
|
28
|
+
}
|
|
29
|
+
var PresenceContext = react.createContext(null);
|
|
30
|
+
function usePresence() {
|
|
31
|
+
return react.useContext(PresenceContext);
|
|
32
|
+
}
|
|
33
|
+
function ensureWorkletEasing(easing) {
|
|
34
|
+
if (!easing) return void 0;
|
|
35
|
+
if (Animated.isWorkletFunction(easing)) return easing;
|
|
36
|
+
const wrapped = (t) => {
|
|
37
|
+
"worklet";
|
|
38
|
+
return easing(t);
|
|
39
|
+
};
|
|
40
|
+
return wrapped;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// src/transitions/resolve.ts
|
|
44
|
+
var DEFAULT_SPRING = {
|
|
45
|
+
tension: 170,
|
|
46
|
+
friction: 26,
|
|
47
|
+
mass: 1
|
|
48
|
+
};
|
|
49
|
+
var DEFAULT_TIMING_DURATION = 250;
|
|
50
|
+
function springToReanimated(t) {
|
|
51
|
+
return {
|
|
52
|
+
stiffness: t.tension ?? DEFAULT_SPRING.tension,
|
|
53
|
+
damping: t.friction ?? DEFAULT_SPRING.friction,
|
|
54
|
+
mass: t.mass ?? DEFAULT_SPRING.mass,
|
|
55
|
+
velocity: t.velocity,
|
|
56
|
+
restSpeedThreshold: t.restSpeedThreshold,
|
|
57
|
+
restDisplacementThreshold: t.restDisplacementThreshold
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function buildSpring(cfg, toValue, cb) {
|
|
61
|
+
return Animated.withSpring(toValue, springToReanimated(cfg), cb);
|
|
62
|
+
}
|
|
63
|
+
function buildTiming(cfg, toValue, cb) {
|
|
64
|
+
return Animated.withTiming(
|
|
65
|
+
toValue,
|
|
66
|
+
{
|
|
67
|
+
duration: cfg.duration ?? DEFAULT_TIMING_DURATION,
|
|
68
|
+
easing: ensureWorkletEasing(cfg.easing) ?? Animated.Easing.inOut(Animated.Easing.ease)
|
|
69
|
+
},
|
|
70
|
+
cb
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
function buildDecay(cfg, cb) {
|
|
74
|
+
return Animated.withDecay(
|
|
75
|
+
{
|
|
76
|
+
velocity: cfg.velocity ?? 0,
|
|
77
|
+
deceleration: cfg.deceleration,
|
|
78
|
+
clamp: cfg.clamp
|
|
79
|
+
},
|
|
80
|
+
cb
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
function buildOne(cfg, toValue, cb) {
|
|
84
|
+
if (cfg.type === "no-animation") {
|
|
85
|
+
if (cb) cb(true, toValue);
|
|
86
|
+
return toValue;
|
|
87
|
+
}
|
|
88
|
+
if (cfg.type === "decay") return buildDecay(cfg, cb);
|
|
89
|
+
if (cfg.type === "timing") return buildTiming(cfg, toValue, cb);
|
|
90
|
+
return buildSpring(cfg, toValue, cb);
|
|
91
|
+
}
|
|
92
|
+
function applyRepeat(animation, repeat) {
|
|
93
|
+
if (repeat === void 0) return animation;
|
|
94
|
+
if (repeat === "infinite") {
|
|
95
|
+
return Animated.withRepeat(animation, -1, true);
|
|
96
|
+
}
|
|
97
|
+
if (typeof repeat === "number") {
|
|
98
|
+
return Animated.withRepeat(animation, repeat, true);
|
|
99
|
+
}
|
|
100
|
+
const count = repeat.count === "infinite" ? -1 : repeat.count;
|
|
101
|
+
const alternate = repeat.alternate ?? true;
|
|
102
|
+
return Animated.withRepeat(animation, count, alternate);
|
|
103
|
+
}
|
|
104
|
+
function applyDelay(animation, delay) {
|
|
105
|
+
if (!delay || delay <= 0) return animation;
|
|
106
|
+
return Animated.withDelay(delay, animation);
|
|
107
|
+
}
|
|
108
|
+
function resolveTransition(config, toValue, callback) {
|
|
109
|
+
const cfg = config ?? { type: "spring" };
|
|
110
|
+
const base = buildOne(cfg, toValue, callback);
|
|
111
|
+
const repeated = applyRepeat(base, repeatOf(cfg));
|
|
112
|
+
return applyDelay(repeated, delayOf(cfg));
|
|
113
|
+
}
|
|
114
|
+
function repeatOf(cfg) {
|
|
115
|
+
if (cfg.type === "no-animation" || cfg.type === "decay") return void 0;
|
|
116
|
+
return cfg.repeat;
|
|
117
|
+
}
|
|
118
|
+
function stripRepeat(cfg) {
|
|
119
|
+
if (!cfg) return cfg;
|
|
120
|
+
if (cfg.type === "no-animation" || cfg.type === "decay") return cfg;
|
|
121
|
+
if (cfg.repeat === void 0) return cfg;
|
|
122
|
+
const next = { ...cfg };
|
|
123
|
+
delete next.repeat;
|
|
124
|
+
return next;
|
|
125
|
+
}
|
|
126
|
+
function delayOf(cfg) {
|
|
127
|
+
if (cfg.type === "no-animation") return void 0;
|
|
128
|
+
return cfg.delay;
|
|
129
|
+
}
|
|
130
|
+
function isStepObject(v) {
|
|
131
|
+
return typeof v === "object" && v !== null && !Array.isArray(v) && "to" in v;
|
|
132
|
+
}
|
|
133
|
+
function resolveAnimatableValue(value, base, factory) {
|
|
134
|
+
if (Array.isArray(value)) {
|
|
135
|
+
const steps = value;
|
|
136
|
+
const stepBase = stripRepeat(base);
|
|
137
|
+
const animations = steps.map(
|
|
138
|
+
(step2, i) => resolveStep(step2, stepBase, factory?.("step", i))
|
|
139
|
+
);
|
|
140
|
+
const seq = Animated.withSequence(...animations);
|
|
141
|
+
return applyRepeat(seq, base ? repeatOf(base) : void 0);
|
|
142
|
+
}
|
|
143
|
+
const step = value;
|
|
144
|
+
const cb = factory?.("animation", void 0);
|
|
145
|
+
if (isStepObject(step)) {
|
|
146
|
+
return resolveStep(step, base, cb);
|
|
147
|
+
}
|
|
148
|
+
return resolveTransition(base, step, cb);
|
|
149
|
+
}
|
|
150
|
+
function resolveStep(step, base, cb) {
|
|
151
|
+
if (isStepObject(step)) {
|
|
152
|
+
const { to, ...override } = step;
|
|
153
|
+
const merged = mergeTransition(base, override);
|
|
154
|
+
return resolveTransition(merged, to, cb);
|
|
155
|
+
}
|
|
156
|
+
return resolveTransition(base, step, cb);
|
|
157
|
+
}
|
|
158
|
+
function mergeTransition(base, override) {
|
|
159
|
+
if (override.type && base && override.type !== base.type) {
|
|
160
|
+
return override;
|
|
161
|
+
}
|
|
162
|
+
return { ...base ?? { type: "spring" }, ...override };
|
|
163
|
+
}
|
|
164
|
+
var TRANSFORM_KEYS = [
|
|
165
|
+
"translateX",
|
|
166
|
+
"translateY",
|
|
167
|
+
"scale",
|
|
168
|
+
"scaleX",
|
|
169
|
+
"scaleY",
|
|
170
|
+
"rotate"
|
|
171
|
+
];
|
|
172
|
+
var TOP_LEVEL_KEYS = ["opacity", "width", "height", "borderRadius"];
|
|
173
|
+
var ALL_KEYS = [...TRANSFORM_KEYS, ...TOP_LEVEL_KEYS];
|
|
174
|
+
var TRANSFORM_KEY_SET = new Set(TRANSFORM_KEYS);
|
|
175
|
+
var EXITING_POINTER_EVENTS_STYLE = { pointerEvents: "none" };
|
|
176
|
+
var DEFAULT_RESTING = {
|
|
177
|
+
translateX: 0,
|
|
178
|
+
translateY: 0,
|
|
179
|
+
scale: 1,
|
|
180
|
+
scaleX: 1,
|
|
181
|
+
scaleY: 1,
|
|
182
|
+
rotate: 0,
|
|
183
|
+
opacity: 1,
|
|
184
|
+
width: 0,
|
|
185
|
+
height: 0,
|
|
186
|
+
borderRadius: 0
|
|
187
|
+
};
|
|
188
|
+
var TRANSITION_KEYS = /* @__PURE__ */ new Set([
|
|
189
|
+
"type",
|
|
190
|
+
"tension",
|
|
191
|
+
"friction",
|
|
192
|
+
"mass",
|
|
193
|
+
"velocity",
|
|
194
|
+
"restSpeedThreshold",
|
|
195
|
+
"restDisplacementThreshold",
|
|
196
|
+
"duration",
|
|
197
|
+
"easing",
|
|
198
|
+
"delay",
|
|
199
|
+
"repeat",
|
|
200
|
+
"deceleration",
|
|
201
|
+
"clamp"
|
|
202
|
+
]);
|
|
203
|
+
function isTopLevelTransition(t) {
|
|
204
|
+
if (t === null || typeof t !== "object") return false;
|
|
205
|
+
const keys = Object.keys(t);
|
|
206
|
+
if (keys.length === 0) return false;
|
|
207
|
+
return keys.every((k) => TRANSITION_KEYS.has(k));
|
|
208
|
+
}
|
|
209
|
+
function transitionFor(prop, transition) {
|
|
210
|
+
if (!transition) return void 0;
|
|
211
|
+
if (isTopLevelTransition(transition)) return transition;
|
|
212
|
+
return transition[prop];
|
|
213
|
+
}
|
|
214
|
+
function createMotionComponent(Component) {
|
|
215
|
+
const AnimatedComponent = Animated__default.default.createAnimatedComponent(
|
|
216
|
+
Component
|
|
217
|
+
);
|
|
218
|
+
const Motion = react.forwardRef(function Motion2(props, ref) {
|
|
219
|
+
const {
|
|
220
|
+
initial,
|
|
221
|
+
animate,
|
|
222
|
+
exit,
|
|
223
|
+
transition,
|
|
224
|
+
variants,
|
|
225
|
+
controller,
|
|
226
|
+
gesture,
|
|
227
|
+
onAnimationEnd,
|
|
228
|
+
style,
|
|
229
|
+
...rest
|
|
230
|
+
} = props;
|
|
231
|
+
const presence = usePresence();
|
|
232
|
+
const isExiting = presence !== null && presence.isPresent === false;
|
|
233
|
+
const shouldReduceMotion = useShouldReduceMotion();
|
|
234
|
+
const onAnimationEndRef = react.useRef(onAnimationEnd);
|
|
235
|
+
onAnimationEndRef.current = onAnimationEnd;
|
|
236
|
+
const variantKey = useControllerKey(controller);
|
|
237
|
+
const resolvedAnimate = resolveAnimateInput(
|
|
238
|
+
animate,
|
|
239
|
+
variants,
|
|
240
|
+
variantKey
|
|
241
|
+
);
|
|
242
|
+
const animateRecord = resolvedAnimate ?? {};
|
|
243
|
+
const initialRecord = initial && initial !== false ? initial : void 0;
|
|
244
|
+
const exitRecord = exit ? exit : void 0;
|
|
245
|
+
const [pressed, setPressed] = react.useState(false);
|
|
246
|
+
const [focused, setFocused] = react.useState(false);
|
|
247
|
+
const [hovered, setHovered] = react.useState(false);
|
|
248
|
+
const activeKeysRef = react.useRef(null);
|
|
249
|
+
if (activeKeysRef.current === null) {
|
|
250
|
+
const touched = /* @__PURE__ */ new Set();
|
|
251
|
+
for (const k of ALL_KEYS) {
|
|
252
|
+
if (k in animateRecord) touched.add(k);
|
|
253
|
+
if (initialRecord && k in initialRecord) touched.add(k);
|
|
254
|
+
}
|
|
255
|
+
if (variants) {
|
|
256
|
+
for (const variant of Object.values(variants)) {
|
|
257
|
+
if (!variant) continue;
|
|
258
|
+
for (const k of ALL_KEYS) {
|
|
259
|
+
if (k in variant) touched.add(k);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
if (gesture) {
|
|
264
|
+
for (const subState of [
|
|
265
|
+
gesture.pressed,
|
|
266
|
+
gesture.focused,
|
|
267
|
+
gesture.hovered
|
|
268
|
+
]) {
|
|
269
|
+
if (!subState) continue;
|
|
270
|
+
for (const k of ALL_KEYS) {
|
|
271
|
+
if (k in subState) touched.add(k);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
if (exitRecord) {
|
|
276
|
+
for (const k of ALL_KEYS) {
|
|
277
|
+
if (k in exitRecord) touched.add(k);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
activeKeysRef.current = ALL_KEYS.filter((k) => touched.has(k));
|
|
281
|
+
}
|
|
282
|
+
const hasTransformRef = react.useRef(
|
|
283
|
+
activeKeysRef.current.some((k) => TRANSFORM_KEY_SET.has(k))
|
|
284
|
+
);
|
|
285
|
+
const sharedValues = useAnimatableSharedValues((key) => {
|
|
286
|
+
if (initial === false) {
|
|
287
|
+
const a = animateRecord[key];
|
|
288
|
+
return restValue(a) ?? DEFAULT_RESTING[key];
|
|
289
|
+
}
|
|
290
|
+
return initialRecord?.[key] ?? restValue(animateRecord[key]) ?? DEFAULT_RESTING[key];
|
|
291
|
+
});
|
|
292
|
+
const mergedRecord = isExiting && exitRecord ? { ...animateRecord, ...exitRecord } : mergeGestureTargets(animateRecord, gesture, {
|
|
293
|
+
pressed,
|
|
294
|
+
focused,
|
|
295
|
+
hovered
|
|
296
|
+
});
|
|
297
|
+
const mergedSig = stableSig(mergedRecord) + (isExiting ? "|exit" : "") + (shouldReduceMotion ? "|rm" : "");
|
|
298
|
+
const transitionSig = stableSig(transition);
|
|
299
|
+
const safeToRemoveRef = react.useRef(void 0);
|
|
300
|
+
safeToRemoveRef.current = presence?.safeToRemove;
|
|
301
|
+
react.useEffect(() => {
|
|
302
|
+
if (isExiting && (!exitRecord || Object.keys(exitRecord).length === 0)) {
|
|
303
|
+
safeToRemoveRef.current?.();
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
let pending = 0;
|
|
307
|
+
let done = false;
|
|
308
|
+
const onSettle = () => {
|
|
309
|
+
if (done) return;
|
|
310
|
+
pending--;
|
|
311
|
+
if (pending <= 0) {
|
|
312
|
+
done = true;
|
|
313
|
+
if (isExiting) safeToRemoveRef.current?.();
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
let transformPending = 0;
|
|
317
|
+
for (const k of ALL_KEYS) {
|
|
318
|
+
if (TRANSFORM_KEY_SET.has(k) && mergedRecord[k] !== void 0) {
|
|
319
|
+
transformPending++;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
const transformGroup = transformPending > 0 ? { remaining: transformPending } : void 0;
|
|
323
|
+
for (const key of ALL_KEYS) {
|
|
324
|
+
const target = mergedRecord[key];
|
|
325
|
+
if (target === void 0) continue;
|
|
326
|
+
const cfg = shouldReduceMotion ? { type: "no-animation" } : transitionFor(key, transition);
|
|
327
|
+
if (isExiting) pending++;
|
|
328
|
+
const factory = makeKeyCallbackFactory(
|
|
329
|
+
key,
|
|
330
|
+
sharedValues[key],
|
|
331
|
+
targetEndValue(target),
|
|
332
|
+
onAnimationEndRef,
|
|
333
|
+
{
|
|
334
|
+
stepCount: stepCountOf(target),
|
|
335
|
+
totalIterations: totalIterationsOf(cfg)
|
|
336
|
+
},
|
|
337
|
+
isExiting ? onSettle : void 0,
|
|
338
|
+
TRANSFORM_KEY_SET.has(key) ? transformGroup : void 0
|
|
339
|
+
);
|
|
340
|
+
sharedValues[key].value = resolveAnimatableValue(
|
|
341
|
+
target,
|
|
342
|
+
cfg,
|
|
343
|
+
factory
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
if (isExiting && pending === 0) {
|
|
347
|
+
safeToRemoveRef.current?.();
|
|
348
|
+
}
|
|
349
|
+
}, [mergedSig, transitionSig]);
|
|
350
|
+
const animatedStyle = Animated.useAnimatedStyle(() => {
|
|
351
|
+
const activeKeys = activeKeysRef.current;
|
|
352
|
+
const hasTransform = hasTransformRef.current;
|
|
353
|
+
const out = {};
|
|
354
|
+
const transform = [];
|
|
355
|
+
for (const key of activeKeys) {
|
|
356
|
+
const v = sharedValues[key].value;
|
|
357
|
+
if (TRANSFORM_KEY_SET.has(key)) {
|
|
358
|
+
transform.push(
|
|
359
|
+
key === "rotate" ? { rotate: `${v}deg` } : { [key]: v }
|
|
360
|
+
);
|
|
361
|
+
} else {
|
|
362
|
+
out[key] = v;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
if (hasTransform) out.transform = transform;
|
|
366
|
+
return out;
|
|
367
|
+
});
|
|
368
|
+
const mergedStyle = react.useMemo(
|
|
369
|
+
() => isExiting ? [style, animatedStyle, EXITING_POINTER_EVENTS_STYLE] : [style, animatedStyle],
|
|
370
|
+
[style, animatedStyle, isExiting]
|
|
371
|
+
);
|
|
372
|
+
const gestureHandlers = useGestureHandlers(
|
|
373
|
+
gesture,
|
|
374
|
+
rest,
|
|
375
|
+
setPressed,
|
|
376
|
+
setFocused,
|
|
377
|
+
setHovered
|
|
378
|
+
);
|
|
379
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
380
|
+
AnimatedComponent,
|
|
381
|
+
{
|
|
382
|
+
ref,
|
|
383
|
+
...rest,
|
|
384
|
+
...gestureHandlers,
|
|
385
|
+
style: mergedStyle
|
|
386
|
+
}
|
|
387
|
+
);
|
|
388
|
+
});
|
|
389
|
+
Motion.displayName = `Motion(${Component.displayName ?? Component.name ?? "Component"})`;
|
|
390
|
+
return Motion;
|
|
391
|
+
}
|
|
392
|
+
function useAnimatableSharedValues(init) {
|
|
393
|
+
const translateX = Animated.useSharedValue(init("translateX"));
|
|
394
|
+
const translateY = Animated.useSharedValue(init("translateY"));
|
|
395
|
+
const scale = Animated.useSharedValue(init("scale"));
|
|
396
|
+
const scaleX = Animated.useSharedValue(init("scaleX"));
|
|
397
|
+
const scaleY = Animated.useSharedValue(init("scaleY"));
|
|
398
|
+
const rotate = Animated.useSharedValue(init("rotate"));
|
|
399
|
+
const opacity = Animated.useSharedValue(init("opacity"));
|
|
400
|
+
const width = Animated.useSharedValue(init("width"));
|
|
401
|
+
const height = Animated.useSharedValue(init("height"));
|
|
402
|
+
const borderRadius = Animated.useSharedValue(init("borderRadius"));
|
|
403
|
+
const ref = react.useRef(null);
|
|
404
|
+
if (ref.current === null) {
|
|
405
|
+
ref.current = {
|
|
406
|
+
translateX,
|
|
407
|
+
translateY,
|
|
408
|
+
scale,
|
|
409
|
+
scaleX,
|
|
410
|
+
scaleY,
|
|
411
|
+
rotate,
|
|
412
|
+
opacity,
|
|
413
|
+
width,
|
|
414
|
+
height,
|
|
415
|
+
borderRadius
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
return ref.current;
|
|
419
|
+
}
|
|
420
|
+
function makeKeyCallbackFactory(key, sharedValue, target, onAnimationEndRef, meta, onSettle, transformGroup) {
|
|
421
|
+
if (!onAnimationEndRef.current && !onSettle) return void 0;
|
|
422
|
+
const state = { iteration: 0 };
|
|
423
|
+
const isTransformKey = TRANSFORM_KEY_SET.has(key);
|
|
424
|
+
const dispatch = (rawPhase, step, finished, value) => {
|
|
425
|
+
const isLastIteration = state.iteration >= meta.totalIterations - 1;
|
|
426
|
+
let phase;
|
|
427
|
+
let isTerminal = false;
|
|
428
|
+
if (rawPhase === "step") {
|
|
429
|
+
const isLastInPass = step !== void 0 && step === meta.stepCount - 1;
|
|
430
|
+
if (!isLastInPass) {
|
|
431
|
+
phase = "step";
|
|
432
|
+
} else if (isLastIteration) {
|
|
433
|
+
phase = "animation";
|
|
434
|
+
isTerminal = true;
|
|
435
|
+
} else {
|
|
436
|
+
phase = "sequence";
|
|
437
|
+
}
|
|
438
|
+
} else if (isLastIteration) {
|
|
439
|
+
phase = "animation";
|
|
440
|
+
isTerminal = true;
|
|
441
|
+
} else {
|
|
442
|
+
phase = "repeat";
|
|
443
|
+
}
|
|
444
|
+
const reportedIteration = state.iteration;
|
|
445
|
+
if (phase === "sequence" || phase === "repeat") state.iteration++;
|
|
446
|
+
const fn = onAnimationEndRef.current;
|
|
447
|
+
if (fn) {
|
|
448
|
+
if (isTransformKey && transformGroup && phase === "animation") {
|
|
449
|
+
transformGroup.remaining--;
|
|
450
|
+
if (transformGroup.remaining <= 0) {
|
|
451
|
+
fn({
|
|
452
|
+
key: "transform",
|
|
453
|
+
finished,
|
|
454
|
+
value,
|
|
455
|
+
target,
|
|
456
|
+
phase,
|
|
457
|
+
step,
|
|
458
|
+
iteration: reportedIteration
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
} else {
|
|
462
|
+
fn({
|
|
463
|
+
key,
|
|
464
|
+
finished,
|
|
465
|
+
value,
|
|
466
|
+
target,
|
|
467
|
+
phase,
|
|
468
|
+
step,
|
|
469
|
+
iteration: reportedIteration
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
if (onSettle && isTerminal) onSettle();
|
|
474
|
+
};
|
|
475
|
+
return (rawPhase, step) => {
|
|
476
|
+
const cb = (finished) => {
|
|
477
|
+
"worklet";
|
|
478
|
+
Animated.runOnJS(dispatch)(rawPhase, step, !!finished, sharedValue.value);
|
|
479
|
+
};
|
|
480
|
+
return cb;
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
function stepCountOf(v) {
|
|
484
|
+
if (Array.isArray(v)) return v.length;
|
|
485
|
+
return 1;
|
|
486
|
+
}
|
|
487
|
+
function totalIterationsOf(cfg) {
|
|
488
|
+
if (!cfg || cfg.type === "no-animation" || cfg.type === "decay") return 1;
|
|
489
|
+
const r = cfg.repeat;
|
|
490
|
+
if (r === void 0) return 1;
|
|
491
|
+
if (r === "infinite") return Number.POSITIVE_INFINITY;
|
|
492
|
+
if (typeof r === "number") return r;
|
|
493
|
+
if (r.count === "infinite") return Number.POSITIVE_INFINITY;
|
|
494
|
+
return r.count;
|
|
495
|
+
}
|
|
496
|
+
function targetEndValue(v) {
|
|
497
|
+
if (v === void 0) return void 0;
|
|
498
|
+
if (typeof v === "number" || typeof v === "string") return v;
|
|
499
|
+
if (Array.isArray(v)) {
|
|
500
|
+
return v.length > 0 ? targetEndValue(v[v.length - 1]) : void 0;
|
|
501
|
+
}
|
|
502
|
+
if (typeof v === "object" && v !== null && "to" in v) {
|
|
503
|
+
const to = v.to;
|
|
504
|
+
return typeof to === "number" || typeof to === "string" ? to : void 0;
|
|
505
|
+
}
|
|
506
|
+
return void 0;
|
|
507
|
+
}
|
|
508
|
+
function useControllerKey(controller) {
|
|
509
|
+
const [, setTick] = react.useState(0);
|
|
510
|
+
react.useEffect(() => {
|
|
511
|
+
if (!controller) return;
|
|
512
|
+
const unsub = controller.subscribe(() => setTick((n) => n + 1));
|
|
513
|
+
return unsub;
|
|
514
|
+
}, [controller]);
|
|
515
|
+
return controller?.current;
|
|
516
|
+
}
|
|
517
|
+
function resolveAnimateInput(animate, variants, controllerKey) {
|
|
518
|
+
if (controllerKey !== void 0 && variants && controllerKey in variants) {
|
|
519
|
+
return variants[controllerKey];
|
|
520
|
+
}
|
|
521
|
+
if (typeof animate === "string") {
|
|
522
|
+
if (variants && animate in variants) return variants[animate];
|
|
523
|
+
if (__DEV__) {
|
|
524
|
+
console.warn(
|
|
525
|
+
`[inertia] animate="${animate}" but no matching variant. Did you forget to pass \`variants\`?`
|
|
526
|
+
);
|
|
527
|
+
}
|
|
528
|
+
return void 0;
|
|
529
|
+
}
|
|
530
|
+
return animate;
|
|
531
|
+
}
|
|
532
|
+
function restValue(v) {
|
|
533
|
+
if (v === void 0) return void 0;
|
|
534
|
+
if (typeof v === "number") return v;
|
|
535
|
+
if (Array.isArray(v)) {
|
|
536
|
+
return v.length > 0 ? restValue(v[0]) : void 0;
|
|
537
|
+
}
|
|
538
|
+
if (typeof v === "object" && v !== null && "to" in v) {
|
|
539
|
+
const to = v.to;
|
|
540
|
+
return typeof to === "number" ? to : void 0;
|
|
541
|
+
}
|
|
542
|
+
return void 0;
|
|
543
|
+
}
|
|
544
|
+
function stableSig(value) {
|
|
545
|
+
if (value === void 0) return "";
|
|
546
|
+
try {
|
|
547
|
+
return stableStringify(value);
|
|
548
|
+
} catch {
|
|
549
|
+
return String(value);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
function stableStringify(v) {
|
|
553
|
+
if (v === null || typeof v !== "object") {
|
|
554
|
+
if (typeof v === "function" || v === void 0) return "null";
|
|
555
|
+
return JSON.stringify(v);
|
|
556
|
+
}
|
|
557
|
+
if (Array.isArray(v)) {
|
|
558
|
+
return "[" + v.map(stableStringify).join(",") + "]";
|
|
559
|
+
}
|
|
560
|
+
const obj = v;
|
|
561
|
+
const keys = Object.keys(obj).sort();
|
|
562
|
+
return "{" + keys.map((k) => JSON.stringify(k) + ":" + stableStringify(obj[k])).join(",") + "}";
|
|
563
|
+
}
|
|
564
|
+
function mergeGestureTargets(base, gesture, active) {
|
|
565
|
+
if (!gesture) return base;
|
|
566
|
+
const merged = {
|
|
567
|
+
...base
|
|
568
|
+
};
|
|
569
|
+
const subStates = [
|
|
570
|
+
gesture.hovered,
|
|
571
|
+
gesture.focused,
|
|
572
|
+
gesture.pressed
|
|
573
|
+
];
|
|
574
|
+
for (const sub of subStates) {
|
|
575
|
+
if (!sub) continue;
|
|
576
|
+
for (const k of ALL_KEYS) {
|
|
577
|
+
if (k in sub && !(k in merged)) {
|
|
578
|
+
merged[k] = DEFAULT_RESTING[k];
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
if (active.hovered && gesture.hovered) {
|
|
583
|
+
Object.assign(
|
|
584
|
+
merged,
|
|
585
|
+
gesture.hovered
|
|
586
|
+
);
|
|
587
|
+
}
|
|
588
|
+
if (active.focused && gesture.focused) {
|
|
589
|
+
Object.assign(
|
|
590
|
+
merged,
|
|
591
|
+
gesture.focused
|
|
592
|
+
);
|
|
593
|
+
}
|
|
594
|
+
if (active.pressed && gesture.pressed) {
|
|
595
|
+
Object.assign(
|
|
596
|
+
merged,
|
|
597
|
+
gesture.pressed
|
|
598
|
+
);
|
|
599
|
+
}
|
|
600
|
+
return merged;
|
|
601
|
+
}
|
|
602
|
+
function useGestureHandlers(gesture, rest, setPressed, setFocused, setHovered) {
|
|
603
|
+
return react.useMemo(() => {
|
|
604
|
+
if (!gesture) return {};
|
|
605
|
+
const handlers = {};
|
|
606
|
+
if (gesture.pressed) {
|
|
607
|
+
handlers.onTouchStart = compose(rest.onTouchStart, () => setPressed(true));
|
|
608
|
+
handlers.onTouchEnd = compose(rest.onTouchEnd, () => setPressed(false));
|
|
609
|
+
handlers.onTouchCancel = compose(
|
|
610
|
+
rest.onTouchCancel,
|
|
611
|
+
() => setPressed(false)
|
|
612
|
+
);
|
|
613
|
+
handlers.onPressIn = compose(rest.onPressIn, () => setPressed(true));
|
|
614
|
+
handlers.onPressOut = compose(rest.onPressOut, () => setPressed(false));
|
|
615
|
+
}
|
|
616
|
+
if (gesture.focused) {
|
|
617
|
+
handlers.onFocus = compose(rest.onFocus, () => setFocused(true));
|
|
618
|
+
handlers.onBlur = compose(rest.onBlur, () => setFocused(false));
|
|
619
|
+
}
|
|
620
|
+
if (gesture.hovered) {
|
|
621
|
+
handlers.onMouseEnter = compose(rest.onMouseEnter, () => setHovered(true));
|
|
622
|
+
handlers.onMouseLeave = compose(
|
|
623
|
+
rest.onMouseLeave,
|
|
624
|
+
() => setHovered(false)
|
|
625
|
+
);
|
|
626
|
+
}
|
|
627
|
+
return handlers;
|
|
628
|
+
}, [
|
|
629
|
+
gesture?.pressed ? 1 : 0,
|
|
630
|
+
gesture?.focused ? 1 : 0,
|
|
631
|
+
gesture?.hovered ? 1 : 0,
|
|
632
|
+
rest.onTouchStart,
|
|
633
|
+
rest.onTouchEnd,
|
|
634
|
+
rest.onTouchCancel,
|
|
635
|
+
rest.onPressIn,
|
|
636
|
+
rest.onPressOut,
|
|
637
|
+
rest.onFocus,
|
|
638
|
+
rest.onBlur,
|
|
639
|
+
rest.onMouseEnter,
|
|
640
|
+
rest.onMouseLeave
|
|
641
|
+
]);
|
|
642
|
+
}
|
|
643
|
+
function compose(user, ours) {
|
|
644
|
+
if (typeof user !== "function") return ours;
|
|
645
|
+
return (event) => {
|
|
646
|
+
user(event);
|
|
647
|
+
ours(event);
|
|
648
|
+
};
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
// src/motion/Pressable.tsx
|
|
652
|
+
var MotionPressable = createMotionComponent(reactNative.Pressable);
|
|
653
|
+
|
|
654
|
+
exports.MotionPressable = MotionPressable;
|
|
655
|
+
//# sourceMappingURL=Pressable.js.map
|
|
656
|
+
//# sourceMappingURL=Pressable.js.map
|