From 1c5021682d5eae58774bbd8e6983cc04d1e29a7f Mon Sep 17 00:00:00 2001 From: "Nate I." Date: Wed, 28 Oct 2026 09:08:35 +0200 Subject: [PATCH 1/2] fix: consume omitted color-mix weights after native serialization --- src/__tests__/native/color-mix.test.tsx | 21 +++++++++++++++++++++ src/native/styles/functions/color-mix.ts | 5 +++++ 2 files changed, 26 insertions(+) diff --git a/src/__tests__/native/color-mix.test.tsx b/src/__tests__/native/color-mix.test.tsx index c6dcb8a0..0c210a2b 100644 --- a/src/__tests__/native/color-mix.test.tsx +++ b/src/__tests__/native/color-mix.test.tsx @@ -1,6 +1,8 @@ import { render, screen } from "@testing-library/react-native"; +import { compile } from "react-native-css/compiler"; import { View } from "react-native-css/components/View"; import { registerCSS, testID } from "react-native-css/jest"; +import { StyleCollection } from "react-native-css/native"; test("color-mix() - keyword", () => { registerCSS( @@ -115,3 +117,22 @@ test("mixing an already translucent color preserves its alpha and restores chang expect(Number(color.slice(5, -1).split(",")[3])).toBeCloseTo(expected, 6); } }); + +test.each([ + ["50%, transparent", "rgba(255, 255, 255, 0.5)"], + [", transparent 75%", "rgba(255, 255, 255, 0.25)"], + [", transparent", "rgba(255, 255, 255, 0.5)"], +])( + "serialized native injection preserves omitted color weights: %s", + (tail, expected) => { + const compiled = compile( + `:root { --white: #fff; } .test { color: color-mix(in oklab, var(--white) ${tail}); }`, + { inlineVariables: false }, + ).stylesheet(); + // Metro's getNativeInjectionCode serializes the stylesheet as JSON. Omitted + // percentage array slots become null, unlike registerCSS's direct injection. + StyleCollection.inject(JSON.parse(JSON.stringify(compiled))); + render(); + expect(screen.getByTestId(testID).props.style?.color).toBe(expected); + }, +); diff --git a/src/native/styles/functions/color-mix.ts b/src/native/styles/functions/color-mix.ts index c134e497..31621ae0 100644 --- a/src/native/styles/functions/color-mix.ts +++ b/src/native/styles/functions/color-mix.ts @@ -28,6 +28,11 @@ export const colorMix: StyleFunctionResolver = (resolveValue, value) => { const left = parse(leftValue); const percentage = () => { const next = args[0]; + // Metro serializes omitted percentage slots in arrays as null. + if (next === null) { + args.shift(); + return undefined; + } if (typeof next !== "string" || !next.endsWith("%")) return undefined; args.shift(); return Number(next.slice(0, -1)) / 100; From 95ff24b448d31b7b0a063bcb3f1532a646365073 Mon Sep 17 00:00:00 2001 From: "Nate I." Date: Wed, 28 Oct 2026 09:14:47 +0200 Subject: [PATCH 2/2] test: retain serialized stylesheet type in color mix regression --- src/__tests__/native/color-mix.test.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/__tests__/native/color-mix.test.tsx b/src/__tests__/native/color-mix.test.tsx index 0c210a2b..d600e8fe 100644 --- a/src/__tests__/native/color-mix.test.tsx +++ b/src/__tests__/native/color-mix.test.tsx @@ -131,7 +131,9 @@ test.each([ ).stylesheet(); // Metro's getNativeInjectionCode serializes the stylesheet as JSON. Omitted // percentage array slots become null, unlike registerCSS's direct injection. - StyleCollection.inject(JSON.parse(JSON.stringify(compiled))); + StyleCollection.inject( + JSON.parse(JSON.stringify(compiled)) as typeof compiled, + ); render(); expect(screen.getByTestId(testID).props.style?.color).toBe(expected); },