Skip to content

Commit 157b518

Browse files
committed
fix: 修改快速滚动偶现滑动错位问题
1 parent 66b2e79 commit 157b518

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/packages/pickerview/pickerroller.taro.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ const InternalPickerRoller: ForwardRefRenderFunction<
107107
onSelect?.(options?.[Math.round(-move / lineSpacing.current)], keyIndex)
108108
}
109109

110+
const isScroll = useRef(false)
111+
110112
const handleTouchStart = (event: React.TouchEvent<HTMLDivElement>) => {
113+
isScroll.current = true
111114
touch.start(event)
112115
setStartY(touch.deltaY.current)
113116
setStartTime(Date.now())
@@ -134,6 +137,7 @@ const InternalPickerRoller: ForwardRefRenderFunction<
134137
} else {
135138
handleMove(move, 'end')
136139
}
140+
isScroll.current = false
137141
setTimeout(() => {
138142
touch.reset()
139143
}, 0)
@@ -245,6 +249,12 @@ const InternalPickerRoller: ForwardRefRenderFunction<
245249
handleTouchEnd,
246250
])
247251

252+
const onTransitionEnd = () => {
253+
if (!isScroll.current) {
254+
stopMomentumScroll()
255+
}
256+
}
257+
248258
return (
249259
<View className="nut-pickerview-list" ref={pickerRollerRef}>
250260
<View
@@ -257,7 +267,7 @@ const InternalPickerRoller: ForwardRefRenderFunction<
257267
id={`${classPrefix}-${uuid}`}
258268
ref={rollerRef}
259269
style={threeDimensional ? touchRollerStyle() : touchTiledStyle()}
260-
onTransitionEnd={stopMomentumScroll}
270+
onTransitionEnd={onTransitionEnd}
261271
>
262272
{/* 3D 效果 */}
263273
{threeDimensional &&

0 commit comments

Comments
 (0)