Skip to content

Commit d8e6d9a

Browse files
fix: Correct native matrix translation indices (#529)
parseTransform expanded the CSS 2D matrix(a, b, c, d, tx, ty) into a 4x4 matrix with tx and ty at indices 8 and 9. React Native reads the 16 values column-major, with translation at indices 12 and 13 (Transform.cpp sets them there for translate), so the translation was dropped. Place tx and ty at 12 and 13 and keep index 10 as 1.
1 parent 1663109 commit d8e6d9a

3 files changed

Lines changed: 23 additions & 4 deletions

File tree

‎packages/react-strict-dom/src/native/css/__tests__/parseTransform-test.js‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,13 @@ describe('parseTransform', () => {
6666

6767
test('matrix', () => {
6868
expect(parseTransform('matrix(1, 2, 3, 4, 5, 6)')).toEqual([
69-
{ matrix: [1, 2, 0, 0, 3, 4, 0, 0, 5, 6, 1, 0, 0, 0, 0, 1] }
69+
{ matrix: [1, 2, 0, 0, 3, 4, 0, 0, 0, 0, 1, 0, 5, 6, 0, 1] }
70+
]);
71+
});
72+
73+
test('matrix translation', () => {
74+
expect(parseTransform('matrix(1, 0, 0, 1, 12, -34)')).toEqual([
75+
{ matrix: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 12, -34, 0, 1] }
7076
]);
7177
});
7278

‎packages/react-strict-dom/src/native/css/parseTransform.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ export function parseTransform(transform: string): CSSTransformValue {
101101
matrix[3],
102102
0,
103103
0,
104-
matrix[4],
105-
matrix[5],
106-
1,
107104
0,
108105
0,
106+
1,
109107
0,
108+
matrix[4],
109+
matrix[5],
110110
0,
111111
1
112112
]

‎packages/react-strict-dom/tests/css/css-create-test.native.js‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,6 +1307,19 @@ describe('css.create()', () => {
13071307
expect(console.warn).toHaveBeenCalledTimes(1);
13081308
});
13091309

1310+
test('matrix translation', () => {
1311+
const styles = css.create({
1312+
root: { transform: 'matrix(1, 0, 0, 1, 12, -34)' }
1313+
});
1314+
let root;
1315+
act(() => {
1316+
root = create(<html.div style={styles.root} />);
1317+
});
1318+
expect(root.toJSON().props.style.transform).toEqual([
1319+
{ matrix: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 12, -34, 0, 1] }
1320+
]);
1321+
});
1322+
13101323
test('transform', () => {
13111324
const styles = css.create({
13121325
none: {

0 commit comments

Comments
 (0)