Skip to content

Commit 8928314

Browse files
authored
Merge pull request #62285 from callstack-internal/fix/optimize-useAnimatedHighlightStyle
Optimize useAnimatedHighlightStyle to reduce unnecessary recalculations
2 parents 04bc4a5 + bb2e1d4 commit 8928314

File tree

1 file changed

+13
-6
lines changed
  • src/hooks/useAnimatedHighlightStyle

1 file changed

+13
-6
lines changed

src/hooks/useAnimatedHighlightStyle/index.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,19 @@ export default function useAnimatedHighlightStyle({
6565
const {didScreenTransitionEnd} = useScreenWrapperTransitionStatus();
6666
const theme = useTheme();
6767

68-
const highlightBackgroundStyle = useAnimatedStyle(() => ({
69-
backgroundColor: interpolateColor(repeatableProgress.get(), [0, 1], [backgroundColor ?? theme.appBG, highlightColor ?? theme.border]),
70-
height: height ? interpolate(nonRepeatableProgress.get(), [0, 1], [0, height]) : 'auto',
71-
opacity: interpolate(nonRepeatableProgress.get(), [0, 1], [0, 1]),
72-
borderRadius,
73-
}));
68+
const highlightBackgroundStyle = useAnimatedStyle(() => {
69+
'worklet';
70+
71+
const repeatableValue = repeatableProgress.get();
72+
const nonRepeatableValue = nonRepeatableProgress.get();
73+
74+
return {
75+
backgroundColor: interpolateColor(repeatableValue, [0, 1], [backgroundColor ?? theme.appBG, highlightColor ?? theme.border]),
76+
height: height ? interpolate(nonRepeatableValue, [0, 1], [0, height]) : 'auto',
77+
opacity: interpolate(nonRepeatableValue, [0, 1], [0, 1]),
78+
borderRadius,
79+
};
80+
}, [borderRadius, height, backgroundColor, highlightColor, theme.appBG, theme.border]);
7481

7582
React.useEffect(() => {
7683
if (!shouldHighlight || startHighlight) {

0 commit comments

Comments
 (0)