1- import React , { useEffect , useMemo } from 'react' ;
1+ import React , { useEffect } from 'react' ;
22import { Platform , Pressable , StyleSheet , useWindowDimensions , View } from 'react-native' ;
33import { Gesture , GestureDetector } from 'react-native-gesture-handler' ;
44import Animated , {
5- cancelAnimation ,
65 clamp ,
76 runOnJS ,
87 useAnimatedStyle ,
98 useDerivedValue ,
109 useSharedValue ,
11- withDecay ,
1210 withSpring ,
1311} from 'react-native-reanimated' ;
1412import { useSafeAreaInsets } from 'react-native-safe-area-context' ;
@@ -124,70 +122,13 @@ export const MessageOverlayHostLayer = () => {
124122 return solvedBottomTop - bottomH . value . y ;
125123 } ) ;
126124
127- const viewportH = useSharedValue ( screenH ) ;
128- useEffect ( ( ) => {
129- viewportH . value = screenH ;
130- } , [ screenH , viewportH ] ) ;
131-
132- const scrollY = useSharedValue ( 0 ) ;
133- const initialScrollOffset = useSharedValue ( 0 ) ;
134-
135- useEffect ( ( ) => {
136- if ( isActive ) scrollY . value = 0 ;
137- } , [ isActive , scrollY ] ) ;
138-
139- const contentH = useDerivedValue ( ( ) =>
140- topH . value && bottomH . value && messageH . value
141- ? Math . max (
142- screenH ,
143- topH . value . h + messageH . value . h + bottomH . value . h + topInset + bottomInset + 20 ,
144- )
145- : 0 ,
146- ) ;
147-
148- const maxScroll = useDerivedValue ( ( ) => Math . max ( 0 , contentH . value - viewportH . value ) ) ;
149-
150- const pan = useMemo (
151- ( ) =>
152- Gesture . Pan ( )
153- . activeOffsetY ( [ - 8 , 8 ] )
154- . failOffsetX ( [ - 12 , 12 ] )
155- . onBegin ( ( ) => {
156- cancelAnimation ( scrollY ) ;
157- initialScrollOffset . value = scrollY . value ;
158- } )
159- . onUpdate ( ( e ) => {
160- scrollY . value = clamp ( initialScrollOffset . value + e . translationY , 0 , maxScroll . value ) ;
161- } )
162- . onEnd ( ( e ) => {
163- scrollY . value = withDecay ( { clamp : [ 0 , maxScroll . value ] , velocity : e . velocityY } ) ;
164- } ) ,
165- [ initialScrollOffset , maxScroll , scrollY ] ,
166- ) ;
167-
168- const scrollAtClose = useSharedValue ( 0 ) ;
169-
170- useDerivedValue ( ( ) => {
171- if ( closing ) {
172- scrollAtClose . value = scrollY . value ;
173- cancelAnimation ( scrollY ) ;
174- }
175- } , [ closing ] ) ;
176-
177- const closeCompStyle = useAnimatedStyle ( ( ) => {
178- const target = closing ? - scrollAtClose . value : 0 ;
179- return {
180- transform : [ { translateY : withSpring ( target , { duration : DURATION } ) } ] ,
181- } ;
182- } , [ closing ] ) ;
183-
184125 const topItemStyle = useAnimatedStyle ( ( ) => {
185126 if ( ! topH . value ) return { height : 0 } ;
186127 return {
187128 height : topH . value . h ,
188129 left : topH . value . x ,
189130 position : 'absolute' ,
190- top : topH . value . y + scrollY . value ,
131+ top : topH . value . y ,
191132 width : topH . value . w ,
192133 } ;
193134 } ) ;
@@ -208,7 +149,7 @@ export const MessageOverlayHostLayer = () => {
208149 height : bottomH . value . h ,
209150 left : bottomH . value . x ,
210151 position : 'absolute' ,
211- top : bottomH . value . y + scrollY . value ,
152+ top : bottomH . value . y ,
212153 width : bottomH . value . w ,
213154 } ;
214155 } ) ;
@@ -229,7 +170,7 @@ export const MessageOverlayHostLayer = () => {
229170 height : messageH . value . h ,
230171 left : messageH . value . x ,
231172 position : 'absolute' ,
232- top : messageH . value . y + scrollY . value , // layout scroll (no special msg-only compensation)
173+ top : messageH . value . y ,
233174 width : messageH . value . w ,
234175 } ;
235176 } ) ;
@@ -246,10 +187,6 @@ export const MessageOverlayHostLayer = () => {
246187 } ;
247188 } , [ isActive , closing ] ) ;
248189
249- const contentStyle = useAnimatedStyle ( ( ) => ( {
250- height : contentH . value ,
251- } ) ) ;
252-
253190 const tap = Gesture . Tap ( )
254191 . onTouchesDown ( ( e , state ) => {
255192 const t = e . allTouches [ 0 ] ;
@@ -260,13 +197,9 @@ export const MessageOverlayHostLayer = () => {
260197
261198 const messageYShift = messageShiftY . value ; // overlay shift for top + message
262199 const bottomYShift = bottomShiftY . value ; // overlay shift for bottom
263- const yParent = scrollY . value ; // parent content
264-
265200 const top = topH . value ;
266201 if ( top ) {
267- // top rectangle's final screen Y
268- // base layout Y + overlay shift + parent scroll transform
269- const topY = top . y + yParent + messageYShift ;
202+ const topY = top . y + messageYShift ;
270203 if ( x >= top . x && x <= top . x + top . w && y >= topY && y <= topY + top . h ) {
271204 state . fail ( ) ;
272205 return ;
@@ -275,9 +208,7 @@ export const MessageOverlayHostLayer = () => {
275208
276209 const bot = bottomH . value ;
277210 if ( bot ) {
278- // bottom rectangle's final screen Y
279- // base layout Y + overlay shift + parent scroll transform
280- const botY = bot . y + yParent + bottomYShift ;
211+ const botY = bot . y + bottomYShift ;
281212 if ( x >= bot . x && x <= bot . x + bot . w && y >= botY && y <= botY + bot . h ) {
282213 state . fail ( ) ;
283214 return ;
@@ -289,7 +220,7 @@ export const MessageOverlayHostLayer = () => {
289220 } ) ;
290221
291222 return (
292- < GestureDetector gesture = { Gesture . Exclusive ( pan , tap ) } >
223+ < GestureDetector gesture = { tap } >
293224 < View pointerEvents = 'box-none' style = { StyleSheet . absoluteFill } >
294225 { isActive ? (
295226 < Animated . View
@@ -298,7 +229,7 @@ export const MessageOverlayHostLayer = () => {
298229 />
299230 ) : null }
300231
301- < Animated . View style = { [ contentStyle , closeCompStyle ] } >
232+ < View pointerEvents = 'box-none' style = { StyleSheet . absoluteFill } >
302233 { isActive ? (
303234 < Pressable onPress = { closeOverlay } style = { StyleSheet . absoluteFillObject } />
304235 ) : null }
@@ -314,7 +245,7 @@ export const MessageOverlayHostLayer = () => {
314245 < Animated . View style = { [ bottomItemStyle , bottomItemTranslateStyle , styles . shadow3 ] } >
315246 < PortalHost name = 'bottom-item' style = { StyleSheet . absoluteFillObject } />
316247 </ Animated . View >
317- </ Animated . View >
248+ </ View >
318249 </ View >
319250 </ GestureDetector >
320251 ) ;
0 commit comments