Skip to content

WheelPicker - fix item snap to vertical center #2989

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
Mar 20, 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
4 changes: 3 additions & 1 deletion src/components/WheelPicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ const WheelPicker = ({
);
}, []);

const offsets = items.map((_, i) => i * itemHeight);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Inbal-Tish
Shouldn't we memoize this?
This will generate a new list each render and might affect performance

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sure


return (
<View testID={testID} bg-$backgroundDefault style={style}>
<View row centerH>
Expand All @@ -356,7 +358,7 @@ const WheelPicker = ({
ref={scrollView}
// @ts-expect-error
contentContainerStyle={contentContainerStyle}
snapToInterval={itemHeight}
snapToOffsets={offsets}
decelerationRate={Constants.isAndroid ? 0.98 : 'normal'}
renderItem={renderItem}
getItemLayout={getItemLayout}
Expand Down