@@ -9,14 +9,16 @@ import Animated, {
99 useDerivedValue ,
1010 useSharedValue ,
1111 withDecay ,
12- withTiming ,
12+ withSpring ,
1313} from 'react-native-reanimated' ;
1414import { useSafeAreaInsets } from 'react-native-safe-area-context' ;
1515import { PortalHost } from 'react-native-teleport' ;
1616
1717import { closeOverlay , useOverlayController } from '../../state-store' ;
1818import { finalizeCloseOverlay } from '../../state-store' ;
1919
20+ const DURATION = 300 ;
21+
2022export const MessageOverlayHostLayer = ( ) => {
2123 const { messageH, topH, bottomH, id, closing } = useOverlayController ( ) ;
2224 const insets = useSafeAreaInsets ( ) ;
@@ -39,7 +41,11 @@ export const MessageOverlayHostLayer = () => {
3941
4042 useEffect ( ( ) => {
4143 const target = isActive && ! closing ? 1 : 0 ;
42- backdrop . value = withTiming ( target , { duration : 150 } ) ;
44+ backdrop . value = withSpring ( target , { duration : DURATION + target * 100 } , ( finished ) => {
45+ if ( finished && closing ) {
46+ runOnJS ( finalizeCloseOverlay ) ( ) ;
47+ }
48+ } ) ;
4349 } , [ isActive , closing , backdrop ] ) ;
4450
4551 const backdropStyle = useAnimatedStyle ( ( ) => ( {
@@ -112,7 +118,7 @@ export const MessageOverlayHostLayer = () => {
112118 const closeCompStyle = useAnimatedStyle ( ( ) => {
113119 const target = closing ? - scrollAtClose . value : 0 ;
114120 return {
115- transform : [ { translateY : withTiming ( target , { duration : 150 } ) } ] ,
121+ transform : [ { translateY : withSpring ( target , { duration : DURATION } ) } ] ,
116122 } ;
117123 } , [ closing ] ) ;
118124
@@ -130,7 +136,10 @@ export const MessageOverlayHostLayer = () => {
130136 const topItemTranslateStyle = useAnimatedStyle ( ( ) => {
131137 const target = isActive ? ( closing ? 0 : shiftY . value ) : 0 ;
132138 return {
133- transform : [ { scale : backdrop . value } , { translateY : withTiming ( target , { duration : 150 } ) } ] ,
139+ transform : [
140+ { scale : backdrop . value } ,
141+ { translateY : withSpring ( target , { duration : DURATION } ) } ,
142+ ] ,
134143 } ;
135144 } , [ isActive , closing ] ) ;
136145
@@ -148,7 +157,10 @@ export const MessageOverlayHostLayer = () => {
148157 const bottomItemTranslateStyle = useAnimatedStyle ( ( ) => {
149158 const target = isActive ? ( closing ? 0 : shiftY . value ) : 0 ;
150159 return {
151- transform : [ { scale : backdrop . value } , { translateY : withTiming ( target , { duration : 150 } ) } ] ,
160+ transform : [
161+ { scale : backdrop . value } ,
162+ { translateY : withSpring ( target , { duration : DURATION } ) } ,
163+ ] ,
152164 } ;
153165 } , [ isActive , closing ] ) ;
154166
@@ -169,11 +181,7 @@ export const MessageOverlayHostLayer = () => {
169181 return {
170182 transform : [
171183 {
172- translateY : withTiming ( target , { duration : 150 } , ( finished ) => {
173- if ( finished && closing ) {
174- runOnJS ( finalizeCloseOverlay ) ( ) ;
175- }
176- } ) ,
184+ translateY : withSpring ( target , { duration : DURATION } ) ,
177185 } ,
178186 ] ,
179187 } ;
0 commit comments