From cbbba7b9a5cf81d5454f13dbf399a4c35d7d6667 Mon Sep 17 00:00:00 2001 From: Zeya Peng Date: Mon, 17 Nov 2025 08:24:39 -0800 Subject: [PATCH] jest tests for PlatformColor support (#54458) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/54458 ## Changelog: [General] [Added] jest tests for PlatformColor support Reviewed By: yungsters Differential Revision: D86547464 fbshipit-source-id: b89e8d30c20dd0a507b312cf1d813891e6ccb077 --- .../Animated/__tests__/Interpolation-test.js | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/packages/react-native/Libraries/Animated/__tests__/Interpolation-test.js b/packages/react-native/Libraries/Animated/__tests__/Interpolation-test.js index a1000ac6066..ee7827538e9 100644 --- a/packages/react-native/Libraries/Animated/__tests__/Interpolation-test.js +++ b/packages/react-native/Libraries/Animated/__tests__/Interpolation-test.js @@ -8,12 +8,16 @@ * @format */ -import type {InterpolationConfigType} from '../nodes/AnimatedInterpolation'; +import type { + InterpolationConfigSupportedOutputType, + InterpolationConfigType, +} from '../nodes/AnimatedInterpolation'; +import {PlatformColor} from '../../../Libraries/StyleSheet/PlatformColorValueTypes'; import Easing from '../Easing'; import AnimatedInterpolation from '../nodes/AnimatedInterpolation'; -function createInterpolation( +function createInterpolation( config: InterpolationConfigType, ): number => T { let parentValue = null; @@ -360,6 +364,31 @@ describe('Interpolation', () => { expect(interpolation(2 / 3)).toBe('rgba(0, 0, 0, 0.667)'); }); + it('should work with PlatformColor', () => { + jest.spyOn(console, 'warn').mockImplementationOnce(() => {}); + const interpolation = createInterpolation({ + inputRange: [0, 1], + outputRange: [ + PlatformColor('@android:color/white'), + PlatformColor('@android:color/darker_gray'), + ], + }); + + // NativeColorValue is deferred to the native side to interpolate + expect(interpolation(0)).toStrictEqual( + PlatformColor('@android:color/white'), + ); + expect(interpolation(2 / 3)).toStrictEqual( + PlatformColor('@android:color/white'), + ); + expect(console.warn).toBeCalledWith( + 'PlatformColor interpolation should happen natively, here we fallback to the closest color', + ); + expect(interpolation(1)).toStrictEqual( + PlatformColor('@android:color/darker_gray'), + ); + }); + it.each([ ['radians', ['1rad', '2rad'], [1, 2]], ['degrees', ['90deg', '180deg'], [Math.PI / 2, Math.PI]],