Skip to content

Commit 4740f21

Browse files
zeyapmeta-codesync[bot]
authored andcommitted
Extract helper function from AnimatedColor.js to process input color value (#54077)
Summary: Pull Request resolved: #54077 ## Changelog: [Internal] [Changed] - Extract helper function from AnimatedColor.js to process input color value Reviewed By: rozele Differential Revision: D84062952 fbshipit-source-id: 2005dc33d7fd6928ba2638d0d99a2e5faa8448d8
1 parent 9e98c72 commit 4740f21

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

packages/react-native/Libraries/Animated/nodes/AnimatedColor.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,27 @@ function isRgbaAnimatedValue(value: any): boolean {
110110
);
111111
}
112112

113+
export function getRgbaValueAndNativeColor(
114+
value: RgbaValue | ColorValue,
115+
): $ReadOnly<{
116+
rgbaValue: RgbaValue,
117+
nativeColor?: NativeColorValue,
118+
}> {
119+
const processedColor: RgbaValue | NativeColorValue =
120+
// $FlowFixMe[incompatible-type] - Type is verified above
121+
processColor((value: ColorValue | RgbaValue)) ?? defaultColor;
122+
if (isRgbaValue(processedColor)) {
123+
// $FlowFixMe[incompatible-type] - Type is verified above
124+
return {rgbaValue: (processedColor: RgbaValue)};
125+
} else {
126+
return {
127+
// $FlowFixMe[incompatible-type] - Type is verified above
128+
nativeColor: (processedColor: NativeColorValue),
129+
rgbaValue: defaultColor,
130+
};
131+
}
132+
}
133+
113134
export default class AnimatedColor extends AnimatedWithChildren {
114135
r: AnimatedValue;
115136
g: AnimatedValue;
@@ -132,18 +153,13 @@ export default class AnimatedColor extends AnimatedWithChildren {
132153
this.b = rgbaAnimatedValue.b;
133154
this.a = rgbaAnimatedValue.a;
134155
} else {
135-
const processedColor: RgbaValue | NativeColorValue =
136-
// $FlowFixMe[incompatible-type] - Type is verified above
137-
processColor((value: ColorValue | RgbaValue)) ?? defaultColor;
138-
let initColor: RgbaValue = defaultColor;
139-
if (isRgbaValue(processedColor)) {
156+
const {rgbaValue: initColor, nativeColor} = getRgbaValueAndNativeColor(
140157
// $FlowFixMe[incompatible-type] - Type is verified above
141-
initColor = (processedColor: RgbaValue);
142-
} else {
143-
// $FlowFixMe[incompatible-type] - Type is verified above
144-
this.nativeColor = (processedColor: NativeColorValue);
158+
(value: ColorValue | RgbaValue),
159+
);
160+
if (nativeColor) {
161+
this.nativeColor = nativeColor;
145162
}
146-
147163
this.r = new AnimatedValue(initColor.r);
148164
this.g = new AnimatedValue(initColor.g);
149165
this.b = new AnimatedValue(initColor.b);

0 commit comments

Comments
 (0)