Skip to content

feat(transforms): read rotate by its own grammar, and none from a var() - #600

Open
YevheniiKotyrlo wants to merge 1 commit into
nativewind:mainfrom
YevheniiKotyrlo:feat/rotate-longhand-grammar
Open

YevheniiKotyrlo wants to merge 1 commit into
nativewind:mainfrom
YevheniiKotyrlo:feat/rotate-longhand-grammar

Conversation

@YevheniiKotyrlo

@YevheniiKotyrlo YevheniiKotyrlo commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

For review after Nativewind v5 stable. Tailwind writes none of these declarations.

Problem

translate, rotate and scale each have a grammar of their own (css-transforms-2, individual transforms), which the transform function of the same name doesn't share. #576 keeps the part Tailwind reaches, an optional z on translate and scale. The rest only comes up in CSS written by hand:

Declaration main This PR
rotate: 0 0 -1 45deg (negative axis) rotateZ: "45deg", the wrong way rotateZ: "-45deg"
rotate: -1 0 0 45deg rotateX: "45deg", the wrong way rotateX: "-45deg"
rotate: 0 0 0 45deg (zero vector) dropped, leaving an earlier rule's rotation and an empty rotate key rotateZ: "0deg"
rotate: 1 1 0 45deg (oblique) rotateX and rotateY, two rotations ignored with a warning
--r: x 45deg; rotate: var(--r) no transform rotateX: "45deg"
--r: 45deg y; rotate: var(--r) no transform rotateY: "45deg"
--r: x; rotate: var(--r) 45deg no transform rotateX: "45deg"
scale: 2 3 400% (z ≠ 1) x and y x and y, and a warning that z is ignored

These render the same either way, in a different shape:

Declaration main This PR
--r: 20deg; rotate: var(--r) rotate: "20deg" rotateZ: "20deg", as a written rotate:
--t: none; translate: var(--t) no transform translateX: 0, translateY: 0
--s: none; scale: var(--s) no transform scaleX: 1, scaleY: 1
--r: none; rotate: var(--r) no transform rotateZ: "0deg"

Browsers draw an oblique rotate as one rotation about that vector and apply a scale along z. React Native's rotate keys turn only about an axis and it has no z to scale along, so this PR warns for both rather than render something else.

Solution

  • individualRotate reads an angle, with an axis keyword or three numbers beside it, in either order.
  • rotationAxis() in react-native-css/utilities decides the axis and negateAngle() flips the angle for a negative one, so the compiler's parseRotate and the runtime agree. An oblique vector warns when written and is none when substituted.
  • individualTranslate, individualScale and individualRotate read a none substituted from a var() as the identity.
  • parseScale warns for a z other than 1.

Split out of #389, whose transform-properties fix landed in #576.

Tests

  • src/__tests__/native/transform.test.tsx: the rotate and none rows above, written and through a var(), and transform: var(--missing) replacing an earlier rule's transform.
  • src/__tests__/compiler/compiler.test.tsx: "a scale along z or a rotate about an oblique axis warns".
  • src/__tests__/native/variable-fold-parity.test.tsx: rotate read through a var() now matches the compiler's rotateZ, so its known-divergence entry goes.

Verification

A local replica of CI passes every job on Node 26.12.1, where .nvmrc pins 24.22.3: lint and typecheck, yarn test --maxWorkers=2 --coverage (2254 passed), the library build with node --test, the web export and commitlint in Ubuntu, and the iOS dev build on macOS with Xcode 27.2, where ci.yml pins 26.6.

The runtime cost is not measured on Hermes. Every runtime translate and scale now checks for none, one comparison each; the axis parsing runs only for a rotate read through a var().

The individual transform properties each have a grammar of their own
(css-transforms-2 §3), which the transform function of the same name
doesn't share. The transform-properties fix keeps the part Tailwind
reaches, an optional z on translate and scale. This adds the rest:

- rotate takes an axis keyword or a vector beside its angle, in either
  order, written or substituted from a var(). A rotation turns about the
  axis its vector names, reversed about a negative axis, and the zero
  vector rotates by none:
    rotate: 0 0 -1 45deg            ->  [{ rotateZ: "-45deg" }]
    --r: x 45deg; rotate: var(--r)  ->  [{ rotateX: "45deg" }]
    rotate: 0 0 0 45deg             ->  [{ rotateZ: "0deg" }]
  The compiler and the runtime share that decision through rotationAxis()
  in react-native-css/utilities. React Native's rotate keys turn only
  about an axis, so a vector off every axis warns and is ignored when
  written, and is none when substituted.
- A rotate from a var() renders as rotateZ, as a written one does.
- translate, rotate and scale read none substituted from a var() as the
  identity.
- A written scale along z warns, as React Native has no z axis to scale
  along.

This was split out of nativewind#389 because Tailwind never reaches it: its
utilities write rotate: <angle> and none literally.
@YevheniiKotyrlo
YevheniiKotyrlo force-pushed the feat/rotate-longhand-grammar branch from df5b62a to 2cd2546 Compare December 2, 2026 16:53
@YevheniiKotyrlo
YevheniiKotyrlo marked this pull request as ready for review December 2, 2026 16:54

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant