From e2b05116959828f8dc039ecc344d0b31843084f6 Mon Sep 17 00:00:00 2001 From: lareinayanyu Date: Tue, 5 Nov 2024 14:19:06 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E4=BF=AE=E6=94=B9injectCatchEvent?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/react/getInnerListeners.ts | 19 -------------- .../components/react/mpx-movable-view.tsx | 25 ++++++++++++++++--- .../lib/runtime/components/react/utils.tsx | 4 +-- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/packages/webpack-plugin/lib/runtime/components/react/getInnerListeners.ts b/packages/webpack-plugin/lib/runtime/components/react/getInnerListeners.ts index 355703a8b..ed7218458 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/getInnerListeners.ts +++ b/packages/webpack-plugin/lib/runtime/components/react/getInnerListeners.ts @@ -105,25 +105,6 @@ export const getCustomEvent = ( } } -export const injectCatchEvent = (props: Record) => { - const eventHandlers: Record = {} - const catchEventList = [ - { name: 'onTouchStart', value: ['catchtouchstart'] }, - { name: 'onTouchMove', value: ['catchtouchmove', 'catchvtouchmove', 'catchvhouchmove'] }, - { name: 'onTouchEnd', value: ['catchtouchend'] } - ] - catchEventList.forEach(event => { - event.value.forEach(name => { - if (props[name] && !eventHandlers[event.name]) { - eventHandlers[event.name] = (e: NativeSyntheticEvent) => { - e.stopPropagation() - } - } - }) - }) - return eventHandlers -} - const useInnerProps = ( props: Props = {}, additionalProps: AdditionalProps = {}, diff --git a/packages/webpack-plugin/lib/runtime/components/react/mpx-movable-view.tsx b/packages/webpack-plugin/lib/runtime/components/react/mpx-movable-view.tsx index 7095afcf0..d132eaee0 100644 --- a/packages/webpack-plugin/lib/runtime/components/react/mpx-movable-view.tsx +++ b/packages/webpack-plugin/lib/runtime/components/react/mpx-movable-view.tsx @@ -19,10 +19,10 @@ */ import { useEffect, forwardRef, ReactNode, useContext, useCallback, useRef, useMemo, Ref } from 'react' import { StyleSheet, NativeSyntheticEvent, View, LayoutChangeEvent } from 'react-native' -import { getCustomEvent, injectCatchEvent } from './getInnerListeners' +import { getCustomEvent } from './getInnerListeners' import useNodesRef, { HandlerRef } from './useNodesRef' import { MovableAreaContext } from './context' -import { useTransformStyle, splitProps, splitStyle, DEFAULT_UNLAY_STYLE, wrapChildren, GestureHandler, flatGesture } from './utils' +import { useTransformStyle, splitProps, splitStyle, HIDDEN_STYLE, wrapChildren, GestureHandler, flatGesture } from './utils' import { GestureDetector, Gesture, GestureTouchEvent, GestureStateChangeEvent, PanGestureHandlerEventPayload, PanGesture } from 'react-native-gesture-handler' import Animated, { useSharedValue, @@ -482,8 +482,27 @@ const _MovableView = forwardRef, MovableViewP } }) + const injectCatchEvent = (props: Record) => { + const eventHandlers: Record = {} + const catchEventList = [ + { name: 'onTouchStart', value: ['catchtouchstart'] }, + { name: 'onTouchMove', value: ['catchtouchmove', 'catchvtouchmove', 'catchhtouchmove'] }, + { name: 'onTouchEnd', value: ['catchtouchend'] } + ] + catchEventList.forEach(event => { + event.value.forEach(name => { + if (props[name] && !eventHandlers[event.name]) { + eventHandlers[event.name] = (e: NativeSyntheticEvent) => { + e.stopPropagation() + } + } + }) + }) + return eventHandlers + } + const catchEventHandlers = injectCatchEvent(props) - const layoutStyle = !hasLayoutRef.current && hasSelfPercent ? DEFAULT_UNLAY_STYLE : {} + const layoutStyle = !hasLayoutRef.current && hasSelfPercent ? HIDDEN_STYLE : {} return ( { const layoutRef = useRef({}) const hasLayoutRef = useRef(false) - const layoutStyle: Record = !hasLayoutRef.current && hasSelfPercent ? DEFAULT_UNLAY_STYLE : {} + const layoutStyle: Record = !hasLayoutRef.current && hasSelfPercent ? HIDDEN_STYLE : {} const layoutProps: Record = {} const enableOffset = props['enable-offset'] if (hasSelfPercent || onLayout || enableOffset) {