Skip to content

Commit d6ddfc4

Browse files
committed
Fix failing test
1 parent 3dfa787 commit d6ddfc4

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

packages/react-native-reanimated/__tests__/normalizeColor.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ describe('Test `normalizeColor` function', () => {
304304
describe('Test colors a colorName string', () => {
305305
test.each([
306306
['red', 0xff0000ff],
307-
['transparent', 0x00000000],
307+
['transparent', undefined], // Transparent cannot be represented as a number
308308
['peachpuff', 0xffdab9ff],
309309
['peachPuff', null],
310310
['PeachPuff', null],

packages/react-native-reanimated/src/Colors.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,9 @@ export function clampRGBA(RGBA: ParsedColorArray): void {
168168
}
169169
}
170170

171-
const names: Record<string, number> = {
171+
const names: Record<string, number | undefined> = {
172+
transparent: undefined,
173+
172174
/* spell-checker: disable */
173175
// http://www.w3.org/TR/css3-color/#svg-color
174176
aliceblue: 0xf0f8ffff,
@@ -362,7 +364,7 @@ export const DynamicColorIOSProperties = [
362364
'highContrastDark',
363365
] as const;
364366

365-
export function normalizeColor(color: unknown): number | null {
367+
export function normalizeColor(color: unknown): number | null | undefined {
366368
'worklet';
367369

368370
if (typeof color === 'number') {
@@ -383,7 +385,7 @@ export function normalizeColor(color: unknown): number | null {
383385
return Number.parseInt(match[1] + 'ff', 16) >>> 0;
384386
}
385387

386-
if (names[color] !== undefined) {
388+
if (color in names) {
387389
return names[color];
388390
}
389391

@@ -644,12 +646,9 @@ export function processColorInitially(
644646
colorNumber = color;
645647
} else {
646648
const normalizedColor = normalizeColor(color);
647-
if (normalizedColor === null || normalizedColor === undefined) {
648-
return undefined;
649-
}
650649

651650
if (typeof normalizedColor !== 'number') {
652-
return null;
651+
return normalizedColor;
653652
}
654653

655654
colorNumber = normalizedColor;

packages/react-native-reanimated/src/common/processors/colors.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,9 @@ function isDynamicColorObject(value: any): boolean {
6262

6363
export function processColor(color: unknown): number | null | undefined {
6464
let normalizedColor = processColorInitially(color);
65-
if (normalizedColor === null || normalizedColor === undefined) {
66-
return undefined;
67-
}
6865

6966
if (typeof normalizedColor !== 'number') {
70-
return null;
67+
return normalizedColor;
7168
}
7269

7370
if (IS_ANDROID) {

0 commit comments

Comments
 (0)