@@ -99,6 +99,7 @@ const WheelPicker = React.memo(({
99
99
preferredNumVisibleRows : numberOfVisibleRows
100
100
} ) ;
101
101
102
+ const prevIndex = useRef ( currentIndex ) ;
102
103
const [ scrollOffset , setScrollOffset ] = useState ( currentIndex * itemHeight ) ;
103
104
104
105
useEffect ( ( ) => {
@@ -122,8 +123,14 @@ const WheelPicker = React.memo(({
122
123
} ;
123
124
124
125
const scrollToIndex = ( index : number , animated : boolean ) => {
126
+ // this is done to handle onMomentumScrollEnd not being called in Android:
127
+ // https://github.com/facebook/react-native/issues/26661
128
+ if ( Constants . isAndroid && prevIndex . current !== index ) {
129
+ prevIndex . current = index ;
130
+ onChange ?.( items ?. [ index ] ?. value , index ) ;
131
+ }
125
132
//@ts -ignore for some reason scrollToOffset isn't recognized
126
- scrollView . current ?. scrollToOffset ( { offset : index * itemHeight , animated} ) ;
133
+ setTimeout ( ( ) => scrollView . current ?. scrollToOffset ( { offset : index * itemHeight , animated} ) , 100 ) ;
127
134
} ;
128
135
129
136
const selectItem = useCallback ( index => {
@@ -181,7 +188,8 @@ const WheelPicker = React.memo(({
181
188
182
189
const getItemLayout = useCallback ( ( _data , index : number ) => {
183
190
return { length : itemHeight , offset : itemHeight * index , index} ;
184
- } , [ itemHeight ] ) ;
191
+ } ,
192
+ [ itemHeight ] ) ;
185
193
186
194
const contentContainerStyle = useMemo ( ( ) => {
187
195
return { paddingVertical : height / 2 - itemHeight / 2 } ;
0 commit comments