Skip to content

Commit 21d7997

Browse files
authored
Fix/wheel picker item layout (#1293)
* Add getItemLayout to the WheelPicker * remove ScrollView getNode() * underscore unused argument
1 parent 8d5a55d commit 21d7997

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/incubator/WheelPicker/index.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,8 @@ const WheelPicker = React.memo(({
122122
};
123123

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

131129
const selectItem = useCallback(index => {
@@ -181,6 +179,10 @@ const WheelPicker = React.memo(({
181179
},
182180
[]);
183181

182+
const getItemLayout = useCallback((_data, index: number) => {
183+
return {length: itemHeight, offset: itemHeight * index, index};
184+
}, [itemHeight]);
185+
184186
const contentContainerStyle = useMemo(() => {
185187
return {paddingVertical: height / 2 - itemHeight / 2};
186188
}, [height, itemHeight]);
@@ -205,6 +207,8 @@ const WheelPicker = React.memo(({
205207
snapToInterval={itemHeight}
206208
decelerationRate={Constants.isAndroid ? 0.98 : 'normal'}
207209
renderItem={renderItem}
210+
getItemLayout={getItemLayout}
211+
initialScrollIndex={currentIndex}
208212
/>
209213
</View>
210214
{label && renderLabel()}

0 commit comments

Comments
 (0)