Skip to content

Commit c56941d

Browse files
fix(pickerview): 解决小程序获取高度计算错误 (#3120)
* feat(pickerview): 选中值增加class类名用于自定义样式 * feat(pickerview): 选中值增加class类名用于自定义样式 * fix: remove console * chore: add types alias * test: update snap * feat: 小程序支持自定义列表行高 * fix: update test * fix: cr修改 * fix(pickerciew): 解决小程序获取高度计算错误 --------- Co-authored-by: oasis <[email protected]>
1 parent ccacc38 commit c56941d

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/packages/pickerview/pickerroller.taro.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const InternalPickerRoller: ForwardRefRenderFunction<
4444
const isMoving = useRef(false)
4545
const rollerRef = useRef<any>(null)
4646
const pickerRollerRef = useRef<any>(null)
47+
const placeholderRef = useRef(null)
4748
const [startTime, setStartTime] = useState(0)
4849
const [startY, setStartY] = useState(0)
4950
const transformY = useRef(0)
@@ -157,7 +158,7 @@ const InternalPickerRoller: ForwardRefRenderFunction<
157158

158159
const getReactHeight = async () => {
159160
try {
160-
const placeholder = await getRectByTaro(rollerRef.current)
161+
const placeholder = await getRectByTaro(placeholderRef.current)
161162
const placeholderHeight = placeholder.height || 0
162163
return placeholderHeight
163164
} catch (error) {
@@ -187,7 +188,7 @@ const InternalPickerRoller: ForwardRefRenderFunction<
187188
}
188189
})
189190
}
190-
}, [pickerRollerRef.current, rollerRef.current])
191+
}, [pickerRollerRef.current, placeholderRef.current])
191192

192193
useEffect(() => {
193194
isMoving.current = false
@@ -246,6 +247,11 @@ const InternalPickerRoller: ForwardRefRenderFunction<
246247

247248
return (
248249
<View className="nut-pickerview-list" ref={pickerRollerRef}>
250+
<View
251+
className={`${classPrefix}-placeholder`}
252+
ref={placeholderRef}
253+
id={`${classPrefix}-placeholder-${uuid}`}
254+
/>
249255
<View
250256
className={classPrefix}
251257
id={`${classPrefix}-${uuid}`}

src/packages/pickerview/pickerview.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
height: $picker-item-height;
5050
z-index: 1;
5151
transform-style: preserve-3d;
52+
&-placeholder {
53+
height: $picker-item-height;
54+
}
5255
}
5356

5457
&-roller-item {

0 commit comments

Comments
 (0)