|
1 | 1 | // TODO: Support style customization
|
| 2 | +import {isFunction} from 'lodash'; |
2 | 3 | import React, {useCallback, useRef, useMemo, useEffect, useState} from 'react';
|
3 | 4 | import {TextStyle, ViewStyle, FlatList, NativeSyntheticEvent, NativeScrollEvent, StyleSheet} from 'react-native';
|
4 | 5 | import Animated, {useSharedValue, useAnimatedScrollHandler} from 'react-native-reanimated';
|
@@ -131,15 +132,26 @@ const WheelPicker = React.memo(({
|
131 | 132 | scrollToIndex(currentIndex, false);
|
132 | 133 | }, []);
|
133 | 134 |
|
| 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 | + |
134 | 147 | const scrollToIndex = (index: number, animated: boolean) => {
|
135 | 148 | // this is done to handle onMomentumScrollEnd not being called in Android:
|
136 | 149 | // https://github.com/facebook/react-native/issues/26661
|
137 | 150 | if (Constants.isAndroid && prevIndex.current !== index) {
|
138 | 151 | prevIndex.current = index;
|
139 | 152 | onChange?.(items?.[index]?.value, index);
|
140 | 153 | }
|
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); |
143 | 155 | };
|
144 | 156 |
|
145 | 157 | const selectItem = useCallback(index => {
|
|
0 commit comments