|
1 | | -import React, { useEffect } from 'react'; |
| 1 | +import React, { useEffect, useMemo } from 'react'; |
2 | 2 | import { Platform, Pressable, StyleSheet, useWindowDimensions, View } from 'react-native'; |
3 | 3 | import { Gesture, GestureDetector } from 'react-native-gesture-handler'; |
4 | 4 | import Animated, { |
@@ -187,37 +187,41 @@ export const MessageOverlayHostLayer = () => { |
187 | 187 | }; |
188 | 188 | }, [isActive, closing]); |
189 | 189 |
|
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 | + ); |
221 | 225 |
|
222 | 226 | return ( |
223 | 227 | <GestureDetector gesture={tap}> |
|
0 commit comments