diff --git a/src/__tests__/native/logical-padding.test.tsx b/src/__tests__/native/logical-padding.test.tsx new file mode 100644 index 00000000..52e37837 --- /dev/null +++ b/src/__tests__/native/logical-padding.test.tsx @@ -0,0 +1,23 @@ +import { render, screen } from "@testing-library/react-native"; +import { TextInput } from "react-native-css/components/TextInput"; +import { registerCSS, testID } from "react-native-css/jest"; + +// Android's TextInput keeps its theme padding unless it sees padding, +// paddingVertical/paddingHorizontal or a physical side, so a one-value +// padding-block/padding-inline must not reach it as paddingBlock/paddingInline. +describe.each([ + ["folded", {}], + ["kept", { inlineVariables: false }], +] as const)("variables %s", (_, options) => { + test.each([ + ["padding-block: 8px", { paddingVertical: 8 }], + ["padding-inline: 16px", { paddingHorizontal: 16 }], + ["--s: 6px; padding-block: var(--s)", { paddingVertical: 6 }], + ["--s: 6px; padding-inline: calc(var(--s) * 2)", { paddingHorizontal: 12 }], + ["padding-block: 1px 2px", { paddingBlockStart: 1, paddingBlockEnd: 2 }], + ])("%s", (body, expected) => { + registerCSS(`.a { ${body} }`, options); + render(); + expect(screen.getByTestId(testID).props.style).toStrictEqual(expected); + }); +}); diff --git a/src/__tests__/vendor/tailwind/@apply.test.tsx b/src/__tests__/vendor/tailwind/@apply.test.tsx index 41b01f50..2a88f6d7 100644 --- a/src/__tests__/vendor/tailwind/@apply.test.tsx +++ b/src/__tests__/vendor/tailwind/@apply.test.tsx @@ -20,8 +20,8 @@ test("@apply", async () => { borderRadius: 7, color: "#fff", fontWeight: 600, - paddingBlock: 7, - paddingInline: 14, + paddingVertical: 7, + paddingHorizontal: 14, boxShadow: [ { offsetX: 0, diff --git a/src/__tests__/vendor/tailwind/spacing.test.tsx b/src/__tests__/vendor/tailwind/spacing.test.tsx index 520fcbc7..79b4fe80 100644 --- a/src/__tests__/vendor/tailwind/spacing.test.tsx +++ b/src/__tests__/vendor/tailwind/spacing.test.tsx @@ -8,12 +8,12 @@ describe("Spacing - Padding", () => { }); test("px-0", async () => { expect(await renderCurrentTest()).toStrictEqual({ - props: { style: { paddingInline: 0 } }, + props: { style: { paddingHorizontal: 0 } }, }); }); test("py-0", async () => { expect(await renderCurrentTest()).toStrictEqual({ - props: { style: { paddingBlock: 0 } }, + props: { style: { paddingVertical: 0 } }, }); }); test("pt-0", async () => { diff --git a/src/compiler/declarations.ts b/src/compiler/declarations.ts index 197a9c69..e5e5a8b9 100644 --- a/src/compiler/declarations.ts +++ b/src/compiler/declarations.ts @@ -72,6 +72,11 @@ const propertyRename: Record = { "border-block-start-width": "border-top-width", "border-block-end-width": "border-bottom-width", "font-variant-caps": "font-variant", + // React Native maps paddingBlock/paddingInline to the same Yoga edges as + // paddingVertical/paddingHorizontal, but Android's TextInput only sees the + // latter and otherwise keeps its theme padding + "padding-block": "padding-vertical", + "padding-inline": "padding-horizontal", }; // React Native only supports a uniform borderStyle, so per-side border @@ -702,7 +707,7 @@ function parsePaddingBlock( { value }: DeclarationType<"padding-block">, builder: StylesheetBuilder, ) { - builder.addShorthand("padding-block", { + builder.addShorthand("padding-vertical", { "padding-block-start": parseLengthPercentageOrAuto( value.blockStart, builder, @@ -715,7 +720,7 @@ function parsePaddingInline( { value }: DeclarationType<"padding-inline">, builder: StylesheetBuilder, ) { - builder.addShorthand("padding-inline", { + builder.addShorthand("padding-horizontal", { "padding-inline-start": parseLengthPercentageOrAuto( value.inlineStart, builder,