@rootnative/inertia 0.0.0-alpha.0 → 0.0.0-alpha.1
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 +10 -0
- package/README.md +2 -0
- package/dist/gestureLayer/index.d.mts +6 -5
- package/dist/gestureLayer/index.d.ts +6 -5
- package/dist/gestureLayer/index.js +89 -27
- package/dist/gestureLayer/index.js.map +1 -1
- package/dist/gestureLayer/index.mjs +89 -27
- package/dist/gestureLayer/index.mjs.map +1 -1
- package/dist/index.d.mts +127 -16
- package/dist/index.d.ts +127 -16
- package/dist/index.js +177 -60
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +175 -61
- 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 +90 -48
- package/dist/motion/Image.js.map +1 -1
- package/dist/motion/Image.mjs +90 -48
- 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 +90 -48
- package/dist/motion/Pressable.js.map +1 -1
- package/dist/motion/Pressable.mjs +90 -48
- 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 +90 -48
- package/dist/motion/ScrollView.js.map +1 -1
- package/dist/motion/ScrollView.mjs +90 -48
- 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 +90 -48
- package/dist/motion/Text.js.map +1 -1
- package/dist/motion/Text.mjs +90 -48
- 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 +90 -48
- package/dist/motion/View.js.map +1 -1
- package/dist/motion/View.mjs +90 -48
- package/dist/motion/View.mjs.map +1 -1
- package/dist/touch/index.d.mts +1 -1
- package/dist/touch/index.d.ts +1 -1
- package/dist/{types-cU43dEmH.d.mts → types-BzEgiUdJ.d.mts} +58 -9
- package/dist/{types-cU43dEmH.d.ts → types-BzEgiUdJ.d.ts} +58 -9
- package/dist/{useGesture-BnY65PlQ.d.ts → useGesture-BRLgiNOC.d.ts} +6 -4
- package/dist/{useGesture-DxtXdz-K.d.mts → useGesture-C0GBS7d2.d.mts} +6 -4
- package/llms.txt +8 -4
- package/package.json +1 -1
- package/src/__type-tests__/motion-value.test-d.ts +39 -0
- package/src/config/MotionConfig.tsx +55 -9
- package/src/config/MotionConfigContext.ts +21 -1
- package/src/config/index.ts +7 -1
- package/src/config/namedTransitions.ts +80 -0
- package/src/gestureLayer/useGestureLayer.ts +32 -8
- package/src/index.ts +20 -2
- package/src/motion/createMotionComponent.tsx +36 -6
- package/src/transitions/cubicBezier.ts +126 -0
- package/src/transitions/index.ts +1 -0
- package/src/types.ts +63 -8
- package/src/values/useAnimation.ts +12 -6
- package/src/values/useBooleanSpring.ts +5 -3
- package/src/values/useGesture.ts +25 -7
- package/src/values/useMotionValue.ts +11 -0
- package/src/values/useScroll.ts +8 -1
- package/src/values/useSpring.ts +46 -9
|
@@ -5,8 +5,31 @@ import { isWorkletFunction } from 'react-native-worklets';
|
|
|
5
5
|
import { jsx } from 'react/jsx-runtime';
|
|
6
6
|
|
|
7
7
|
// src/motion/ScrollView.tsx
|
|
8
|
+
|
|
9
|
+
// src/transitions/sig.ts
|
|
10
|
+
function stableSig(value) {
|
|
11
|
+
if (value === void 0) return "";
|
|
12
|
+
try {
|
|
13
|
+
return stableStringify(value);
|
|
14
|
+
} catch {
|
|
15
|
+
return String(value);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function stableStringify(v) {
|
|
19
|
+
if (v === null || typeof v !== "object") {
|
|
20
|
+
if (typeof v === "function" || v === void 0) return "null";
|
|
21
|
+
return JSON.stringify(v);
|
|
22
|
+
}
|
|
23
|
+
if (Array.isArray(v)) {
|
|
24
|
+
return "[" + v.map(stableStringify).join(",") + "]";
|
|
25
|
+
}
|
|
26
|
+
const obj = v;
|
|
27
|
+
const keys = Object.keys(obj).sort();
|
|
28
|
+
return "{" + keys.map((k) => JSON.stringify(k) + ":" + stableStringify(obj[k])).join(",") + "}";
|
|
29
|
+
}
|
|
8
30
|
var DEFAULT_MOTION_CONFIG = {
|
|
9
|
-
reducedMotion: "user"
|
|
31
|
+
reducedMotion: "user",
|
|
32
|
+
transitions: {}
|
|
10
33
|
};
|
|
11
34
|
var MotionConfigContext = createContext(
|
|
12
35
|
DEFAULT_MOTION_CONFIG
|
|
@@ -14,6 +37,9 @@ var MotionConfigContext = createContext(
|
|
|
14
37
|
function useMotionConfig() {
|
|
15
38
|
return useContext(MotionConfigContext);
|
|
16
39
|
}
|
|
40
|
+
function useNamedTransitions() {
|
|
41
|
+
return useMotionConfig().transitions;
|
|
42
|
+
}
|
|
17
43
|
function useShouldReduceMotion() {
|
|
18
44
|
const { reducedMotion } = useMotionConfig();
|
|
19
45
|
const osReduced = useReducedMotion();
|
|
@@ -21,6 +47,59 @@ function useShouldReduceMotion() {
|
|
|
21
47
|
if (reducedMotion === "always") return true;
|
|
22
48
|
return osReduced;
|
|
23
49
|
}
|
|
50
|
+
|
|
51
|
+
// src/transitions/keys.ts
|
|
52
|
+
var TRANSITION_CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
53
|
+
"type",
|
|
54
|
+
"tension",
|
|
55
|
+
"friction",
|
|
56
|
+
"mass",
|
|
57
|
+
"velocity",
|
|
58
|
+
"restSpeedThreshold",
|
|
59
|
+
"restDisplacementThreshold",
|
|
60
|
+
"duration",
|
|
61
|
+
"easing",
|
|
62
|
+
"delay",
|
|
63
|
+
"repeat",
|
|
64
|
+
"deceleration",
|
|
65
|
+
"clamp"
|
|
66
|
+
]);
|
|
67
|
+
function isTopLevelTransition(t) {
|
|
68
|
+
if (t === null || typeof t !== "object") return false;
|
|
69
|
+
const keys = Object.keys(t);
|
|
70
|
+
if (keys.length === 0) return false;
|
|
71
|
+
return keys.every((k) => TRANSITION_CONFIG_KEYS.has(k));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// src/config/namedTransitions.ts
|
|
75
|
+
var UNKNOWN_NAME_FALLBACK = { type: "spring" };
|
|
76
|
+
function lookupNamedTransition(name, registry) {
|
|
77
|
+
const cfg = registry[name];
|
|
78
|
+
if (cfg) return cfg;
|
|
79
|
+
if (__DEV__) {
|
|
80
|
+
console.warn(
|
|
81
|
+
`[inertia] Unknown transition name "${name}" \u2014 falling back to the default spring. Register it on a provider: <MotionConfig transitions={{ '${name}': { ... } }}>.`
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
return UNKNOWN_NAME_FALLBACK;
|
|
85
|
+
}
|
|
86
|
+
function resolveNamedTransitionProp(transition, registry) {
|
|
87
|
+
if (transition === void 0) return void 0;
|
|
88
|
+
if (typeof transition === "string") {
|
|
89
|
+
return lookupNamedTransition(transition, registry);
|
|
90
|
+
}
|
|
91
|
+
if (isTopLevelTransition(transition)) return transition;
|
|
92
|
+
const map = transition;
|
|
93
|
+
let out = null;
|
|
94
|
+
for (const key in map) {
|
|
95
|
+
const value = map[key];
|
|
96
|
+
if (typeof value === "string") {
|
|
97
|
+
if (out === null) out = { ...map };
|
|
98
|
+
out[key] = lookupNamedTransition(value, registry);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return out ?? transition;
|
|
102
|
+
}
|
|
24
103
|
var modality = "keyboard";
|
|
25
104
|
var installed = false;
|
|
26
105
|
function setKeyboard() {
|
|
@@ -357,51 +436,6 @@ function mergeTransition(base, override) {
|
|
|
357
436
|
}
|
|
358
437
|
return { ...base ?? { type: "spring" }, ...override };
|
|
359
438
|
}
|
|
360
|
-
|
|
361
|
-
// src/transitions/keys.ts
|
|
362
|
-
var TRANSITION_CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
363
|
-
"type",
|
|
364
|
-
"tension",
|
|
365
|
-
"friction",
|
|
366
|
-
"mass",
|
|
367
|
-
"velocity",
|
|
368
|
-
"restSpeedThreshold",
|
|
369
|
-
"restDisplacementThreshold",
|
|
370
|
-
"duration",
|
|
371
|
-
"easing",
|
|
372
|
-
"delay",
|
|
373
|
-
"repeat",
|
|
374
|
-
"deceleration",
|
|
375
|
-
"clamp"
|
|
376
|
-
]);
|
|
377
|
-
function isTopLevelTransition(t) {
|
|
378
|
-
if (t === null || typeof t !== "object") return false;
|
|
379
|
-
const keys = Object.keys(t);
|
|
380
|
-
if (keys.length === 0) return false;
|
|
381
|
-
return keys.every((k) => TRANSITION_CONFIG_KEYS.has(k));
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
// src/transitions/sig.ts
|
|
385
|
-
function stableSig(value) {
|
|
386
|
-
if (value === void 0) return "";
|
|
387
|
-
try {
|
|
388
|
-
return stableStringify(value);
|
|
389
|
-
} catch {
|
|
390
|
-
return String(value);
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
function stableStringify(v) {
|
|
394
|
-
if (v === null || typeof v !== "object") {
|
|
395
|
-
if (typeof v === "function" || v === void 0) return "null";
|
|
396
|
-
return JSON.stringify(v);
|
|
397
|
-
}
|
|
398
|
-
if (Array.isArray(v)) {
|
|
399
|
-
return "[" + v.map(stableStringify).join(",") + "]";
|
|
400
|
-
}
|
|
401
|
-
const obj = v;
|
|
402
|
-
const keys = Object.keys(obj).sort();
|
|
403
|
-
return "{" + keys.map((k) => JSON.stringify(k) + ":" + stableStringify(obj[k])).join(",") + "}";
|
|
404
|
-
}
|
|
405
439
|
var alreadyChecked = false;
|
|
406
440
|
function ensureReanimatedInstalled() {
|
|
407
441
|
if (!__DEV__ || alreadyChecked) return;
|
|
@@ -504,12 +538,14 @@ var DEFAULT_RESTING = {
|
|
|
504
538
|
};
|
|
505
539
|
function transitionFor(prop, transition) {
|
|
506
540
|
if (!transition) return void 0;
|
|
541
|
+
if (typeof transition === "string") return void 0;
|
|
507
542
|
if (isTopLevelTransition(transition)) return transition;
|
|
508
543
|
if (GESTURE_LAYER_NAME_SET.has(prop)) return void 0;
|
|
509
544
|
return transition[prop];
|
|
510
545
|
}
|
|
511
546
|
function gestureLayerTransitionFor(layer, transition) {
|
|
512
547
|
if (!transition) return void 0;
|
|
548
|
+
if (typeof transition === "string") return void 0;
|
|
513
549
|
if (isTopLevelTransition(transition)) return transition;
|
|
514
550
|
return transition[layer];
|
|
515
551
|
}
|
|
@@ -524,17 +560,23 @@ function createMotionComponent(Component) {
|
|
|
524
560
|
initial,
|
|
525
561
|
animate,
|
|
526
562
|
exit,
|
|
527
|
-
transition,
|
|
563
|
+
transition: transitionProp,
|
|
528
564
|
variants,
|
|
529
565
|
controller,
|
|
530
566
|
gesture,
|
|
531
|
-
layout,
|
|
567
|
+
layout: layoutProp,
|
|
532
568
|
layoutId,
|
|
533
569
|
onAnimationEnd,
|
|
534
570
|
style,
|
|
535
571
|
onLayout: userOnLayout,
|
|
536
572
|
...rest
|
|
537
573
|
} = props;
|
|
574
|
+
const namedTransitions = useNamedTransitions();
|
|
575
|
+
const transition = resolveNamedTransitionProp(
|
|
576
|
+
transitionProp,
|
|
577
|
+
namedTransitions
|
|
578
|
+
);
|
|
579
|
+
const layout = typeof layoutProp === "string" ? lookupNamedTransition(layoutProp, namedTransitions) : layoutProp;
|
|
538
580
|
if (__DEV__ && typeof style === "function") {
|
|
539
581
|
throw new Error(
|
|
540
582
|
"[inertia] `style` must be a style object or array of style objects, not a function. The function-form `style={(state) => ...}` Pressable API is not supported \u2014 use `gesture.pressed` (or `gesture.focused`, etc.) to drive state-dependent styling instead."
|