fix: 🐛 修复 FloadingPanel 设置 height 不生效的问题 (#725)

 Closes: #703
This commit is contained in:
不如摸鱼去 2024-11-21 14:37:31 +08:00 committed by GitHub
parent cd20581ca6
commit 3cc18058ae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 10 deletions

View File

@ -45,9 +45,10 @@ const touch = useTouch()
const props = defineProps(floatingPanelProps) const props = defineProps(floatingPanelProps)
const emit = defineEmits(['update:height', 'height-change']) const emit = defineEmits(['update:height', 'height-change'])
const heightValue = ref<number>(props.height)
const DAMP = 0.2 // const DAMP = 0.2 //
let startY: number // let startY: number //
const height = ref<number>(props.height) //
const windowHeight = ref<number>(0) const windowHeight = ref<number>(0)
const dragging = ref<boolean>(false) // const dragging = ref<boolean>(false) //
@ -61,17 +62,22 @@ const anchors = computed(() => (props.anchors.length >= 2 ? props.anchors : [bou
const rootStyle = computed(() => { const rootStyle = computed(() => {
const style: CSSProperties = { const style: CSSProperties = {
height: addUnit(boundary.value.max), height: addUnit(boundary.value.max),
transform: `translateY(calc(100% + ${addUnit(-height.value)}))`, transform: `translateY(calc(100% + ${addUnit(-heightValue.value)}))`,
transition: !dragging.value ? `transform ${props.duration}ms cubic-bezier(0.18, 0.89, 0.32, 1.28)` : 'none' transition: !dragging.value ? `transform ${props.duration}ms cubic-bezier(0.18, 0.89, 0.32, 1.28)` : 'none'
} }
return `${objToStyle(style)};${props.customStyle}` return `${objToStyle(style)};${props.customStyle}`
}) })
const updateHeight = (value: number) => {
heightValue.value = value
emit('update:height', value)
}
const handleTouchStart = (event: TouchEvent) => { const handleTouchStart = (event: TouchEvent) => {
touch.touchStart(event) touch.touchStart(event)
dragging.value = true dragging.value = true
startY = -height.value startY = -heightValue.value
} }
const handleTouchMove = (event: TouchEvent) => { const handleTouchMove = (event: TouchEvent) => {
@ -81,15 +87,15 @@ const handleTouchMove = (event: TouchEvent) => {
} }
touch.touchMove(event) touch.touchMove(event)
const moveY = touch.deltaY.value + startY const moveY = touch.deltaY.value + startY
height.value = -ease(moveY) updateHeight(-ease(moveY))
} }
const handleTouchEnd = () => { const handleTouchEnd = () => {
dragging.value = false dragging.value = false
height.value = closest(anchors.value, height.value) updateHeight(closest(anchors.value, heightValue.value))
if (height.value !== -startY) { if (heightValue.value !== -startY) {
emit('height-change', { height: height.value }) emit('height-change', { height: heightValue.value })
} }
} }
@ -109,16 +115,16 @@ const ease = (y: number) => {
} }
watch( watch(
() => height.value, () => props.height,
(value) => { (value) => {
emit('update:height', value) heightValue.value = value
} }
) )
watch( watch(
boundary, boundary,
() => { () => {
height.value = closest(anchors.value, height.value) updateHeight(closest(anchors.value, heightValue.value))
}, },
{ immediate: true } { immediate: true }
) )

View File

@ -91,6 +91,7 @@ declare module 'vue' {
WdIndexAnchor: typeof import('./components/wd-index-anchor/wd-index-anchor.vue')['default'] WdIndexAnchor: typeof import('./components/wd-index-anchor/wd-index-anchor.vue')['default']
WdText: typeof import('./components/wd-text/wd-text.vue')['default'] WdText: typeof import('./components/wd-text/wd-text.vue')['default']
WdCountTo: typeof import('./components/wd-count-to/wd-count-to.vue')['default'] WdCountTo: typeof import('./components/wd-count-to/wd-count-to.vue')['default']
WdFloatingPanel: typeof import('./components/wd-floating-panel/wd-floating-panel.vue')['default']
} }
} }