Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,34 @@ inline void fromRawValue(
}

size_t i = 0;
for (auto number : numbers) {
transformMatrix.matrix[i++] = number;
if (numbers.size() == 16) {
for (auto number : numbers) {
transformMatrix.matrix[i++] = number;
}
} else if (numbers.size() == 9) {
// We need to convert the 2d transform matrix into a 3d one as such:
// [
// x01, x02, 0, x03
Copy link
Contributor

@tomekzaw tomekzaw Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be x00, x01, 0, x02 if we start numbering from 0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be x00, x01, 0, x02 if we start numbering from 0

yeah I believe this is fixed already on main, I followed up in a separate PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, my bad, sorry, all good

// x10, x11, 0, x12
// 0, 0, 1, 0
// x20, x21, 0, x22
// ]
transformMatrix.matrix[0] = numbers[0];
transformMatrix.matrix[1] = numbers[1];
transformMatrix.matrix[2] = 0;
transformMatrix.matrix[3] = numbers[2];
transformMatrix.matrix[4] = numbers[3];
transformMatrix.matrix[5] = numbers[4];
transformMatrix.matrix[6] = 0;
transformMatrix.matrix[7] = numbers[5];
transformMatrix.matrix[8] = 0;
transformMatrix.matrix[9] = 0;
transformMatrix.matrix[10] = 1;
transformMatrix.matrix[11] = 0;
transformMatrix.matrix[12] = numbers[6];
transformMatrix.matrix[13] = numbers[7];
transformMatrix.matrix[14] = 0;
transformMatrix.matrix[15] = numbers[8];
}
transformMatrix.operations.push_back(TransformOperation{
TransformOperationType::Arbitrary, Zero, Zero, Zero});
Expand Down
34 changes: 34 additions & 0 deletions packages/rn-tester/js/examples/Transform/TransformExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ function TranslatePercentage() {
return <View style={styles.translatePercentageView} />;
}

function TranslateMatrix2D() {
return <View style={styles.translateMatrix2D} />;
}
function TranslateMatrix3D() {
return <View style={styles.translateMatrix3D} />;
}

const styles = StyleSheet.create({
container: {
height: 500,
Expand Down Expand Up @@ -288,6 +295,18 @@ const styles = StyleSheet.create({
alignSelf: 'flex-start',
backgroundColor: 'lightblue',
},
translateMatrix2D: {
transform: [{matrix: [1, 0, 0, 0, 1, 0, 0, 0, 1]}],
width: 50,
height: 50,
backgroundColor: 'red',
},
translateMatrix3D: {
transform: [{matrix: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]}],
height: 50,
width: 50,
backgroundColor: 'green',
},
});

exports.title = 'Transforms';
Expand Down Expand Up @@ -414,4 +433,19 @@ exports.examples = [
return <TranslatePercentage />;
},
},
{
title: 'Transform Matrix 2D',
description: "transform: 'matrix(1, 0, 0, 0, 1, 0, 0, 0, 1)'",
render(): React.Node {
return <TranslateMatrix2D />;
},
},
{
title: 'Transform Matrix 3D',
description:
"transform: 'matrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)'",
render(): React.Node {
return <TranslateMatrix3D />;
},
},
] as Array<RNTesterModuleExample>;
Loading