Skip to content

Commit 441370a

Browse files
authored
fix: 修改小程序下自动吸边计算逻辑&&解决部分小程序写法不支持问题 (#2855)
1 parent 4713330 commit 441370a

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

src/packages/drag/demos/taro/demo4.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const Demo4 = () => {
1111
return screenWidth - 300 - 9
1212
}
1313
const bottom = () => {
14-
return windowHeight - 501 - 57
14+
return windowHeight - 559
1515
}
1616
return (
1717
<>

src/packages/drag/drag.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
display: inline-flex;
1111
width: fit-content;
1212
height: fit-content;
13+
touch-action: none;
1314
}
1415
}

src/packages/drag/drag.taro.tsx

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { FunctionComponent, useState, useEffect, useRef } from 'react'
2-
import { getSystemInfoSync, createSelectorQuery } from '@tarojs/taro'
2+
import { getSystemInfoSync } from '@tarojs/taro'
33
import { BasicComponent, ComponentDefaults } from '@/utils/typings'
44
import { getRectByTaro } from '@/utils/get-rect-by-taro'
55
import { DragState } from './drag'
@@ -66,22 +66,22 @@ export const Drag: FunctionComponent<
6666
const { top, left, bottom, right } = boundary
6767
const { screenWidth, windowHeight } = getSystemInfoSync()
6868

69-
const { width, height } = await getRectByTaro(dragRef.current)
70-
dragRef.current?.getBoundingClientRect()
71-
createSelectorQuery()
72-
.select(`.${className}`)
73-
.boundingClientRect((rec: any) => {
74-
setBoundaryState({
75-
top: -rec.top + top,
76-
left: -rec.left + left,
77-
bottom: windowHeight - rec.top - bottom - Math.ceil(height),
78-
right: screenWidth - rec.left - right - Math.ceil(width),
79-
})
69+
const {
70+
width,
71+
height,
72+
top: dragTop,
73+
left: dragLeft,
74+
} = await getRectByTaro(dragRef.current)
8075

81-
middleLine.current =
82-
screenWidth - rec.width - rec.left - (screenWidth - rec.width) / 2
83-
})
84-
.exec()
76+
setBoundaryState({
77+
top: -dragTop + top,
78+
left: -dragLeft + left,
79+
bottom: windowHeight - dragTop - bottom - Math.ceil(height),
80+
right: screenWidth - dragLeft - right - Math.ceil(width),
81+
})
82+
83+
middleLine.current =
84+
screenWidth - width - dragLeft - (screenWidth - width) / 2
8585
}
8686
}
8787

0 commit comments

Comments
 (0)