Skip to content

Commit 0b0b482

Browse files
author
Andrzej Antoni Kwaśniewski
committed
fix web!!!!
1 parent 5ef3310 commit 0b0b482

2 files changed

Lines changed: 27 additions & 14 deletions

File tree

packages/react-native-gesture-handler/src/v3/components/Pressable/utils.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { Insets } from 'react-native';
1+
import { Insets, Platform } from 'react-native';
22
import {
3-
FullPressableDimensions,
43
InnerPressableEvent,
54
PressableEvent,
5+
FullPressableDimensions,
66
} from './PressableProps';
77
import {
88
GestureTouchEvent,
@@ -62,12 +62,17 @@ const isTouchWithinInset = (
6262
inset: Insets,
6363
touch?: InnerPressableEvent
6464
) =>
65-
(touch?.locationX ?? 0) <
66-
(inset.right ?? 0) + dimensions.width + dimensions.x &&
67-
(touch?.locationY ?? 0) <
68-
(inset.bottom ?? 0) + dimensions.height + dimensions.y &&
69-
(touch?.locationX ?? 0) > -(inset.left ?? 0) + dimensions.x &&
70-
(touch?.locationY ?? 0) > -(inset.top ?? 0) + dimensions.y;
65+
Platform.OS === 'ios'
66+
? (touch?.locationX ?? 0) <
67+
(inset.right ?? 0) + dimensions.width + dimensions.x &&
68+
(touch?.locationY ?? 0) <
69+
(inset.bottom ?? 0) + dimensions.height + dimensions.y &&
70+
(touch?.locationX ?? 0) > -(inset.left ?? 0) + dimensions.x &&
71+
(touch?.locationY ?? 0) > -(inset.top ?? 0) + dimensions.y
72+
: (touch?.locationX ?? 0) < (inset.right ?? 0) + dimensions.width &&
73+
(touch?.locationY ?? 0) < (inset.bottom ?? 0) + dimensions.height &&
74+
(touch?.locationX ?? 0) > -(inset.left ?? 0) &&
75+
(touch?.locationY ?? 0) > -(inset.top ?? 0);
7176

7277
const gestureToPressableEvent = (
7378
event: HoverGestureEvent | LongPressGestureEvent

packages/react-native-gesture-handler/src/v3/detectors/HostGestureDetector.web.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { Ref, RefObject, useEffect, useRef } from 'react';
1+
import React, { Ref, RefObject, useEffect, useMemo, useRef } from 'react';
22
import RNGestureHandlerModule from '../../RNGestureHandlerModule.web';
33
import { ActionType } from '../../ActionType';
44
import { PropsRef } from '../../web/interfaces';
@@ -27,6 +27,8 @@ const EMPTY_HANDLERS = new Set<number>();
2727
const HostGestureDetector = (props: GestureHandlerDetectorProps) => {
2828
const { handlerTags, children } = props;
2929

30+
const handlerTagsSet = useMemo(() => new Set(handlerTags), [...handlerTags]);
31+
3032
const viewRef = useRef<Element>(null);
3133
const propsRef = useRef<GestureHandlerDetectorProps>(props);
3234
const attachedHandlers = useRef<Set<number>>(new Set<number>());
@@ -110,25 +112,31 @@ const HostGestureDetector = (props: GestureHandlerDetectorProps) => {
110112
tagMessage('Detector expected to have exactly one child element')
111113
);
112114
}
115+
}, [children]);
113116

114-
const currentHandlerTags = new Set(handlerTags);
115-
detachHandlers(currentHandlerTags, attachedHandlers.current);
117+
useEffect(() => {
118+
if (React.Children.count(children) !== 1) {
119+
throw new Error(
120+
tagMessage('Detector expected to have exactly one child element')
121+
);
122+
}
123+
124+
detachHandlers(handlerTagsSet, attachedHandlers.current);
116125

117126
attachHandlers(
118127
viewRef,
119128
propsRef,
120-
currentHandlerTags,
129+
handlerTagsSet,
121130
attachedHandlers.current,
122131
ActionType.NATIVE_DETECTOR
123132
);
124-
125133
return () => {
126134
detachHandlers(EMPTY_HANDLERS, attachedHandlers.current);
127135
attachedVirtualHandlers?.current.forEach((childHandlerTags) => {
128136
detachHandlers(EMPTY_HANDLERS, childHandlerTags);
129137
});
130138
};
131-
}, [handlerTags, children]);
139+
}, [handlerTagsSet, viewRef]);
132140

133141
useEffect(() => {
134142
const virtualChildrenToDetach: Set<number> = new Set(

0 commit comments

Comments
 (0)