Skip to content

Commit d377226

Browse files
authored
WheelPicker - fix warning about getNode (#1403)
* WheelPicker - fix warning about getNode * Add missing semicolon * change from ignore to expect-error
1 parent 07052c6 commit d377226

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/incubator/WheelPicker/index.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// TODO: Support style customization
2+
import {isFunction} from 'lodash';
23
import React, {useCallback, useRef, useMemo, useEffect, useState} from 'react';
34
import {TextStyle, ViewStyle, FlatList, NativeSyntheticEvent, NativeScrollEvent, StyleSheet} from 'react-native';
45
import Animated, {useSharedValue, useAnimatedScrollHandler} from 'react-native-reanimated';
@@ -131,15 +132,26 @@ const WheelPicker = React.memo(({
131132
scrollToIndex(currentIndex, false);
132133
}, []);
133134

135+
const scrollToOffset = (index: number, animated: boolean) => {
136+
// TODO: we should remove this split (the getNode section) in V6 and remove support for reanimated 1
137+
//@ts-expect-error for some reason scrollToOffset isn't recognized
138+
if (isFunction(scrollView.current?.scrollToOffset)) {
139+
//@ts-expect-error
140+
scrollView.current?.scrollToOffset({offset: index * itemHeight, animated});
141+
} else {
142+
//@ts-expect-error
143+
scrollView.current?.getNode()?.scrollToOffset({offset: index * itemHeight, animated});
144+
}
145+
};
146+
134147
const scrollToIndex = (index: number, animated: boolean) => {
135148
// this is done to handle onMomentumScrollEnd not being called in Android:
136149
// https://github.com/facebook/react-native/issues/26661
137150
if (Constants.isAndroid && prevIndex.current !== index) {
138151
prevIndex.current = index;
139152
onChange?.(items?.[index]?.value, index);
140153
}
141-
//@ts-ignore for some reason scrollToOffset isn't recognized
142-
setTimeout(() => scrollView.current?.getNode()?.scrollToOffset({offset: index * itemHeight, animated}), 100);
154+
setTimeout(() => scrollToOffset(index, animated), 100);
143155
};
144156

145157
const selectItem = useCallback(index => {

0 commit comments

Comments
 (0)