Skip to content

Commit

Permalink
fix: 修改小程序下自动吸边计算逻辑&&解决部分小程序写法不支持问题
Browse files Browse the repository at this point in the history
  • Loading branch information
irisSong committed Dec 12, 2024
1 parent 402e32f commit 002f570
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/packages/drag/demos/taro/demo4.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const Demo4 = () => {
return screenWidth - 300 - 9
}
const bottom = () => {
return windowHeight - 501 - 57
return windowHeight - 559
}
return (
<>
Expand Down
1 change: 1 addition & 0 deletions src/packages/drag/drag.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
display: inline-flex;
width: fit-content;
height: fit-content;
touch-action: none;
}
}
32 changes: 16 additions & 16 deletions src/packages/drag/drag.taro.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { FunctionComponent, useState, useEffect, useRef } from 'react'
import { getSystemInfoSync, createSelectorQuery } from '@tarojs/taro'
import { getSystemInfoSync } from '@tarojs/taro'
import { BasicComponent, ComponentDefaults } from '@/utils/typings'
import { getRectByTaro } from '@/utils/get-rect-by-taro'
import { DragState } from './drag'
Expand Down Expand Up @@ -66,22 +66,22 @@ export const Drag: FunctionComponent<
const { top, left, bottom, right } = boundary
const { screenWidth, windowHeight } = getSystemInfoSync()

const { width, height } = await getRectByTaro(dragRef.current)
dragRef.current?.getBoundingClientRect()
createSelectorQuery()
.select(`.${className}`)
.boundingClientRect((rec: any) => {
setBoundaryState({
top: -rec.top + top,
left: -rec.left + left,
bottom: windowHeight - rec.top - bottom - Math.ceil(height),
right: screenWidth - rec.left - right - Math.ceil(width),
})
const {
width,
height,
top: dragTop,
left: dragLeft,
} = await getRectByTaro(dragRef.current)

middleLine.current =
screenWidth - rec.width - rec.left - (screenWidth - rec.width) / 2
})
.exec()
setBoundaryState({
top: -dragTop + top,
left: -dragLeft + left,
bottom: windowHeight - dragTop - bottom - Math.ceil(height),
right: screenWidth - dragLeft - right - Math.ceil(width),
})

middleLine.current =
screenWidth - width - dragLeft - (screenWidth - width) / 2
}
}

Expand Down

0 comments on commit 002f570

Please sign in to comment.