@@ -156,6 +156,21 @@ const Picker = (props: PickerProps) => {
156
156
setScrollHandle ( saveY . current ) ;
157
157
}
158
158
} ;
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
+
159
174
return (
160
175
< View style = { { paddingVertical : 0 , height : ( style . containerHeight as number ) * lines } } >
161
176
< ScrollView
@@ -169,6 +184,12 @@ const Picker = (props: PickerProps) => {
169
184
} ) }
170
185
scrollEnabled = { ! readonly }
171
186
>
187
+ {
188
+ < Pressable
189
+ style = { [ style . containerUn , { height : ( style . containerHeight as number ) * getBlankHeight . top } ] }
190
+ onPressOut = { Platform . OS === 'android' ? onTouchEnd : undefined }
191
+ />
192
+ }
172
193
{ data . map ( ( item , index ) => (
173
194
< Pressable
174
195
onLayout = { getItemHeight }
@@ -193,13 +214,13 @@ const Picker = (props: PickerProps) => {
193
214
) ) }
194
215
{
195
216
< Pressable
196
- style = { [ style . containerUn , { height : ( style . containerHeight as number ) * ( lines - 1 ) } ] }
217
+ style = { [ style . containerUn , { height : ( style . containerHeight as number ) * getBlankHeight . bottom } ] }
197
218
onPressOut = { Platform . OS === 'android' ? onTouchEnd : undefined }
198
219
/>
199
220
}
200
221
</ 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 ) } ] } />
203
224
</ View >
204
225
) ;
205
226
} ;
0 commit comments