|
1 | 1 | import React, { FunctionComponent, useState, useEffect, useRef } from 'react' |
2 | 2 | import { getSystemInfoSync, createSelectorQuery } from '@tarojs/taro' |
3 | 3 | import { BasicComponent, ComponentDefaults } from '@/utils/typings' |
| 4 | +import { getRectByTaro } from '@/utils/get-rect-by-taro' |
4 | 5 |
|
5 | 6 | export interface DragProps extends BasicComponent { |
6 | 7 | attract: boolean |
@@ -45,20 +46,24 @@ export const Drag: FunctionComponent< |
45 | 46 | const translateY = useRef(0) |
46 | 47 | const middleLine = useRef(0) |
47 | 48 |
|
48 | | - const getInfo = () => { |
| 49 | + const getInfo = async () => { |
49 | 50 | const el = myDrag.current |
50 | 51 | if (el) { |
51 | 52 | const { top, left, bottom, right } = boundary |
52 | 53 | const { screenWidth, windowHeight } = getSystemInfoSync() |
53 | 54 |
|
| 55 | + const { width, height } = await getRectByTaro(dragRef.current) |
| 56 | + dragRef.current && dragRef.current.getBoundingClientRect() |
| 57 | + |
| 58 | + console.log('width', width, 'height', height) |
54 | 59 | createSelectorQuery() |
55 | 60 | .select(`.${className}`) |
56 | 61 | .boundingClientRect((rec: any) => { |
57 | 62 | setBoundaryState({ |
58 | 63 | top: -rec.top + top, |
59 | 64 | left: -rec.left + left, |
60 | | - bottom: windowHeight - rec.height - rec.top - bottom, |
61 | | - right: screenWidth - rec.width - rec.left - right, |
| 65 | + bottom: windowHeight - rec.top - bottom - Math.ceil(height), |
| 66 | + right: screenWidth - rec.left - right - Math.ceil(width), |
62 | 67 | }) |
63 | 68 |
|
64 | 69 | middleLine.current = |
@@ -135,6 +140,7 @@ export const Drag: FunctionComponent< |
135 | 140 | ref={myDrag} |
136 | 141 | > |
137 | 142 | <div |
| 143 | + className={`${classPrefix}-inner`} |
138 | 144 | onTouchStart={(event) => touchStart(event)} |
139 | 145 | ref={dragRef} |
140 | 146 | onTouchMove={touchMove} |
|
0 commit comments