Skip to content

TabController - fix indicator when using old reanimated (ignore TS) #3241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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