Skip to content

Commit ce1de86

Browse files
committed
Animate background color
1 parent d88a599 commit ce1de86

File tree

2 files changed

+63
-9
lines changed

2 files changed

+63
-9
lines changed

packages/core/src/js/feedback/FeedbackForm.styles.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { ViewStyle } from 'react-native';
2+
13
import type { FeedbackFormStyles } from './FeedbackForm.types';
24

35
const PURPLE = 'rgba(88, 74, 192, 1)';
@@ -79,4 +81,31 @@ const defaultStyles: FeedbackFormStyles = {
7981
},
8082
};
8183

84+
export const modalWrapper: ViewStyle = {
85+
position: 'absolute',
86+
top: 0,
87+
left: 0,
88+
right: 0,
89+
bottom: 0,
90+
};
91+
92+
export const modalBackground: ViewStyle = {
93+
flex: 1,
94+
justifyContent: 'flex-end',
95+
};
96+
97+
export const modalSheetContainer: ViewStyle = {
98+
backgroundColor: '#ffffff',
99+
borderTopLeftRadius: 16,
100+
borderTopRightRadius: 16,
101+
overflow: 'hidden',
102+
alignSelf: 'stretch',
103+
height: '92%',
104+
shadowColor: '#000',
105+
shadowOffset: { width: 0, height: -3 },
106+
shadowOpacity: 0.1,
107+
shadowRadius: 4,
108+
elevation: 5,
109+
};
110+
82111
export default defaultStyles;

packages/core/src/js/feedback/FeedbackFormManager.tsx

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { logger } from '@sentry/core';
22
import * as React from 'react';
3-
import { Modal, View } from 'react-native';
3+
import { Animated, Modal, View } from 'react-native';
44

55
import { FeedbackForm } from './FeedbackForm';
6-
import defaultStyles from './FeedbackForm.styles';
6+
import { modalBackground, modalSheetContainer, modalWrapper } from './FeedbackForm.styles';
77
import type { FeedbackFormStyles } from './FeedbackForm.types';
88
import { getFeedbackOptions } from './integration';
99
import { 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+
4348
class 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

Comments
 (0)