Skip to content

Commit 4035d2f

Browse files
authored
chore: Update example to run on fabric (#3102)
1 parent 6ef2f7b commit 4035d2f

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

Diff for: apps/paper/src/Examples/Stickers/GestureHandler.tsx

+11-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ import Animated, {
1717
useSharedValue,
1818
} from "react-native-reanimated";
1919

20+
const multiply = (...matrices: Matrix4[]) => {
21+
"worklet";
22+
return matrices.reduce((acc, matrix) => multiply4(acc, matrix), Matrix4());
23+
};
24+
2025
interface GestureHandlerProps {
2126
matrix: SharedValue<Matrix4>;
2227
dimensions: SkRect;
@@ -60,7 +65,12 @@ export const GestureHandler = ({
6065
});
6166

6267
const style = useAnimatedStyle(() => {
63-
const m4 = convertToColumnMajor(matrix.value);
68+
const m = multiply(
69+
translate(-width / 2, -height / 2),
70+
matrix.value,
71+
translate(width / 2, height / 2)
72+
);
73+
const m4 = convertToColumnMajor(m);
6474
return {
6575
position: "absolute",
6676
left: x,
@@ -69,16 +79,12 @@ export const GestureHandler = ({
6979
height,
7080
backgroundColor: debug ? "rgba(100, 200, 300, 0.4)" : "transparent",
7181
transform: [
72-
{ translateX: -width / 2 },
73-
{ translateY: -height / 2 },
7482
{
7583
matrix:
7684
Platform.OS === "web"
7785
? convertToAffineMatrix(m4)
7886
: (m4 as unknown as number[]),
7987
},
80-
{ translateX: width / 2 },
81-
{ translateY: height / 2 },
8288
],
8389
};
8490
});

0 commit comments

Comments
 (0)