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
6 changes: 6 additions & 0 deletions src/compiler/__tests__/@prop.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ test("@prop single", () => {
myBackgroundColor: "#00f",
},
],
v: [["__rn-css-color", "#f00"]],
s: [1, 1],
},
],
Expand Down Expand Up @@ -51,6 +52,7 @@ test("@prop single, nested value", () => {
["#00f", ["myBackgroundColor", "nested"]],
],
s: [1, 1],
v: [["__rn-css-color", "#f00"]],
},
],
],
Expand Down Expand Up @@ -79,6 +81,7 @@ test("@prop single, top level", () => {
},
["#00f", ["^", "myBackgroundColor"]],
],
v: [["__rn-css-color", "#f00"]],
s: [1, 1],
},
],
Expand Down Expand Up @@ -108,6 +111,7 @@ test("@prop single, top level, nested", () => {
},
["#00f", ["^", "myBackgroundColor", "test"]],
],
v: [["__rn-css-color", "#f00"]],
s: [1, 1],
},
],
Expand Down Expand Up @@ -138,6 +142,7 @@ test("@prop single, top level, nested", () => {
["#00f", ["^", "myBackgroundColor", "test"]],
],
s: [1, 1],
v: [["__rn-css-color", "#f00"]],
},
],
],
Expand Down Expand Up @@ -169,6 +174,7 @@ test("@prop multiple", () => {
myColor: "#f00",
},
],
v: [["__rn-css-color", "#f00"]],
s: [1, 1],
},
],
Expand Down
3 changes: 3 additions & 0 deletions src/compiler/__tests__/compiler.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ test("hello world", () => {
},
],
s: [1, 1],
v: [["__rn-css-color", "#f00"]],
},
],
],
Expand Down Expand Up @@ -128,6 +129,7 @@ test("multiple rules with same selector", () => {
},
],
s: [2, 1],
v: [["__rn-css-color", "#f00"]],
},
{
d: [
Expand All @@ -139,6 +141,7 @@ test("multiple rules with same selector", () => {
h: 1,
},
s: [1, 2],
v: [["__rn-css-color", "#008000"]],
},
],
],
Expand Down
1 change: 1 addition & 0 deletions src/compiler/attributes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ test("multiple classes", () => {
},
],
s: [1, 2],
v: [["__rn-css-color", "#f00"]],
},
],
],
Expand Down
15 changes: 15 additions & 0 deletions src/compiler/compiler.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,31 @@ export type StyleFunction =
Record<never, never>,
string, // string
]
| readonly [
Record<never, never>,
string, // string
]
| [
Record<never, never>,
string, // string
StyleDescriptor, // arguments
]
| readonly [
Record<never, never>,
string, // string
StyleDescriptor, // arguments
]
| [
Record<never, never>,
string, // string
StyleDescriptor, // arguments
1, // Should process after styles have been calculated
]
| readonly [
Record<never, never>,
string, // string
StyleDescriptor, // arguments
1, // Should process after styles have been calculated
];

/****************************** Variables *******************************/
Expand Down
32 changes: 27 additions & 5 deletions src/compiler/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ const parsers: {
"bottom": parseSizeDeclaration,
"box-shadow": parseBoxShadow,
"caret-color": parseColorOrAuto,
"color": parseColorDeclaration,
"color": parseFontColorDeclaration,
"column-gap": parseGap,
"container": parseContainer,
"container-name": parseContainerName,
Expand Down Expand Up @@ -836,6 +836,10 @@ export function parseDeclarationUnparsed(
if (property === "font-size") {
builder.addDescriptor("--__rn-css-em", value);
}

if (property === "color") {
builder.addDescriptor("--__rn-css-current-color", value);
}
}
}

Expand Down Expand Up @@ -940,6 +944,8 @@ export function parseUnparsed(
return true;
} else if (tokenOrValue === "false") {
return false;
} else if (tokenOrValue === "currentcolor") {
return [{}, "var", "__rn-css-current-color"] as const;
} else {
return tokenOrValue;
}
Expand Down Expand Up @@ -1033,6 +1039,8 @@ export function parseUnparsed(
if (value === "inherit") {
builder.addWarning("value", value);
return;
} else if (value === "currentcolor") {
return [{}, "var", "__rn-css-current-color"] as const;
}

if (value === "true") {
Expand Down Expand Up @@ -1324,11 +1332,26 @@ export function parseColorOrAuto(
}
}

export function parseFontColorDeclaration(
declaration: Extract<Declaration, { value: CssColor }>,
builder: StylesheetBuilder,
) {
parseColorDeclaration(declaration, builder);

builder.addDescriptor(
"--__rn-css-color",
parseColor(declaration.value, builder),
);
}

export function parseColorDeclaration(
declaration: { value: CssColor },
declaration: Extract<Declaration, { value: CssColor }>,
builder: StylesheetBuilder,
) {
return parseColor(declaration.value, builder);
builder.addDescriptor(
declaration.property,
parseColor(declaration.value, builder),
);
}

export function parseColor(cssColor: CssColor, builder: StylesheetBuilder) {
Expand All @@ -1345,8 +1368,7 @@ export function parseColor(cssColor: CssColor, builder: StylesheetBuilder) {

switch (cssColor.type) {
case "currentcolor":
builder.addWarning("value", cssColor.type);
return;
return [{}, "var", "__rn-css-current-color"] as const;
case "light-dark":
// TODO: Handle light-dark colors
return;
Expand Down
3 changes: 3 additions & 0 deletions src/compiler/inheritance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ test("nested classes", () => {
{
cq: [{ n: "my-class" }],
d: [{ color: "#f00" }],
v: [["__rn-css-color", "#f00"]],
s: [1, 2],
},
],
Expand Down Expand Up @@ -63,6 +64,7 @@ test("multiple tiers classes", () => {
{
cq: [{ n: "one" }, { n: "two" }],
d: [{ color: "#f00" }],
v: [["__rn-css-color", "#f00"]],
s: [1, 3],
},
],
Expand Down Expand Up @@ -109,6 +111,7 @@ test("tiers with multiple classes", () => {
},
],
d: [{ color: "#f00" }],
v: [["__rn-css-color", "#f00"]],
s: [1, 4],
},
],
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/native/__tests__/grouping.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ test("groups", () => {
test("group - active", () => {
registerCSS(
`.group\\/item:active .my-class {
color: red;
background-color: red;
}`,
);

Expand All @@ -54,7 +54,7 @@ test("group - active", () => {

fireEvent(parent, "pressIn");

expect(child.props.style).toStrictEqual({ color: "#f00" });
expect(child.props.style).toStrictEqual({ backgroundColor: "#f00" });
});

test.skip("group - active (animated)", () => {
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/native/__tests__/media-query.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ test("not all", () => {
// It is the same as max-width: 639px
registerCSS(`
@media not all and (min-width: 640px) {
.my-class { color: red; }
.my-class { background-color: red; }
}`);
// Make larger than 640
act(() => {
Expand All @@ -173,7 +173,7 @@ test("not all", () => {
});

expect(component.props.style).toStrictEqual({
color: "#f00",
backgroundColor: "#f00",
});
});

Expand Down
Loading