<pan-gesture-handler worklet:ongesture="handlePan" style="flex-shrink: 0;">
<view class="comment-header" @touchend="handleTouchEnd">
<view class="comment-handler"></view>
留言
</view>
</pan-gesture-handler>
handlePan(gestureEvent) {
'worklet'
console.log(2134231312312343234234234234);
// 滚动半屏的位置
if (gestureEvent.state === GestureState.ACTIVE) {
// deltaY < 0,往上滑动
this.upward.value = gestureEvent.deltaY < 0
// 当前半屏位置
const curPosition = this.transY.value
// 只能在 [statusBarHeight, screenHeight] 之间移动
const destination = clamp(curPosition + gestureEvent.deltaY, statusBarHeight, screenHeight)
if (curPosition === destination) return
// 改变 transY,来改变半屏的位置
this.transY.value = destination
}
if (gestureEvent.state === GestureState.END || gestureEvent.state === GestureState.CANCELLED) {
if (this.transY.value <= screenHeight / 2) {
// 在上面的位置
if (this.upward.value) {
this.scrollTo(statusBarHeight)
} else {
this.scrollTo(screenHeight / 2)
}
} else if (this.transY.value > screenHeight / 2 && this.transY.value <= this.initTransY.value) {
// 在中间位置的时候
if (this.upward.value) {
this.scrollTo(screenHeight / 2)
} else {
this.scrollTo(this.initTransY.value)
}
} else {
// 在最下面的位置
this.scrollTo(this.initTransY.value)
}
}
},
1 个回复
BoneTM
参考
https://ask.dcloud.net.cn/article/41063