Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/__tests__/native/transform.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ describe("scale", () => {

test("unparsed", () => {
registerCSS(`
.my-class {
.my-class {
--scale-x: 2%;
--scale-y: 2%;
scale: var(--scale-x) var(--scale-y);
scale: var(--scale-x) var(--scale-y);
}
`);
const component = render(
Expand Down Expand Up @@ -153,4 +153,24 @@ describe("transform", () => {
transform: [{ translateX: "10%" }, { scaleX: 2 }],
});
});

test.only("no duplicated translate objects", () => {
registerCSS(`
.translate-x-1 {
--tw-translate-x: 4px;
transform: translate(var(--tw-translate-x), var(--tw-translate-y));
}
.translate-y-1 {
--tw-translate-y: 4px;
transform: translate(var(--tw-translate-x), var(--tw-translate-y));
}`);

const component = render(
<View testID={testID} className="translate-x-1 translate-y-1" />,
).getByTestId(testID);

expect(component.props.style).toStrictEqual({
transform: [{ translateX: 4 }, { translateY: 4 }],
});
});
});
13 changes: 11 additions & 2 deletions src/native/objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,17 @@ export function applyValue(

const transformArray: Record<string, unknown>[] = target.transform;

// Remove any existing values
target.transform = transformArray.filter((t) => !(prop in t));
// Remove any existing values and any keys that are to be appended next
const keysToRemove = Array.isArray(value)
? new Set(
value.flatMap((v) =>
v && typeof v === "object" ? Object.keys(v) : [],
),
)
: new Set([prop]);
target.transform = transformArray.filter(
(t) => !(prop in t) && !Object.keys(t).some((k) => keysToRemove.has(k)),
);
Comment on lines +73 to +82

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added the test, but I realised that it would be passed even without my change - it wasn't enough to capture the regression, but I couldn't find why


if (Array.isArray(value)) {
target.transform.push(...value);
Expand Down