From c970d4b237392f946429b6ecc90276011ac656bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20Go=CC=88ttert?= Date: Wed, 11 Mar 2026 08:30:54 +0100 Subject: [PATCH 1/3] Fix issue with initial visibility --- src/WheelPicker.tsx | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/WheelPicker.tsx b/src/WheelPicker.tsx index cd0f0c4..9d13cc1 100644 --- a/src/WheelPicker.tsx +++ b/src/WheelPicker.tsx @@ -49,8 +49,10 @@ const WheelPicker: React.FC = ({ containerProps = {}, flatListProps = {}, }) => { - const flatListRef = useRef(null); - const [scrollY] = useState(new Animated.Value(0)); + const flatListRef = useRef>(null); + const [scrollY] = useState( + () => new Animated.Value(selectedIndex * itemHeight), + ); const containerHeight = (1 + visibleRest * 2) * itemHeight; const paddedOptions = useMemo(() => { @@ -107,11 +109,16 @@ const WheelPicker: React.FC = ({ * This ensures that what the user sees as selected in the picker always corresponds to the value state. */ useEffect(() => { - flatListRef.current?.scrollToIndex({ - index: selectedIndex, + const offset = selectedIndex * itemHeight; + + // Also sync animated-state instantly + scrollY.setValue(offset); + + flatListRef.current?.scrollToOffset({ + offset, animated: false, }); - }, [selectedIndex]); + }, [selectedIndex, itemHeight, scrollY]); return ( = ({ ref={flatListRef} style={styles.scrollView} showsVerticalScrollIndicator={false} + contentOffset={{ x: 0, y: selectedIndex * itemHeight }} onScroll={Animated.event( [{ nativeEvent: { contentOffset: { y: scrollY } } }], { useNativeDriver: true }, From 72caeb153ad1b9a4221b5067201816d2b85f8f19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20Go=CC=88ttert?= Date: Wed, 11 Mar 2026 08:35:51 +0100 Subject: [PATCH 2/3] Clean up changes that apparently were not necessary --- src/WheelPicker.tsx | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/WheelPicker.tsx b/src/WheelPicker.tsx index 9d13cc1..70d3dc2 100644 --- a/src/WheelPicker.tsx +++ b/src/WheelPicker.tsx @@ -49,10 +49,8 @@ const WheelPicker: React.FC = ({ containerProps = {}, flatListProps = {}, }) => { - const flatListRef = useRef>(null); - const [scrollY] = useState( - () => new Animated.Value(selectedIndex * itemHeight), - ); + const flatListRef = useRef(null); + const [scrollY] = useState(() => new Animated.Value(selectedIndex * itemHeight)); const containerHeight = (1 + visibleRest * 2) * itemHeight; const paddedOptions = useMemo(() => { @@ -140,7 +138,6 @@ const WheelPicker: React.FC = ({ ref={flatListRef} style={styles.scrollView} showsVerticalScrollIndicator={false} - contentOffset={{ x: 0, y: selectedIndex * itemHeight }} onScroll={Animated.event( [{ nativeEvent: { contentOffset: { y: scrollY } } }], { useNativeDriver: true }, From b6c86def3f2b49bf61bf286beee281c031ce0d4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20Go=CC=88ttert?= Date: Wed, 11 Mar 2026 09:12:31 +0100 Subject: [PATCH 3/3] Clean up changes that apparently were not necessary II --- src/WheelPicker.tsx | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/WheelPicker.tsx b/src/WheelPicker.tsx index 70d3dc2..c98f812 100644 --- a/src/WheelPicker.tsx +++ b/src/WheelPicker.tsx @@ -107,16 +107,11 @@ const WheelPicker: React.FC = ({ * This ensures that what the user sees as selected in the picker always corresponds to the value state. */ useEffect(() => { - const offset = selectedIndex * itemHeight; - - // Also sync animated-state instantly - scrollY.setValue(offset); - - flatListRef.current?.scrollToOffset({ - offset, + flatListRef.current?.scrollToIndex({ + index: selectedIndex, animated: false, }); - }, [selectedIndex, itemHeight, scrollY]); + }, [selectedIndex]); return (