@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/dist/motion/Text.d.mts
CHANGED
package/dist/motion/Text.d.ts
CHANGED
package/dist/motion/Text.js
CHANGED
|
@@ -1207,8 +1207,8 @@ function setupSetTimeout() {
|
|
|
1207
1207
|
const start = performance.now();
|
|
1208
1208
|
let timeoutHandle = 0;
|
|
1209
1209
|
const rafCallback = () => {
|
|
1210
|
-
const
|
|
1211
|
-
if (
|
|
1210
|
+
const now2 = performance.now();
|
|
1211
|
+
if (now2 - start >= delay) {
|
|
1212
1212
|
callback(...args);
|
|
1213
1213
|
timeoutHandleToRafHandle.delete(timeoutHandle);
|
|
1214
1214
|
} else {
|
|
@@ -1502,6 +1502,157 @@ function resolveLayoutTransition(layout) {
|
|
|
1502
1502
|
if ("delay" in spring && spring.delay) builder = builder.delay(spring.delay);
|
|
1503
1503
|
return builder;
|
|
1504
1504
|
}
|
|
1505
|
+
|
|
1506
|
+
// src/layout/sharedRegistry.ts
|
|
1507
|
+
var REGISTRY = /* @__PURE__ */ new Map();
|
|
1508
|
+
var SHARED_LAYOUT_TTL_MS = 1e3;
|
|
1509
|
+
var now = () => Date.now();
|
|
1510
|
+
function registerLayout(id, rect) {
|
|
1511
|
+
REGISTRY.set(id, { rect, expiresAt: now() + SHARED_LAYOUT_TTL_MS });
|
|
1512
|
+
}
|
|
1513
|
+
function releaseLayout(id, rect) {
|
|
1514
|
+
REGISTRY.set(id, { rect, expiresAt: now() + SHARED_LAYOUT_TTL_MS });
|
|
1515
|
+
}
|
|
1516
|
+
function consumeLayout(id) {
|
|
1517
|
+
const entry = REGISTRY.get(id);
|
|
1518
|
+
if (!entry) return void 0;
|
|
1519
|
+
REGISTRY.delete(id);
|
|
1520
|
+
if (entry.expiresAt < now()) return void 0;
|
|
1521
|
+
return entry.rect;
|
|
1522
|
+
}
|
|
1523
|
+
function useSharedLayout(options) {
|
|
1524
|
+
const { layoutId, userRef, transition, shouldReduceMotion, userOnLayout } = options;
|
|
1525
|
+
const dx = Animated.useSharedValue(0);
|
|
1526
|
+
const dy = Animated.useSharedValue(0);
|
|
1527
|
+
const sx = Animated.useSharedValue(1);
|
|
1528
|
+
const sy = Animated.useSharedValue(1);
|
|
1529
|
+
const lastRectRef = react.useRef(null);
|
|
1530
|
+
const consumedRef = react.useRef(false);
|
|
1531
|
+
const transitionRef = react.useRef(transition);
|
|
1532
|
+
transitionRef.current = transition;
|
|
1533
|
+
const reducedMotionRef = react.useRef(shouldReduceMotion);
|
|
1534
|
+
reducedMotionRef.current = shouldReduceMotion;
|
|
1535
|
+
const setRef = react.useCallback(
|
|
1536
|
+
(node) => {
|
|
1537
|
+
if (typeof userRef === "function") userRef(node);
|
|
1538
|
+
else if (userRef) userRef.current = node;
|
|
1539
|
+
},
|
|
1540
|
+
[userRef]
|
|
1541
|
+
);
|
|
1542
|
+
const onLayout = react.useCallback(
|
|
1543
|
+
(event) => {
|
|
1544
|
+
userOnLayout?.(event);
|
|
1545
|
+
if (!layoutId) return;
|
|
1546
|
+
const { x, y, width, height } = event.nativeEvent.layout;
|
|
1547
|
+
const rect = { x, y, width, height };
|
|
1548
|
+
lastRectRef.current = rect;
|
|
1549
|
+
let source;
|
|
1550
|
+
if (!consumedRef.current) {
|
|
1551
|
+
consumedRef.current = true;
|
|
1552
|
+
source = consumeLayout(layoutId);
|
|
1553
|
+
}
|
|
1554
|
+
registerLayout(layoutId, rect);
|
|
1555
|
+
if (source) {
|
|
1556
|
+
applyFlip({
|
|
1557
|
+
source,
|
|
1558
|
+
target: rect,
|
|
1559
|
+
dx,
|
|
1560
|
+
dy,
|
|
1561
|
+
sx,
|
|
1562
|
+
sy,
|
|
1563
|
+
transition: transitionRef.current,
|
|
1564
|
+
shouldReduceMotion: reducedMotionRef.current
|
|
1565
|
+
});
|
|
1566
|
+
}
|
|
1567
|
+
},
|
|
1568
|
+
// dx/dy/sx/sy are stable refs from useSharedValue, but eslint's
|
|
1569
|
+
// exhaustive-deps would flag them — including them is harmless and
|
|
1570
|
+
// silences the warning.
|
|
1571
|
+
[layoutId, userOnLayout, dx, dy, sx, sy]
|
|
1572
|
+
);
|
|
1573
|
+
react.useEffect(() => {
|
|
1574
|
+
consumedRef.current = false;
|
|
1575
|
+
}, [layoutId]);
|
|
1576
|
+
react.useEffect(() => {
|
|
1577
|
+
return () => {
|
|
1578
|
+
if (!layoutId) return;
|
|
1579
|
+
const rect = lastRectRef.current;
|
|
1580
|
+
if (!rect) return;
|
|
1581
|
+
releaseLayout(layoutId, rect);
|
|
1582
|
+
};
|
|
1583
|
+
}, [layoutId]);
|
|
1584
|
+
return react.useMemo(
|
|
1585
|
+
() => ({
|
|
1586
|
+
flip: { dx, dy, sx, sy },
|
|
1587
|
+
setRef,
|
|
1588
|
+
onLayout
|
|
1589
|
+
}),
|
|
1590
|
+
[dx, dy, sx, sy, setRef, onLayout]
|
|
1591
|
+
);
|
|
1592
|
+
}
|
|
1593
|
+
function applyFlip(args) {
|
|
1594
|
+
const { source, target, dx, dy, sx, sy, transition, shouldReduceMotion } = args;
|
|
1595
|
+
const sourceCenterX = source.x + source.width / 2;
|
|
1596
|
+
const sourceCenterY = source.y + source.height / 2;
|
|
1597
|
+
const targetCenterX = target.x + target.width / 2;
|
|
1598
|
+
const targetCenterY = target.y + target.height / 2;
|
|
1599
|
+
const deltaX = sourceCenterX - targetCenterX;
|
|
1600
|
+
const deltaY = sourceCenterY - targetCenterY;
|
|
1601
|
+
const scaleX = target.width > 0 ? source.width / target.width : 1;
|
|
1602
|
+
const scaleY = target.height > 0 ? source.height / target.height : 1;
|
|
1603
|
+
if (shouldReduceMotion) {
|
|
1604
|
+
dx.value = 0;
|
|
1605
|
+
dy.value = 0;
|
|
1606
|
+
sx.value = 1;
|
|
1607
|
+
sy.value = 1;
|
|
1608
|
+
return;
|
|
1609
|
+
}
|
|
1610
|
+
if (transition?.type === "no-animation") {
|
|
1611
|
+
dx.value = 0;
|
|
1612
|
+
dy.value = 0;
|
|
1613
|
+
sx.value = 1;
|
|
1614
|
+
sy.value = 1;
|
|
1615
|
+
return;
|
|
1616
|
+
}
|
|
1617
|
+
if (transition?.type === "timing") {
|
|
1618
|
+
const duration = transition.duration ?? 300;
|
|
1619
|
+
dx.value = Animated.withSequence(
|
|
1620
|
+
Animated.withTiming(deltaX, { duration: 0 }),
|
|
1621
|
+
Animated.withTiming(0, { duration })
|
|
1622
|
+
);
|
|
1623
|
+
dy.value = Animated.withSequence(
|
|
1624
|
+
Animated.withTiming(deltaY, { duration: 0 }),
|
|
1625
|
+
Animated.withTiming(0, { duration })
|
|
1626
|
+
);
|
|
1627
|
+
sx.value = Animated.withSequence(
|
|
1628
|
+
Animated.withTiming(scaleX, { duration: 0 }),
|
|
1629
|
+
Animated.withTiming(1, { duration })
|
|
1630
|
+
);
|
|
1631
|
+
sy.value = Animated.withSequence(
|
|
1632
|
+
Animated.withTiming(scaleY, { duration: 0 }),
|
|
1633
|
+
Animated.withTiming(1, { duration })
|
|
1634
|
+
);
|
|
1635
|
+
return;
|
|
1636
|
+
}
|
|
1637
|
+
const springCfg = transition?.type === "spring" ? { ...DEFAULT_SPRING, ...transition } : { ...DEFAULT_SPRING };
|
|
1638
|
+
const springParams = springToReanimated(springCfg);
|
|
1639
|
+
dx.value = Animated.withSequence(
|
|
1640
|
+
Animated.withTiming(deltaX, { duration: 0 }),
|
|
1641
|
+
Animated.withSpring(0, springParams)
|
|
1642
|
+
);
|
|
1643
|
+
dy.value = Animated.withSequence(
|
|
1644
|
+
Animated.withTiming(deltaY, { duration: 0 }),
|
|
1645
|
+
Animated.withSpring(0, springParams)
|
|
1646
|
+
);
|
|
1647
|
+
sx.value = Animated.withSequence(
|
|
1648
|
+
Animated.withTiming(scaleX, { duration: 0 }),
|
|
1649
|
+
Animated.withSpring(1, springParams)
|
|
1650
|
+
);
|
|
1651
|
+
sy.value = Animated.withSequence(
|
|
1652
|
+
Animated.withTiming(scaleY, { duration: 0 }),
|
|
1653
|
+
Animated.withSpring(1, springParams)
|
|
1654
|
+
);
|
|
1655
|
+
}
|
|
1505
1656
|
var PresenceContext = react.createContext(null);
|
|
1506
1657
|
function usePresence() {
|
|
1507
1658
|
return react.useContext(PresenceContext);
|
|
@@ -1790,10 +1941,17 @@ function createMotionComponent(Component) {
|
|
|
1790
1941
|
controller,
|
|
1791
1942
|
gesture,
|
|
1792
1943
|
layout,
|
|
1944
|
+
layoutId,
|
|
1793
1945
|
onAnimationEnd,
|
|
1794
1946
|
style,
|
|
1947
|
+
onLayout: userOnLayout,
|
|
1795
1948
|
...rest
|
|
1796
1949
|
} = props;
|
|
1950
|
+
if (__DEV__ && typeof style === "function") {
|
|
1951
|
+
throw new Error(
|
|
1952
|
+
"[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."
|
|
1953
|
+
);
|
|
1954
|
+
}
|
|
1797
1955
|
const presence = usePresence();
|
|
1798
1956
|
const isExiting = presence !== null && presence.isPresent === false;
|
|
1799
1957
|
const shouldReduceMotion = useShouldReduceMotion();
|
|
@@ -1967,6 +2125,15 @@ function createMotionComponent(Component) {
|
|
|
1967
2125
|
isExiting,
|
|
1968
2126
|
shouldReduceMotion
|
|
1969
2127
|
);
|
|
2128
|
+
const sharedLayout = useSharedLayout({
|
|
2129
|
+
layoutId,
|
|
2130
|
+
userRef: ref,
|
|
2131
|
+
transition: isTopLevelTransition(transition) ? transition : void 0,
|
|
2132
|
+
shouldReduceMotion,
|
|
2133
|
+
userOnLayout
|
|
2134
|
+
});
|
|
2135
|
+
const flip = sharedLayout.flip;
|
|
2136
|
+
const hasLayoutId = layoutId !== void 0;
|
|
1970
2137
|
const animatedStyle = Animated.useAnimatedStyle(() => {
|
|
1971
2138
|
const activeKeys = activeKeysRef.current;
|
|
1972
2139
|
const hasTransform = hasTransformRef.current;
|
|
@@ -2015,7 +2182,13 @@ function createMotionComponent(Component) {
|
|
|
2015
2182
|
out[key] = v;
|
|
2016
2183
|
}
|
|
2017
2184
|
}
|
|
2018
|
-
if (
|
|
2185
|
+
if (hasLayoutId) {
|
|
2186
|
+
transform.push({ translateX: flip.dx.value });
|
|
2187
|
+
transform.push({ translateY: flip.dy.value });
|
|
2188
|
+
transform.push({ scaleX: flip.sx.value });
|
|
2189
|
+
transform.push({ scaleY: flip.sy.value });
|
|
2190
|
+
}
|
|
2191
|
+
if (hasTransform || hasLayoutId) out.transform = transform;
|
|
2019
2192
|
if (hasShadowOffset) {
|
|
2020
2193
|
out.shadowOffset = { width: shadowOffsetW, height: shadowOffsetH };
|
|
2021
2194
|
}
|
|
@@ -2042,9 +2215,10 @@ function createMotionComponent(Component) {
|
|
|
2042
2215
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2043
2216
|
AnimatedComponent,
|
|
2044
2217
|
{
|
|
2045
|
-
ref,
|
|
2218
|
+
ref: sharedLayout.setRef,
|
|
2046
2219
|
...rest,
|
|
2047
2220
|
...gestureHandlers,
|
|
2221
|
+
onLayout: sharedLayout.onLayout,
|
|
2048
2222
|
layout: layoutTransition,
|
|
2049
2223
|
style: mergedStyle
|
|
2050
2224
|
}
|