Skip to content
Open
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
17 changes: 17 additions & 0 deletions src/__tests__/native/units.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,23 @@ test("rem - css root font-size override", () => {
});
});

test("rem - via var() inlining picks up css root font-size ", () => {
registerCSS(`
:root { font-size: 16px; --text-base: 1rem; }
.text-base { font-size: var(--text-base); }
`);

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

expect(result.current.type).toBe(VariableContext.Provider);
expect(result.current.props.children.type).toBe(View);
expect(result.current.props.children.props).toStrictEqual({
style: { fontSize: 16 },
});
});

test("rem - css override", () => {
registerCSS(
`
Expand Down
1 change: 1 addition & 0 deletions src/compiler/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export function compile(code: Buffer | string, options: CompilerOptions = {}) {
const css = typeof code === "string" ? code : code.toString();
const match = css.match(/:root\s*\{[^}]*font-size:\s*([\d.]+)px/);
effectiveRem = match?.[1] ? parseFloat(match[1]) : 14;
options.inlineRem = effectiveRem;
}
Comment thread
maxencehenneron marked this conversation as resolved.

const firstPassVisitor: Visitor<CustomAtRules> = {};
Expand Down
10 changes: 5 additions & 5 deletions src/metro/metro-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ const worker =
require(unstable_transformerPath) as typeof import("metro-transform-worker");

export async function transform(
config: JsTransformerConfig,
config: JsTransformerConfig & {
reactNativeCSS?: CompilerOptions | undefined;
},
projectRoot: string,
filePath: string,
data: Buffer,
options: JsTransformOptions & {
reactNativeCSS?: CompilerOptions | undefined;
},
options: JsTransformOptions,
): Promise<TransformResponse> {
const isCss = options.type !== "asset" && /\.(s?css|sass)$/.test(filePath);

Expand All @@ -37,7 +37,7 @@ export async function transform(
const css = cssFile.output[0].data.css.code.toString();

const productionJS = compile(css, {
...options.reactNativeCSS,
...config.reactNativeCSS,
filename: filePath,
projectRoot: projectRoot,
}).stylesheet();
Expand Down