@@ -50,12 +50,11 @@ const WheelPicker: React.FC<Props> = ({
5050} ) => {
5151 const flatListRef = useRef < FlatList > ( null ) ;
5252 const [ scrollY ] = useState ( new Animated . Value ( 0 ) ) ;
53- const flatList = useRef < any > ( null )
5453
55- const lastScrollTimestamp = useRef ( new Date ( ) . getTime ( ) )
54+ const lastScrollTimestamp = useRef ( new Date ( ) . getTime ( ) ) ;
5655
5756 const containerHeight = ( 1 + visibleRest * 2 ) * itemHeight ;
58- const [ scrollIndex , setScrollIndex ] = useState ( selectedIndex )
57+ const [ scrollIndex , setScrollIndex ] = useState ( selectedIndex ) ;
5958 const paddedOptions = useMemo ( ( ) => {
6059 const array : ( string | null ) [ ] = [ ...options ] ;
6160 for ( let i = 0 ; i < visibleRest ; i ++ ) {
@@ -101,45 +100,39 @@ const WheelPicker: React.FC<Props> = ({
101100
102101
103102 useEffect ( ( ) => {
104- if ( Platform . OS === " web" ) {
105- const SCROLL_COOLDOWN_MILISECONDS = 100
106- const SCROLL_DID_STOP_TIMEOUT = 500
103+ if ( Platform . OS === ' web' ) {
104+ const SCROLL_COOLDOWN_MILLISECONDS = 100 ;
105+ const SCROLL_DID_STOP_TIMEOUT = 500 ;
107106 const intervalID = setInterval ( ( ) => {
108- const time = new Date ( ) . getTime ( )
109- const difference = time - lastScrollTimestamp . current
107+ const time = new Date ( ) . getTime ( ) ;
108+ const difference = time - lastScrollTimestamp . current ;
110109 if ( difference > SCROLL_DID_STOP_TIMEOUT ) {
111- flatList . current ?. scrollToIndex ( { index : scrollIndex , animated : true } )
110+ flatListRef . current ?. scrollToIndex ( {
111+ index : scrollIndex ,
112+ animated : true ,
113+ } ) ;
112114 }
113- } , SCROLL_COOLDOWN_MILISECONDS )
115+ } , SCROLL_COOLDOWN_MILLISECONDS ) ;
114116 return ( ) => {
115- clearInterval ( intervalID )
116- }
117+ clearInterval ( intervalID ) ;
118+ } ;
117119 }
118- } , [ scrollIndex ] )
120+ } , [ scrollIndex ] ) ;
119121
120122 useEffect ( ( ) => {
121- if ( Platform . OS === "web" ) {
122- if ( onChange ) {
123- onChange ( scrollIndex )
124- }
123+ if ( Platform . OS === 'web' ) {
124+ onChange ( scrollIndex ) ;
125125 }
126- } , [ scrollIndex ] )
126+ } , [ scrollIndex , onChange ] ) ;
127127
128- const handleScroll = ( event : {
129- nativeEvent : {
130- contentInset : { bottom : number , left : number , right : number , top : number } ,
131- contentOffset : { x : number , y : number } ,
132- contentSize : { height : number , width : number } ,
133- layoutMeasurement : { height : number , width : number } ,
128+ const handleScroll = ( event : Animated . EventConfig < NativeScrollEvent > ) => {
129+ if ( Platform . OS === 'web' ) {
130+ const positionY = event . nativeEvent . contentOffset . y ;
131+ const index = Math . round ( positionY / itemHeight ) ;
132+ setScrollIndex ( index ) ;
133+ lastScrollTimestamp . current = new Date ( ) . getTime ( ) ;
134134 }
135- } ) => {
136- if ( Platform . OS === "web" ) {
137- const positionY = event ?. nativeEvent ?. contentOffset ?. y ?? 0 ;
138- const index = Math . round ( positionY / itemHeight )
139- setScrollIndex ( index )
140- lastScrollTimestamp . current = new Date ( ) . getTime ( )
141- }
142- }
135+ } ;
143136
144137 return (
145138 < View
0 commit comments