You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/animations/hooks.md
+79-19Lines changed: 79 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,77 @@ sidebar_label: Hooks
5
5
slug: /animations/hooks
6
6
---
7
7
8
+
## usePathInterpolation
9
+
10
+
This hook interpolates between different path values based on a progress value, providing smooth transitions between the provided paths.
11
+
12
+
Paths need to be interpolatable, meaning they must contain the same number and types of commands. If the paths have different commands or different numbers of commands, the interpolation may not behave as expected. Ensure that all paths in the `outputRange` array are structured similarly for proper interpolation.
This hook returns a number indicating the time in milliseconds since the hook was activated.
@@ -32,31 +103,20 @@ export default function App() {
32
103
}
33
104
```
34
105
35
-
## usePathInterpolation
36
-
37
-
This hook interpolates between different path values based on a progress value, providing smooth transitions between the provided paths.
106
+
## Canvas Size
38
107
39
-
Paths need to be interpolatable, meaning they must contain the same number and types of commands. If the paths have different commands or different numbers of commands, the interpolation may not behave as expected. Ensure that all paths in the `outputRange` array are structured similarly for proper interpolation.
108
+
The Canvas element has an `onSize` property that can receive a shared value, which will be updated whenever the canvas size changes.
When animating with React Native Skia, we recommend avoiding new JSI allocations on each frame. Instead of creating a new value on each frame to notify Reanimated that the value has changed, directly mutate the value and notify Reanimated. Below are examples illustrating this pattern:
// ✅ Instead, mutate the value directly and notify Reanimated
68
-
path.value.lineTo(e.changeX, e.changeY);
69
-
notifyChange(path);
70
-
});
71
-
72
-
const pinch =Gesture.Pinch().onChange((e) => {
73
-
// ❌ Avoid creating a new matrix on every frame
74
-
const newMatrix =Skia.Matrix(matrix.value.get());
75
-
matrix.value=newMatrix.scale(e.scale);
76
-
});
77
-
78
-
const pinch2 =Gesture.Pinch().onChange((e) => {
79
-
// ✅ Mutate the value and notify Reanimated
80
-
matrix.value.scale(e.scale);
81
-
notifyChange(matrix);
82
-
});
83
-
```
84
-
85
-
`path.interpolate` now has an extra parameter to interpolate paths without allocating new paths. We provide a [usePathInterpolation](/docs/animations/hooks#usepathinterpolation) hook that will do all the heavy lifting for you.
86
-
87
-
## Canvas Size
88
-
89
-
The Canvas element has an `onSize` property that can receive a shared value, which will be updated whenever the canvas size changes.
0 commit comments