Skip to content

Commit

Permalink
fix(💄): new utility functions
Browse files Browse the repository at this point in the history
  • Loading branch information
wcandillon committed Aug 30, 2021
1 parent f7e2c8b commit 0f595a1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/Matrix3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,14 @@ export const multiply3 = (m1: Matrix3, m2: Matrix3) => {
] as const;
};

export const serializeToSVGMatrixArray = (m: Matrix3) => {
const serializeToSVGMatrix = (m: Matrix3) => {
"worklet";
return [m[0][0], m[1][0], m[0][1], m[1][1], m[0][2], m[1][2]];
return `matrix(${m[0][0]}, ${m[1][0]}, ${m[0][1]}, ${m[1][1]}, ${m[0][2]}, ${m[1][2]})`;
};

export const serializeToSVGMatrix = (m: Matrix3) => {
export const svgMatrix = (transforms: Transforms2d) => {
"worklet";
return `matrix(${m[0][0]}, ${m[1][0]}, ${m[0][1]}, ${m[1][1]}, ${m[0][2]}, ${m[1][2]})`;
return serializeToSVGMatrix(processTransform2d(transforms));
};

export const processTransform2d = (transforms: Transforms2d) => {
Expand Down
7 changes: 6 additions & 1 deletion src/Transforms.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { TransformsStyle } from "react-native";
import type Animated from "react-native-reanimated";
import { useAnimatedStyle } from "react-native-reanimated";

import type { Vector } from "./Vectors";
import type { Transforms2d } from "./Matrix3";
Expand Down Expand Up @@ -33,7 +35,10 @@ export const transformOrigin2d = (
];
};

export const useTranslation = ({ x, y }: Vector<Animated.SharedValue<number>>) =>
export const useTranslation = ({
x,
y,
}: Vector<Animated.SharedValue<number>>) =>
useAnimatedStyle(() => ({
transform: [{ translateX: x.value }, { translateY: y.value }],
}));

0 comments on commit 0f595a1

Please sign in to comment.