From 002f570961d2f64a948376b875a08e7db5c48e2c Mon Sep 17 00:00:00 2001 From: songchenglin3 <353833373@qq.com> Date: Thu, 12 Dec 2024 09:57:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E5=B0=8F=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E4=B8=8B=E8=87=AA=E5=8A=A8=E5=90=B8=E8=BE=B9=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E9=80=BB=E8=BE=91&&=E8=A7=A3=E5=86=B3=E9=83=A8?= =?UTF-8?q?=E5=88=86=E5=B0=8F=E7=A8=8B=E5=BA=8F=E5=86=99=E6=B3=95=E4=B8=8D?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/packages/drag/demos/taro/demo4.tsx | 2 +- src/packages/drag/drag.scss | 1 + src/packages/drag/drag.taro.tsx | 32 +++++++++++++------------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/packages/drag/demos/taro/demo4.tsx b/src/packages/drag/demos/taro/demo4.tsx index 7ac2923b44..b20c513f29 100644 --- a/src/packages/drag/demos/taro/demo4.tsx +++ b/src/packages/drag/demos/taro/demo4.tsx @@ -11,7 +11,7 @@ const Demo4 = () => { return screenWidth - 300 - 9 } const bottom = () => { - return windowHeight - 501 - 57 + return windowHeight - 559 } return ( <> diff --git a/src/packages/drag/drag.scss b/src/packages/drag/drag.scss index ec167762d3..681be86960 100644 --- a/src/packages/drag/drag.scss +++ b/src/packages/drag/drag.scss @@ -10,5 +10,6 @@ display: inline-flex; width: fit-content; height: fit-content; + touch-action: none; } } diff --git a/src/packages/drag/drag.taro.tsx b/src/packages/drag/drag.taro.tsx index 39a7f91b62..087dcdb86e 100644 --- a/src/packages/drag/drag.taro.tsx +++ b/src/packages/drag/drag.taro.tsx @@ -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' @@ -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 } }