@@ -156,6 +156,21 @@ const Picker = (props: PickerProps) => {
156156 setScrollHandle ( saveY . current ) ;
157157 }
158158 } ;
159+ const getBlankHeight = useMemo ( ( ) => {
160+ if ( lines % 2 ) {
161+ return {
162+ top : Math . floor ( lines / 2 ) ,
163+ center : Number ( ( lines / 2 ) . toFixed ( ) ) ,
164+ bottom : Math . floor ( lines / 2 ) ,
165+ } ;
166+ }
167+ return {
168+ top : lines / 2 - 1 ,
169+ center : lines / 2 + 1 ,
170+ bottom : lines / 2 ,
171+ } ;
172+ } , [ lines ] ) ;
173+
159174 return (
160175 < View style = { { paddingVertical : 0 , height : ( style . containerHeight as number ) * lines } } >
161176 < ScrollView
@@ -169,6 +184,12 @@ const Picker = (props: PickerProps) => {
169184 } ) }
170185 scrollEnabled = { ! readonly }
171186 >
187+ {
188+ < Pressable
189+ style = { [ style . containerUn , { height : ( style . containerHeight as number ) * getBlankHeight . top } ] }
190+ onPressOut = { Platform . OS === 'android' ? onTouchEnd : undefined }
191+ />
192+ }
172193 { data . map ( ( item , index ) => (
173194 < Pressable
174195 onLayout = { getItemHeight }
@@ -193,13 +214,13 @@ const Picker = (props: PickerProps) => {
193214 ) ) }
194215 {
195216 < Pressable
196- style = { [ style . containerUn , { height : ( style . containerHeight as number ) * ( lines - 1 ) } ] }
217+ style = { [ style . containerUn , { height : ( style . containerHeight as number ) * getBlankHeight . bottom } ] }
197218 onPressOut = { Platform . OS === 'android' ? onTouchEnd : undefined }
198219 />
199220 }
200221 </ ScrollView >
201- < View style = { [ style . containerAc , { top : ( - style . containerHeight as number ) * lines } ] } />
202- < View style = { [ style . containerAc , { top : ( - style . containerHeight as number ) * ( lines - 1 ) } ] } />
222+ < View style = { [ style . containerAc , { top : ( - style . containerHeight as number ) * getBlankHeight . center } ] } />
223+ < View style = { [ style . containerAc , { top : ( - style . containerHeight as number ) * ( getBlankHeight . center - 1 ) } ] } />
203224 </ View >
204225 ) ;
205226} ;
0 commit comments