Skip to content

Commit 6c82640

Browse files
committed
fix: default EaseText color transitions
1 parent acc810b commit 6c82640

2 files changed

Lines changed: 32 additions & 7 deletions

File tree

src/__tests__/EaseText.test.tsx

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
import { render, screen } from '@testing-library/react-native';
22
import { EaseText } from '../EaseText';
33

4+
function getTextColor(text: ReturnType<typeof screen.getByText>) {
5+
const flatStyle = Array.isArray(text.props.style)
6+
? Object.assign({}, ...text.props.style.filter(Boolean))
7+
: text.props.style;
8+
return flatStyle?.color;
9+
}
10+
411
describe('EaseText', () => {
512
describe('interpolateColor', () => {
613
it('applies interpolateColor to Text style', () => {
714
render(<EaseText interpolateColor="#ff0000">Hello</EaseText>);
815
const text = screen.getByText('Hello');
9-
const flatStyle = Array.isArray(text.props.style)
10-
? Object.assign({}, ...text.props.style.filter(Boolean))
11-
: text.props.style;
12-
expect(flatStyle.color).toBe('#ff0000');
16+
expect(getTextColor(text)).toBe('#ff0000');
1317
});
1418

1519
it('merges interpolateColor with existing style', () => {
@@ -25,11 +29,26 @@ describe('EaseText', () => {
2529
const flatStyle = Array.isArray(text.props.style)
2630
? Object.assign({}, ...text.props.style.filter(Boolean))
2731
: text.props.style;
28-
expect(flatStyle.color).toBe('#ff0000');
32+
expect(getTextColor(text)).toBe('#ff0000');
2933
expect(flatStyle.fontSize).toBe(16);
3034
expect(flatStyle.fontWeight).toBe('600');
3135
});
3236

37+
it('does not apply the target color immediately when color is omitted from a transition map', () => {
38+
render(
39+
<EaseText
40+
interpolateColor="#ffffff"
41+
initialInterpolateColor="#000000"
42+
transition={{ transform: { type: 'spring' } }}
43+
>
44+
Hello
45+
</EaseText>,
46+
);
47+
48+
const text = screen.getByText('Hello');
49+
expect(getTextColor(text)).toBe('#000000');
50+
});
51+
3352
it('does not override style when interpolateColor is not set', () => {
3453
render(
3554
<EaseText style={{ fontSize: 16, color: '#000' }}>Hello</EaseText>,

src/useColorTransition.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ const easings: Record<string, (t: number) => number> = {
3838
};
3939

4040
/** Resolve the color transition config. Follows the same logic as EaseView:
41-
* color category → default fallback. No transition = instant. */
41+
* use `color`, else `default`, else implicit defaults (300ms easeInOut), including
42+
* when `transition` is omitted or a category map has no color-specific entry.
43+
* Instant only when the resolved single transition has `type: 'none'`. */
4244
function resolveColorConfig(transition?: Transition): {
4345
duration: number;
4446
easing: (t: number) => number;
@@ -55,7 +57,11 @@ function resolveColorConfig(transition?: Transition): {
5557
config = transition.color ?? transition.default;
5658
}
5759

58-
if (!config || config.type === 'none') {
60+
if (!config) {
61+
return defaults;
62+
}
63+
64+
if (config.type === 'none') {
5965
return { duration: 0, easing: easings.linear!, delay: 0 };
6066
}
6167

0 commit comments

Comments
 (0)