@@ -63,6 +63,7 @@ const Picker = (props: PickerProps) => {
63
63
const ItemHeights = useRef < Array < number > > ( [ ] ) . current ;
64
64
const saveY = useRef < number > ( 0 ) ;
65
65
const timer = useRef < NodeJS . Timeout > ( ) ;
66
+ const onPressTimer = useRef < NodeJS . Timeout > ( ) ;
66
67
const onPressORonScroll = useRef < 'onPress' | 'onScroll' > ( 'onScroll' ) ;
67
68
const currentY = useRef < number > ( 0 ) ;
68
69
const [ current , setCurrent ] = useState ( 0 ) ;
@@ -103,7 +104,6 @@ const Picker = (props: PickerProps) => {
103
104
let an = Platform . OS === 'android' && { duration : 0 } ;
104
105
let os = Platform . OS === 'ios' && { animated : false } ;
105
106
scrollView . current ?. scrollTo ( { x : 0 , y : scrollY - ( style . containerHeight as number ) , ...an , ...os } ) ;
106
- setCurrent ( index ) ;
107
107
} ;
108
108
const setScrollHandle = ( val : number ) => {
109
109
const spot = val / ItemHeights [ 0 ] ;
@@ -123,7 +123,14 @@ const Picker = (props: PickerProps) => {
123
123
timer . current = undefined ;
124
124
} ;
125
125
const listener = ( event : NativeSyntheticEvent < NativeScrollEvent > ) => {
126
- if ( onPressORonScroll . current === 'onPress' ) return ;
126
+ if ( onPressORonScroll . current === 'onPress' ) {
127
+ clearTimeout ( onPressTimer . current ! ) ;
128
+ onPressTimer . current = setTimeout ( ( ) => {
129
+ setCurrent ( currentY . current ) ;
130
+ clearTimeout ( onPressTimer . current ! ) ;
131
+ } , 16 ) ;
132
+ return ;
133
+ }
127
134
saveY . current = event . nativeEvent . contentOffset . y ;
128
135
if ( timer . current ) {
129
136
clearTimeout ( timer . current ! ) ;
@@ -162,6 +169,7 @@ const Picker = (props: PickerProps) => {
162
169
onPressOut = { Platform . OS === 'android' ? onTouchEnd : undefined }
163
170
onPress = { ( ) => {
164
171
if ( timer . current ) return ;
172
+ clearTimeout ( onPressTimer . current ! ) ;
165
173
onPressORonScroll . current = 'onPress' ;
166
174
location ( ItemHeights ! [ index ] , index ) ;
167
175
} }
0 commit comments