11import { logger } from '@sentry/core' ;
22import * as React from 'react' ;
3- import { Modal , View } from 'react-native' ;
3+ import { Animated , Modal , View } from 'react-native' ;
44
55import { FeedbackForm } from './FeedbackForm' ;
6- import defaultStyles from './FeedbackForm.styles' ;
6+ import { modalBackground , modalSheetContainer , modalWrapper } from './FeedbackForm.styles' ;
77import type { FeedbackFormStyles } from './FeedbackForm.types' ;
88import { getFeedbackOptions } from './integration' ;
99import { isModalSupported } from './utils' ;
@@ -40,16 +40,37 @@ interface FeedbackFormProviderProps {
4040 styles ?: FeedbackFormStyles ;
4141}
4242
43+ interface FeedbackFormProviderState {
44+ isVisible : boolean ;
45+ backgroundOpacity : Animated . Value ;
46+ }
47+
4348class FeedbackFormProvider extends React . Component < FeedbackFormProviderProps > {
44- public state = {
49+ public state : FeedbackFormProviderState = {
4550 isVisible : false ,
51+ backgroundOpacity : new Animated . Value ( 0 ) ,
4652 } ;
4753
4854 public constructor ( props : FeedbackFormProviderProps ) {
4955 super ( props ) ;
5056 FeedbackFormManager . initialize ( this . _setVisibilityFunction ) ;
5157 }
5258
59+ /**
60+ * Animates the background opacity when the modal is shown.
61+ */
62+ public componentDidUpdate ( _prevProps : any , prevState : FeedbackFormProviderState ) : void {
63+ if ( ! prevState . isVisible && this . state . isVisible ) {
64+ Animated . timing ( this . state . backgroundOpacity , {
65+ toValue : 1 ,
66+ duration : 300 ,
67+ useNativeDriver : true ,
68+ } ) . start ( ) ;
69+ } else if ( prevState . isVisible && ! this . state . isVisible ) {
70+ this . state . backgroundOpacity . setValue ( 0 ) ;
71+ }
72+ }
73+
5374 /**
5475 * Renders the feedback form modal.
5576 */
@@ -59,27 +80,31 @@ class FeedbackFormProvider extends React.Component<FeedbackFormProviderProps> {
5980 return < > { this . props . children } </ > ;
6081 }
6182
62- const { isVisible } = this . state ;
63- const styles : FeedbackFormStyles = { ...defaultStyles , ...this . props . styles } ;
83+ const { isVisible, backgroundOpacity } = this . state ;
84+
85+ const backgroundColor = backgroundOpacity . interpolate ( {
86+ inputRange : [ 0 , 1 ] ,
87+ outputRange : [ 'rgba(0, 0, 0, 0)' , 'rgba(0, 0, 0, 0.9)' ] ,
88+ } ) ;
6489
6590 // Wrapping the `Modal` component in a `View` component is necessary to avoid
6691 // issues like https://github.com/software-mansion/react-native-reanimated/issues/6035
6792 return (
6893 < >
6994 { this . props . children }
7095 { isVisible && (
71- < View >
96+ < Animated . View style = { [ modalWrapper , { backgroundColor } ] } >
7297 < Modal visible = { isVisible } transparent animationType = "slide" onRequestClose = { this . _handleClose } testID = "feedback-form-modal" >
73- < View style = { styles . modalBackground } >
74- < View style = { styles . modalSheetContainer } >
98+ < View style = { modalBackground } >
99+ < View style = { modalSheetContainer } >
75100 < FeedbackForm { ...getFeedbackOptions ( ) }
76101 onFormClose = { this . _handleClose }
77102 onFormSubmitted = { this . _handleClose }
78103 />
79104 </ View >
80105 </ View >
81106 </ Modal >
82- </ View >
107+ </ Animated . View >
83108 ) }
84109 </ >
85110 ) ;
0 commit comments