|
8 | 8 | * @format |
9 | 9 | */ |
10 | 10 |
|
11 | | -import type {InterpolationConfigType} from '../nodes/AnimatedInterpolation'; |
| 11 | +import type { |
| 12 | + InterpolationConfigSupportedOutputType, |
| 13 | + InterpolationConfigType, |
| 14 | +} from '../nodes/AnimatedInterpolation'; |
12 | 15 |
|
| 16 | +import {PlatformColor} from '../../../Libraries/StyleSheet/PlatformColorValueTypes'; |
13 | 17 | import Easing from '../Easing'; |
14 | 18 | import AnimatedInterpolation from '../nodes/AnimatedInterpolation'; |
15 | 19 |
|
16 | | -function createInterpolation<T: number | string>( |
| 20 | +function createInterpolation<T: InterpolationConfigSupportedOutputType>( |
17 | 21 | config: InterpolationConfigType<T>, |
18 | 22 | ): number => T { |
19 | 23 | let parentValue = null; |
@@ -360,6 +364,31 @@ describe('Interpolation', () => { |
360 | 364 | expect(interpolation(2 / 3)).toBe('rgba(0, 0, 0, 0.667)'); |
361 | 365 | }); |
362 | 366 |
|
| 367 | + it('should work with PlatformColor', () => { |
| 368 | + jest.spyOn(console, 'warn').mockImplementationOnce(() => {}); |
| 369 | + const interpolation = createInterpolation({ |
| 370 | + inputRange: [0, 1], |
| 371 | + outputRange: [ |
| 372 | + PlatformColor('@android:color/white'), |
| 373 | + PlatformColor('@android:color/darker_gray'), |
| 374 | + ], |
| 375 | + }); |
| 376 | + |
| 377 | + // NativeColorValue is deferred to the native side to interpolate |
| 378 | + expect(interpolation(0)).toStrictEqual( |
| 379 | + PlatformColor('@android:color/white'), |
| 380 | + ); |
| 381 | + expect(interpolation(2 / 3)).toStrictEqual( |
| 382 | + PlatformColor('@android:color/white'), |
| 383 | + ); |
| 384 | + expect(console.warn).toBeCalledWith( |
| 385 | + 'PlatformColor interpolation should happen natively, here we fallback to the closest color', |
| 386 | + ); |
| 387 | + expect(interpolation(1)).toStrictEqual( |
| 388 | + PlatformColor('@android:color/darker_gray'), |
| 389 | + ); |
| 390 | + }); |
| 391 | + |
363 | 392 | it.each([ |
364 | 393 | ['radians', ['1rad', '2rad'], [1, 2]], |
365 | 394 | ['degrees', ['90deg', '180deg'], [Math.PI / 2, Math.PI]], |
|
0 commit comments