Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions src/Transform2d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,13 @@ export function apply2dTransforms({
}
}

const Transform2d = ({
children,
export function use2dTransformations({
parentMatrixWorld,
translate,
scale,
rotate,
multiplicationOrder = 'POST',
}: Transform2dProps) => {
}: Omit<Transform2dProps, 'children'>) {
const safeParentMatrixWorld = useFactoryRef<mat2d>(
() => parentMatrixWorld || mat2d.create(),
);
Expand All @@ -101,6 +100,28 @@ const Transform2d = ({
rotate,
});

return {
matrix,
matrixWorld,
};
}

const Transform2d = ({
children,
parentMatrixWorld,
translate,
scale,
rotate,
multiplicationOrder = 'POST',
}: Transform2dProps) => {
const { matrixWorld } = use2dTransformations({
parentMatrixWorld,
translate,
scale,
rotate,
multiplicationOrder,
});

const render = useRender<mat2d>({
cssMatrixPrefix: 'matrix',
matrixWorld,
Expand Down
29 changes: 26 additions & 3 deletions src/Transform3d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,14 @@ export function apply3dTransforms({
}
}

const Transform3d = ({
children,
export function use3dTransformations({
parentMatrixWorld,
translate,
scale,
rotate,
rotateAxis,
multiplicationOrder = 'POST',
}: Transform3dProps) => {
}: Omit<Transform3dProps, 'children'>) {
const safeParentMatrixWorld = useFactoryRef<mat4>(
() => parentMatrixWorld || mat4.create(),
);
Expand All @@ -112,6 +111,30 @@ const Transform3d = ({
rotateAxis,
});

return {
matrix,
matrixWorld,
};
}

const Transform3d = ({
children,
parentMatrixWorld,
translate,
scale,
rotate,
rotateAxis,
multiplicationOrder = 'POST',
}: Transform3dProps) => {
const { matrixWorld } = use3dTransformations({
parentMatrixWorld,
translate,
scale,
rotate,
rotateAxis,
multiplicationOrder,
});

const render = useRender<mat4>({
cssMatrixPrefix: 'matrix3d',
matrixWorld,
Expand Down
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './propTypes';
export { useFactoryRef } from './useFactoryRef';
export { default as Transform2d } from './Transform2d';
export { default as Transform3d } from './Transform3d';
export { default as Transform2d, use2dTransformations } from './Transform2d';
export { default as Transform3d, use3dTransformations } from './Transform3d';
export type { Transform2dProps } from './Transform2d';
export type { Transform3dProps } from './Transform3d';
export type { GLMatrixType, Vec2Object, Vec3Object } from './types';
2 changes: 2 additions & 0 deletions test/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ exports[`index export modules for react-css-transform 1`] = `
"mat2dGlMatrix": [Function],
"mat4GlMatrix": [Function],
"mat4GlMatrixValidator": [Function],
"use2dTransformations": [Function],
"use3dTransformations": [Function],
"useFactoryRef": [Function],
"vec2GlMatrix": [Function],
"vec2Obj": [Function],
Expand Down