@rootnative/inertia 0.0.0-alpha.3 → 0.0.0-alpha.5
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 +16 -0
- package/dist/{chunk-S4AEU72O.js → chunk-2HYD2ZBK.js} +2 -2
- package/dist/chunk-3UTJJ4A3.js +8 -0
- package/dist/{chunk-K7ICHCTZ.js → chunk-4PEHWDAZ.js} +7 -7
- package/dist/chunk-4QGXK6TF.js +8 -0
- package/dist/{chunk-RJNR7CFN.mjs → chunk-6SMPIOIC.mjs} +1 -1
- package/dist/{chunk-JWHKMNYA.js → chunk-7AOERN53.js} +4 -3
- package/dist/{chunk-KVSJWO5X.js → chunk-7UDYEFBU.js} +22 -22
- package/dist/{chunk-UM3WVSKQ.mjs → chunk-ALRHDFZE.mjs} +1 -1
- package/dist/{chunk-KARV7QKF.mjs → chunk-CWLFUYIY.mjs} +1 -1
- package/dist/{chunk-6FENLMCA.mjs → chunk-CY7Y64C3.mjs} +17 -1
- package/dist/{chunk-UXK4YCT6.mjs → chunk-DWCLIBYO.mjs} +2 -2
- package/dist/{chunk-FSPQVLBF.mjs → chunk-JVBXPF2G.mjs} +1 -1
- package/dist/{chunk-E4MDU4YV.mjs → chunk-NXDJZD6A.mjs} +1 -1
- package/dist/{chunk-SFRNO6AW.js → chunk-PTRF47DA.js} +17 -0
- package/dist/{chunk-GJD4VVAS.mjs → chunk-R63GIUNU.mjs} +2 -1
- package/dist/{chunk-W6IS4HAK.mjs → chunk-RGNX6UZN.mjs} +2 -2
- package/dist/{chunk-5RCMIJGZ.js → chunk-TDSO63CJ.js} +2 -2
- package/dist/chunk-Z7HIOFKQ.js +8 -0
- package/dist/gestureLayer/index.js +10 -10
- package/dist/gestureLayer/index.mjs +3 -3
- package/dist/index.d.mts +19 -11
- package/dist/index.d.ts +19 -11
- package/dist/index.js +52 -44
- package/dist/index.mjs +28 -20
- package/dist/motion/Image.js +5 -5
- package/dist/motion/Image.mjs +4 -4
- package/dist/motion/Pressable.js +5 -5
- package/dist/motion/Pressable.mjs +4 -4
- package/dist/motion/ScrollView.js +5 -5
- package/dist/motion/ScrollView.mjs +4 -4
- package/dist/motion/Text.js +5 -5
- package/dist/motion/Text.mjs +4 -4
- package/dist/motion/View.js +5 -5
- package/dist/motion/View.mjs +4 -4
- package/dist/touch/index.js +3 -3
- package/dist/touch/index.mjs +1 -1
- package/package.json +2 -2
- package/src/gestures/focusVisibility.ts +15 -4
- package/src/internal/nonWorkletWarning.ts +41 -0
- package/src/layout/resolveLayout.ts +3 -2
- package/src/transitions/easing.ts +13 -8
- package/src/values/useTransform.ts +28 -12
- package/dist/chunk-NJYRN3WG.js +0 -8
- package/dist/chunk-R3ODWDTI.js +0 -8
- package/dist/chunk-UMFBAFZP.js +0 -8
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
// `react-native-worklets` is a required peer of Reanimated 4, so the direct
|
|
11
11
|
// import is always available wherever Inertia is.
|
|
12
12
|
import { isWorkletFunction } from 'react-native-worklets'
|
|
13
|
+
import { warnNonWorkletOnce } from '../internal/nonWorkletWarning'
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Extrapolation behavior at the edges of the input range. Mirrors
|
|
@@ -36,9 +37,17 @@ export interface UseTransformOptions {
|
|
|
36
37
|
* const distance = useTransform(() => Math.sqrt(x.value ** 2 + y.value ** 2))
|
|
37
38
|
* ```
|
|
38
39
|
*
|
|
39
|
-
* The transformer
|
|
40
|
-
*
|
|
41
|
-
*
|
|
40
|
+
* The transformer MUST be a worklet — put the `'worklet'` directive as its
|
|
41
|
+
* first statement so the consumer's Babel plugin captures the shared values
|
|
42
|
+
* it reads as its closure. It runs on the UI thread on every frame where
|
|
43
|
+
* any read shared value changes.
|
|
44
|
+
*
|
|
45
|
+
* A plain function cannot work here, and the hook warns in dev when it gets
|
|
46
|
+
* one: the best-effort wrapper it falls back to closes over the opaque
|
|
47
|
+
* function reference, not the shared values read inside it, so Reanimated
|
|
48
|
+
* can't track them as dependencies — the derived value only refreshes on
|
|
49
|
+
* React re-renders, and native builds reject the plain function when the
|
|
50
|
+
* closure crosses to the UI thread.
|
|
42
51
|
*/
|
|
43
52
|
export function useTransform<T>(transformer: () => T): SharedValue<T>
|
|
44
53
|
|
|
@@ -80,16 +89,23 @@ export function useTransform<T>(
|
|
|
80
89
|
// interpolation) is decided once at JS time, never at frame time.
|
|
81
90
|
let producer: () => unknown
|
|
82
91
|
if (typeof arg1 === 'function') {
|
|
83
|
-
// Transformer overload.
|
|
84
|
-
//
|
|
85
|
-
//
|
|
92
|
+
// Transformer overload. Must be a worklet — the directive-wrapped
|
|
93
|
+
// fallback below is best-effort only (its closure holds the opaque
|
|
94
|
+
// function, not the shared values read inside it, so dependency
|
|
95
|
+
// tracking cannot work — see `warnNonWorkletOnce`).
|
|
86
96
|
const userFn = arg1 as () => T
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
97
|
+
if (isWorkletFunction(userFn)) {
|
|
98
|
+
producer = userFn
|
|
99
|
+
} else {
|
|
100
|
+
warnNonWorkletOnce(
|
|
101
|
+
'useTransform-transformer',
|
|
102
|
+
"[inertia] useTransform: the transformer is not a worklet, so the shared values it reads can't be tracked as dependencies — the derived value will only refresh on React re-renders, and native builds reject plain functions on the UI thread. Add the 'worklet' directive as the first statement of the transformer.",
|
|
103
|
+
)
|
|
104
|
+
producer = () => {
|
|
105
|
+
'worklet'
|
|
106
|
+
return userFn()
|
|
107
|
+
}
|
|
108
|
+
}
|
|
93
109
|
} else {
|
|
94
110
|
// Interpolation overload. We pre-resolve everything JS-side so the
|
|
95
111
|
// worklet body only consumes flat values.
|
package/dist/chunk-NJYRN3WG.js
DELETED
package/dist/chunk-R3ODWDTI.js
DELETED
package/dist/chunk-UMFBAFZP.js
DELETED