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 } }