Skip to content

Commit

Permalink
Fix/wheel picker item layout (#1293)
Browse files Browse the repository at this point in the history
* Add getItemLayout to the WheelPicker

* remove ScrollView getNode()

* underscore unused argument
  • Loading branch information
lidord-wix authored May 12, 2021
1 parent 8d5a55d commit 21d7997
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/incubator/WheelPicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,8 @@ const WheelPicker = React.memo(({
};

const scrollToIndex = (index: number, animated: boolean) => {
if (scrollView.current?.getNode()) {
//@ts-ignore for some reason scrollToOffset isn't recognized
scrollView.current?.getNode()?.scrollToOffset({offset: index * itemHeight, animated});
}
//@ts-ignore for some reason scrollToOffset isn't recognized
scrollView.current?.scrollToOffset({offset: index * itemHeight, animated});
};

const selectItem = useCallback(index => {
Expand Down Expand Up @@ -181,6 +179,10 @@ const WheelPicker = React.memo(({
},
[]);

const getItemLayout = useCallback((_data, index: number) => {
return {length: itemHeight, offset: itemHeight * index, index};
}, [itemHeight]);

const contentContainerStyle = useMemo(() => {
return {paddingVertical: height / 2 - itemHeight / 2};
}, [height, itemHeight]);
Expand All @@ -205,6 +207,8 @@ const WheelPicker = React.memo(({
snapToInterval={itemHeight}
decelerationRate={Constants.isAndroid ? 0.98 : 'normal'}
renderItem={renderItem}
getItemLayout={getItemLayout}
initialScrollIndex={currentIndex}
/>
</View>
{label && renderLabel()}
Expand Down

0 comments on commit 21d7997

Please sign in to comment.