From 21d799769920a10711cda4270909fca20b887463 Mon Sep 17 00:00:00 2001 From: Lidor Dafna <66782556+lidord-wix@users.noreply.github.com> Date: Wed, 12 May 2021 12:55:05 +0300 Subject: [PATCH] Fix/wheel picker item layout (#1293) * Add getItemLayout to the WheelPicker * remove ScrollView getNode() * underscore unused argument --- src/incubator/WheelPicker/index.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/incubator/WheelPicker/index.tsx b/src/incubator/WheelPicker/index.tsx index 05153435bb..ac730ef859 100644 --- a/src/incubator/WheelPicker/index.tsx +++ b/src/incubator/WheelPicker/index.tsx @@ -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 => { @@ -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]); @@ -205,6 +207,8 @@ const WheelPicker = React.memo(({ snapToInterval={itemHeight} decelerationRate={Constants.isAndroid ? 0.98 : 'normal'} renderItem={renderItem} + getItemLayout={getItemLayout} + initialScrollIndex={currentIndex} /> {label && renderLabel()}