Skip to content

fix: expand logical padding to physical properties on native - #400

Closed
kdwkr wants to merge 1 commit into
nativewind:mainfrom
scatterlab:zeta-logical-padding
Closed

kdwkr wants to merge 1 commit into
nativewind:mainfrom
scatterlab:zeta-logical-padding

Conversation

@kdwkr

@kdwkr kdwkr commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Android's Fabric TextInput ignores logical padding (paddingBlock / paddingInline). The value is dropped and the EditText theme default (~21dp) stays, so a py-2 input measures 42.67dp on a real device instead of 35.81dp. Measured on a Samsung SM-M236L, density 2.625, RN 0.86.2 new architecture.

Tailwind compiles py-* / px-* to exactly those logical properties, so in practice nearly every text input is affected.

Rewriting call sites to pt-* / pb-* is not a workaround — a Tailwind class sorter (prettier-plugin-tailwindcss, oxfmt) collapses them straight back to py-*.

This expands logical padding to physical properties in getStyledProps, after className resolution, so it covers every path that produces a style. Existing physical values win, so an explicit paddingTop is never overwritten. Arrays are handled and the input object is returned unchanged when there is nothing to expand.

Android's Fabric TextInput ignores `paddingBlock` / `paddingInline` — the value is dropped and
the EditText theme default (~21dp) remains, so `py-2` measures 42.67dp on a real device instead
of 35.81dp. Tailwind compiles `py-*` / `px-*` to exactly those logical properties, so nearly
every text input is affected.

Convert to physical properties after className resolution. Existing physical values win.
Copilot AI review requested due to automatic review settings August 1, 2026 09:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to work around an Android Fabric TextInput issue where logical padding shorthands (paddingBlock / paddingInline, commonly produced by Tailwind py-* / px-*) are ignored, by expanding them into non-logical padding properties during getStyledProps processing.

Changes:

  • Adds a post-merge transformation step in getStyledProps to expand logical padding properties on the resolved style.
  • Introduces expandLogicalPadding() to recursively handle style objects and arrays, preserving existing physical values.
Suppressed comments (2)

src/native/styles/index.ts:357

  • paddingInline is a logical (start/end) shorthand. Expanding it to paddingLeft/paddingRight changes behavior in RTL layouts. To preserve inline semantics while still avoiding paddingInline, prefer paddingStart/paddingEnd (and keep the same “existing values win” behavior).
  if (paddingInline !== undefined) {
    next.paddingLeft ??= paddingInline;
    next.paddingRight ??= paddingInline;
  }

src/native/styles/index.ts:308

  • This change alters the runtime style output (e.g. px-*/py-* will no longer surface as paddingInline/paddingBlock). Existing Tailwind vendor tests assert the old shape (e.g. src/__tests__/vendor/tailwind/spacing.test.tsx, src/__tests__/vendor/tailwind/@apply.test.tsx) and should be updated or supplemented to cover the new expansion behavior.
    if (result.style !== undefined) {
      result.style = expandLogicalPadding(result.style);
    }

Comment on lines +306 to +308
if (result.style !== undefined) {
result.style = expandLogicalPadding(result.style);
}
Comment on lines +329 to +339
if (Array.isArray(style)) {
let changed = false;
const next = style.map((entry) => {
const expanded = expandLogicalPadding(entry);
if (expanded !== entry) {
changed = true;
}
return expanded;
});
return changed ? next : style;
}

@sammoore sammoore left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@kdwkr Made a compile-time only version in the form of #580 -- simply mapping over to paddingVertical/paddingHorizontal. As far as I can tell, there's nothing wrong with that, and we avoid any potential runtime performance hits from allocations on the hot path (which we are also trying to optimize on an ongoing basis).

Let me know if you have any concerns that it won't solve the underlying issue or tangential ones, and we can revisit!

sammoore added a commit to sammoore/react-native-css that referenced this pull request Nov 20, 2026
…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]>
danstepanov pushed a commit that referenced this pull request Nov 20, 2026
@danstepanov

Copy link
Copy Markdown
Member

Closing this in favor of #580, which carries your commit with some changes from Sam and just landed in 90fdbb5. Thanks for the diagnosis and the device measurements!

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.

4 participants