Skip to content

Commit 4511ab1

Browse files
committed
fix: worklet issue
1 parent 7309488 commit 4511ab1

File tree

1 file changed

+36
-32
lines changed

1 file changed

+36
-32
lines changed

package/src/contexts/overlayContext/MessageOverlayHostLayer.tsx

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect } from 'react';
1+
import React, { useEffect, useMemo } from 'react';
22
import { Platform, Pressable, StyleSheet, useWindowDimensions, View } from 'react-native';
33
import { Gesture, GestureDetector } from 'react-native-gesture-handler';
44
import Animated, {
@@ -187,37 +187,41 @@ export const MessageOverlayHostLayer = () => {
187187
};
188188
}, [isActive, closing]);
189189

190-
const tap = Gesture.Tap()
191-
.onTouchesDown((e, state) => {
192-
const t = e.allTouches[0];
193-
if (!t) return;
194-
195-
const x = t.x;
196-
const y = t.y;
197-
198-
const messageYShift = messageShiftY.value; // overlay shift for top + message
199-
const bottomYShift = bottomShiftY.value; // overlay shift for bottom
200-
const top = topH.value;
201-
if (top) {
202-
const topY = top.y + messageYShift;
203-
if (x >= top.x && x <= top.x + top.w && y >= topY && y <= topY + top.h) {
204-
state.fail();
205-
return;
206-
}
207-
}
208-
209-
const bot = bottomH.value;
210-
if (bot) {
211-
const botY = bot.y + bottomYShift;
212-
if (x >= bot.x && x <= bot.x + bot.w && y >= botY && y <= botY + bot.h) {
213-
state.fail();
214-
return;
215-
}
216-
}
217-
})
218-
.onEnd(() => {
219-
runOnJS(closeOverlay)();
220-
});
190+
const tap = useMemo(
191+
() =>
192+
Gesture.Tap()
193+
.onTouchesDown((e, state) => {
194+
const t = e.allTouches[0];
195+
if (!t || !topH || !bottomH) return;
196+
197+
const x = t.x;
198+
const y = t.y;
199+
200+
const messageYShift = messageShiftY.value; // overlay shift for top + message
201+
const bottomYShift = bottomShiftY.value; // overlay shift for bottom
202+
const top = topH.value;
203+
if (top) {
204+
const topY = top.y + messageYShift;
205+
if (x >= top.x && x <= top.x + top.w && y >= topY && y <= topY + top.h) {
206+
state.fail();
207+
return;
208+
}
209+
}
210+
211+
const bot = bottomH.value;
212+
if (bot) {
213+
const botY = bot.y + bottomYShift;
214+
if (x >= bot.x && x <= bot.x + bot.w && y >= botY && y <= botY + bot.h) {
215+
state.fail();
216+
return;
217+
}
218+
}
219+
})
220+
.onEnd(() => {
221+
runOnJS(closeOverlay)();
222+
}),
223+
[bottomH, bottomShiftY, messageShiftY, topH],
224+
);
221225

222226
return (
223227
<GestureDetector gesture={tap}>

0 commit comments

Comments
 (0)