Skip to content
Merged
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
4 changes: 4 additions & 0 deletions src/compiler/stylesheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const staticDeclarations = new WeakMap<

const extraRules = new WeakMap<StyleRule, Partial<StyleRule>[]>();

const keywords = new Set(["unset"]);

export class StylesheetBuilder {
animationFrames?: AnimationKeyframes_V2[];
animationDeclarations: StyleDeclaration[] = [];
Expand Down Expand Up @@ -418,6 +420,8 @@ export class StylesheetBuilder {
]);
} else if (Array.isArray(value) && value.some(isStyleFunction)) {
declarations.push([value, propPath]);
} else if (typeof value === "string" && keywords.has(value)) {
declarations.push([value, propPath]);
} else {
let staticDeclarationRecord = staticDeclarations.get(declarations);
if (!staticDeclarationRecord) {
Expand Down
18 changes: 18 additions & 0 deletions src/runtime/native/__tests__/keywords.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { View } from "react-native";

import { renderHook } from "@testing-library/react-native";
import { registerCSS } from "react-native-css/jest";

import { useNativeCss } from "../react/useNativeCss";

test("unset", () => {
registerCSS(`.my-class { background-color: unset; }`);

const { result } = renderHook(() => {
return useNativeCss(View, { className: "my-class" });
});

expect(result.current.props).toStrictEqual({
style: { backgroundColor: undefined },
});
});
14 changes: 10 additions & 4 deletions src/runtime/native/styles/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,16 @@ export function resolveValue(
case "number":
case "boolean":
return value;
case "string":
return value.endsWith("px") // Inline vars() might set a value with a px suffix
? parseInt(value.slice(0, -2), 10)
: value;
case "string": {
if (value === "unset") {
return null;
} else if (value.endsWith("px")) {
// Inline vars() might set a value with a px suffix
return parseInt(value.slice(0, -2), 10);
} else {
return value;
}
}
case "object": {
if (!Array.isArray(value)) {
return value;
Expand Down
5 changes: 5 additions & 0 deletions src/runtime/utils/objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,13 @@ export function applyValue(
prop: string,
value: any,
) {
// This is confusing.
// An undefined value means "don't set anything" (something failed while parsing)
// While a null value means "remove this value", which in React Native means "set to undefined"
if (value === undefined) {
return;
} else if (value === null) {
value = undefined;
}

if (transformKeys.has(prop)) {
Expand Down
Loading