Skip to content

fix: Correct native matrix translation indices - #529

Open
ZainnQureshii wants to merge 1 commit into
react:mainfrom
ZainnQureshii:fix/native-matrix-translation
Open

ZainnQureshii wants to merge 1 commit into
react:mainfrom
ZainnQureshii:fix/native-matrix-translation

Conversation

@ZainnQureshii

Copy link
Copy Markdown

Summary

parseTransform expands CSS matrix(a, b, c, d, tx, ty) into the 16-value native matrix, but it put tx and ty at indices 8 and 9 (packages/react-strict-dom/src/native/css/parseTransform.js). React Native reads that array column-major with translation at indices 12 and 13 (the translate case in ReactCommon/react/renderer/graphics/Transform.cpp sets matrix[12] and matrix[13]), and the CSS Transforms spec maps matrix(a, b, c, d, e, f) to matrix3d(a, b, 0, 0, c, d, 0, 0, 0, 0, 1, 0, e, f, 0, 1). So on native any translation inside a 2D matrix() was dropped.

For matrix(1, 0, 0, 1, 12, -34) the output goes from [1, 0, 0, 0, 0, 1, 0, 0, 12, -34, 1, 0, 0, 0, 0, 1] to [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 12, -34, 0, 1].

The existing matrix parser expectation is updated, and there are two new regression tests: one on the parser and one through css.create() on an html.div.

Test plan

npm run jest -w react-strict-dom -- --runInBand --runTestsByPath src/native/css/__tests__/parseTransform-test.js tests/css/css-create-test.native.js

With the fix reverted and the tests kept: 3 failed, 108 passed. With the fix: 111 passed.

npm run jest -w react-strict-dom

19 suites, 899 tests passed. Prettier and ESLint are clean on the changed files. Not run: device rendering and Flow.

Prepared with AI assistance (Claude Code) and reviewed with GitHub Copilot.

🤖 Generated with Claude Code

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.
@meta-cla meta-cla Bot added the cla signed label Nov 10, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant