Skip to content

Commit

Permalink
fix: x,y位置修正
Browse files Browse the repository at this point in the history
  • Loading branch information
lareinayanyu committed Jan 13, 2025
1 parent 45cd200 commit 7fb6e70
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* ✔ vtouchmove
*/
import { useEffect, forwardRef, ReactNode, useContext, useCallback, useRef, useMemo, createElement } from 'react'
import { StyleSheet, NativeSyntheticEvent, View, LayoutChangeEvent } from 'react-native'
import { StyleSheet, View, LayoutChangeEvent } from 'react-native'
import useInnerProps, { getCustomEvent } from './getInnerListeners'
import useNodesRef, { HandlerRef } from './useNodesRef'
import { MovableAreaContext } from './context'
Expand All @@ -34,6 +34,7 @@ import Animated, {
withSpring
} from 'react-native-reanimated'
import { collectDataset, noop } from '@mpxjs/utils'
import { useNavigation } from '@react-navigation/native'

interface MovableViewProps {
children: ReactNode;
Expand Down Expand Up @@ -126,6 +127,8 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
setHeight
} = useTransformStyle(Object.assign({}, style, styles.container), { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })

const navigation = useNavigation()

const prevSimultaneousHandlersRef = useRef<Array<GestureHandler>>(originSimultaneousHandlers || [])
const prevWaitForHandlersRef = useRef<Array<GestureHandler>>(waitFor || [])
const gestureSwitch = useRef(false)
Expand Down Expand Up @@ -333,25 +336,27 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
setHeight(height || 0)
}
nodeRef.current?.measure((x: number, y: number, width: number, height: number) => {
layoutRef.current = { x, y, width, height, offsetLeft: 0, offsetTop: 0 }
const { y: navigationY = 0 } = navigation?.layout || {}
layoutRef.current = { x, y: y - navigationY, width, height, offsetLeft: 0, offsetTop: 0 }
resetBoundaryAndCheck({ width, height })
})
props.onLayout && props.onLayout(e)
}

const extendEvent = useCallback((e: any, obj?: Record<string, any>) => {
const { y: navigationY = 0 } = navigation?.layout || {}
const touchArr = [e.changedTouches, e.allTouches]
touchArr.forEach(touches => {
touches && touches.forEach((item: { absoluteX: number; absoluteY: number; pageX: number; pageY: number }) => {
item.pageX = item.absoluteX
item.pageY = item.absoluteY
item.pageY = item.absoluteY - navigationY
})
})
Object.assign(e, {
touches: e.allTouches,
detail: {
x: e.changedTouches[0].absoluteX,
y: e.changedTouches[0].absoluteY
y: e.changedTouches[0].absoluteY - navigationY
},
currentTarget: {
id: props.id || '',
Expand Down

0 comments on commit 7fb6e70

Please sign in to comment.