Skip to content

Commit

Permalink
TabController - fix indicator when using old reanimated (ignore TS) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
M-i-k-e-l authored Sep 4, 2024
1 parent abeac15 commit c95d43f
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/components/tabController/useScrollToItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ const useScrollToItem = <T extends ScrollToSupportedViews>(props: ScrollToItemPr
innerSpacing = 0
} = props;
const itemsWidths = useRef<(number | null)[]>(_.times(itemsCount, () => null));
const itemsWidthsAnimated = useSharedValue(_.times(itemsCount, () => 0));
const itemsOffsetsAnimated = useSharedValue(_.times(itemsCount, () => 0));
const itemsWidthsAnimated = useSharedValue<number[]>(_.times(itemsCount, () => 0));
const itemsOffsetsAnimated = useSharedValue<number[]>(_.times(itemsCount, () => 0));
const currentIndex = useRef<number>(selectedIndex || 0);
const [offsets, setOffsets] = useState<Offsets>({CENTER: [], LEFT: [], RIGHT: []});
const {scrollViewRef, scrollTo, onContentSizeChange, onLayout} = useScrollTo<T>({scrollViewRef: propsScrollViewRef});
Expand Down Expand Up @@ -148,12 +148,10 @@ const useScrollToItem = <T extends ScrollToSupportedViews>(props: ScrollToItemPr
setOffsets({CENTER: centeredOffsets, LEFT: leftOffsets, RIGHT: rightOffsets}); // default for DYNAMIC is CENTER

// Update shared values
// @ts-expect-error pretty sure this is a bug in reanimated since itemsWidthsAnimated is defined as SharedValue<number[]>
itemsWidthsAnimated.modify((value) => {
'worklet';
value.forEach((_, index) => {
value[index] = widths[index];
});
return value;
return value.map((_, index) => widths[index]);
});

itemsOffsetsAnimated.modify((value) => {
Expand Down

0 comments on commit c95d43f

Please sign in to comment.