Skip to content

fix(compiler): compile padding-block/-inline to paddingVertical/Horizontal - #580

Merged
danstepanov merged 1 commit into
nativewind:mainfrom
sammoore:fix/logical-padding-compile
Nov 20, 2026
Merged

danstepanov merged 1 commit into
nativewind:mainfrom
sammoore:fix/logical-padding-compile

Conversation

@sammoore

Copy link
Copy Markdown
Contributor

Supersedes #400. Thanks to @kdwkr for the diagnosis and the device measurements.

Problem

This is a regression relative to Nativewind v4 / Tailwind v3: they rendered py-2 as paddingTop/paddingBottom and px-4 as paddingLeft/paddingRight, which TextInput honours. Tailwind v4 does not, as follows.

Tailwind v4 compiles py-* / px-* to padding-block / padding-inline, and we passed those through as paddingBlock / paddingInline. On Android, Fabric's TextInput applies its EditText theme padding (about 21dp) to every edge it finds no padding for, and that check (AndroidTextInputComponentDescriptor::adopt) only reads padding, paddingVertical/paddingHorizontal and the single sides. It doesn't see paddingBlock / paddingInline, so the theme padding wins. #400 measured a py-2 input at 42.67dp on a real device, where it should be 35.81dp.

Solution

React Native maps paddingBlock to Yoga's Vertical edge and paddingInline to its Horizontal edge, the same edges as paddingVertical and paddingHorizontal. So the compiler now emits those keys for a one-value padding-block / padding-inline:

  • two entries in propertyRename, which covers values with var() (Tailwind's calc(var(--spacing) * 2) when the theme is kept at runtime)
  • the shorthand name in parsePaddingBlock / parsePaddingInline, for literal values

Two-value forms still emit paddingBlockStart/End and paddingInlineStart/End.

Why at compile time

#400 expanded the keys in getStyledProps on every render. Doing it in the compiler instead:

  • adds no runtime code (the diff is 7 lines in declarations.ts)
  • keeps React Native's own precedence (a side beats an axis), so every other component renders exactly as before
  • covers every style target, not only style

An inline style={{ paddingBlock }} that the app passes itself still reaches TextInput unchanged. Plain React Native behaves the same, so that's left to React Native.

Impact

  • Every Tailwind class containing py-*/px-* gets the new key names. On a View, every class paints the same edges as before, and nothing fails React Native's validators.
  • Tests: the new native/logical-padding.test.tsx covers literal, var() and calc(var()) values, with variables both inlined and kept at runtime. 8 of its 10 cases fail on main. spacing and @apply were updated for the new keys.
  • Performance: no runtime code changes.

Possible follow-up, not in this PR: ps-*/pe-* emit paddingInlineStart/End, which the same TextInput check doesn't read either. v4 emitted paddingStart/paddingEnd. Not verified on a device.

…ical/paddingHorizontal

Android's Fabric TextInput applies its EditText theme padding (about 21dp)
to every edge it finds no padding for, and it only checks padding,
paddingVertical/paddingHorizontal and the single sides. React Native maps
paddingBlock and paddingInline to the same Yoga edges as paddingVertical and
paddingHorizontal, but that check doesn't see them. So a Tailwind py-*/px-*
TextInput kept the theme padding.

Renaming the keys at compile time fixes literal and var() values alike
(propertyRename covers the unparsed path), costs nothing at runtime, and
renders the same as before on every other component. Nativewind v4 rendered
physical keys for py-*/px-*, so this fixes a v4 regression.

Diagnosed in nativewind#400, which expanded the keys at runtime instead.

Co-authored-by: Daewoon Kim <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sammoore
sammoore force-pushed the fix/logical-padding-compile branch from 39e9501 to 58232af Compare November 20, 2026 22:53
@danstepanov
danstepanov merged commit 90fdbb5 into nativewind:main Nov 20, 2026
6 checks passed
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.

2 participants