@@ -8,7 +8,7 @@ import React, {
8
8
} from 'react'
9
9
import clsx from 'clsx'
10
10
import { PickerColumnOption , PickerColumnProps } from './PropsType'
11
- import { createNamespace , range } from '../utils'
11
+ import { createNamespace , range , unitToPx } from '../utils'
12
12
import { useIsomorphicLayoutEffect , useSetState , useTouch } from '../hooks'
13
13
import ConfigProviderContext from '../config-provider/ConfigProviderContext'
14
14
@@ -39,12 +39,14 @@ const PickerColumn = memo<
39
39
const {
40
40
valueKey,
41
41
textKey,
42
- itemHeight,
42
+ itemHeight : _itemHeight ,
43
43
visibleItemCount,
44
44
placeholder,
45
45
value,
46
46
} = props
47
47
48
+ const itemHeight = useMemo ( ( ) => unitToPx ( _itemHeight ) , [ _itemHeight ] )
49
+
48
50
const options = useMemo ( ( ) => {
49
51
if ( Array . isArray ( props . options ) && ! props . options . length ) return [ ]
50
52
if ( placeholder ) {
@@ -96,7 +98,7 @@ const PickerColumn = memo<
96
98
97
99
const setIndex = ( index : number ) => {
98
100
index = adjustIndex ( index ) || 0
99
- const offset = - index * props . itemHeight
101
+ const offset = - index * itemHeight
100
102
const trigger = ( ) => {
101
103
if ( options [ index ] ?. [ valueKey ] !== value ) {
102
104
onSelect ( options [ index ] )
@@ -114,7 +116,7 @@ const PickerColumn = memo<
114
116
115
117
const animate = ( index : number ) => {
116
118
index = adjustIndex ( index ) || 0
117
- const offset = - index * props . itemHeight
119
+ const offset = - index * itemHeight
118
120
updateState ( { offset } )
119
121
}
120
122
@@ -143,7 +145,7 @@ const PickerColumn = memo<
143
145
}
144
146
145
147
const getIndexByOffset = ( offset : number ) =>
146
- range ( Math . round ( - offset / props . itemHeight ) , 0 , options . length - 1 )
148
+ range ( Math . round ( - offset / itemHeight ) , 0 , options . length - 1 )
147
149
148
150
const momentum = ( distance : number , _duration : number ) => {
149
151
const speed = Math . abs ( distance / _duration )
@@ -201,8 +203,8 @@ const PickerColumn = memo<
201
203
202
204
const offset = range (
203
205
startOffset . current + touch . deltaY . current ,
204
- - ( options . length * props . itemHeight ) ,
205
- props . itemHeight
206
+ - ( options . length * itemHeight ) ,
207
+ itemHeight
206
208
)
207
209
208
210
updateState ( {
0 commit comments