Skip to content

Commit 2e4c95f

Browse files
authored
fix: more fixes for unparsed transform values (#99)
1 parent 244a14b commit 2e4c95f

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

src/runtime/native/__tests__/transform.test.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,23 @@ describe("scale", () => {
4444
});
4545

4646
test("unparsed", () => {
47+
registerCSS(`
48+
.my-class {
49+
--scale-x: 2%;
50+
--scale-y: 2%;
51+
scale: var(--scale-x) var(--scale-y);
52+
}
53+
`);
54+
const component = render(
55+
<View testID={testID} className="my-class" />,
56+
).getByTestId(testID);
57+
58+
expect(component.props.style).toStrictEqual({
59+
transform: [{ scale: "2%" }],
60+
});
61+
});
62+
63+
test("unparsed - different values", () => {
4764
registerCSS(`
4865
:root {
4966
--scale-x: 2;

src/runtime/utils/objects.ts

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,25 +66,14 @@ export function applyValue(
6666
}
6767

6868
const transformArray: Record<string, unknown>[] = target.transform;
69-
const transform = transformArray.find((t: any) => t[prop] !== undefined);
70-
71-
/**
72-
* If our value is an array, this means a shorthand was split into multiple values
73-
* e.g scale -> scaleX, scaleY
74-
*/
75-
if (transform) {
76-
if (Array.isArray(value)) {
77-
target.transform = transformArray.filter((t) => !(prop in t));
78-
target.transform.push(...value);
79-
} else {
80-
transform[prop] = value;
81-
}
69+
70+
// Remove any existing values
71+
target.transform = transformArray.filter((t) => !(prop in t));
72+
73+
if (Array.isArray(value)) {
74+
target.transform.push(...value);
8275
} else {
83-
if (Array.isArray(value)) {
84-
transformArray.push(...value);
85-
} else {
86-
transformArray.push(value);
87-
}
76+
target.transform.push(value);
8877
}
8978
return;
9079
} else if (typeof value === "object" && value && ShortHandSymbol in value) {

0 commit comments

Comments
 (0)