|
1 | 1 | import React, { FunctionComponent, useState, useEffect, useRef } from 'react'
|
2 |
| -import { getSystemInfoSync, createSelectorQuery } from '@tarojs/taro' |
| 2 | +import { getSystemInfoSync } from '@tarojs/taro' |
3 | 3 | import { BasicComponent, ComponentDefaults } from '@/utils/typings'
|
4 | 4 | import { getRectByTaro } from '@/utils/get-rect-by-taro'
|
5 | 5 | import { DragState } from './drag'
|
@@ -66,22 +66,22 @@ export const Drag: FunctionComponent<
|
66 | 66 | const { top, left, bottom, right } = boundary
|
67 | 67 | const { screenWidth, windowHeight } = getSystemInfoSync()
|
68 | 68 |
|
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) |
80 | 75 |
|
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 |
85 | 85 | }
|
86 | 86 | }
|
87 | 87 |
|
|
0 commit comments