-
-
Notifications
You must be signed in to change notification settings - Fork 359
Expand file tree
/
Copy pathFeedbackButton.tsx
More file actions
71 lines (62 loc) · 2.3 KB
/
FeedbackButton.tsx
File metadata and controls
71 lines (62 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import type { NativeEventSubscription } from 'react-native';
import * as React from 'react';
import { Appearance, Image, Text, TouchableOpacity } from 'react-native';
import type { FeedbackButtonProps, FeedbackButtonStyles, FeedbackButtonTextConfiguration } from './FeedbackForm.types';
import { defaultButtonConfiguration } from './defaults';
import { defaultButtonStyles } from './FeedbackForm.styles';
import { getTheme } from './FeedbackForm.theme';
import { showFeedbackForm } from './FeedbackFormManager';
import { feedbackIcon } from './icons';
import { lazyLoadFeedbackIntegration } from './lazy';
/**
* @beta
* @deprecated The `FeedbackButton` component will be removed in a future major version.
* Implements a feedback button that opens the FeedbackForm.
*/
export class FeedbackButton extends React.Component<FeedbackButtonProps> {
private _themeListener: NativeEventSubscription | undefined;
public constructor(props: FeedbackButtonProps) {
super(props);
lazyLoadFeedbackIntegration();
}
/**
* Adds a listener for theme changes.
*/
public componentDidMount(): void {
this._themeListener = Appearance.addChangeListener(() => {
this.forceUpdate();
});
}
/**
* Removes the theme listener.
*/
public componentWillUnmount(): void {
if (this._themeListener) {
this._themeListener.remove();
}
}
/**
* Renders the feedback button.
*/
public render(): React.ReactNode {
const theme = getTheme();
const text: FeedbackButtonTextConfiguration = { ...defaultButtonConfiguration, ...this.props };
const styles: FeedbackButtonStyles = {
triggerButton: { ...defaultButtonStyles(theme).triggerButton, ...this.props.styles?.triggerButton },
triggerText: { ...defaultButtonStyles(theme).triggerText, ...this.props.styles?.triggerText },
triggerIcon: { ...defaultButtonStyles(theme).triggerIcon, ...this.props.styles?.triggerIcon },
};
return (
<TouchableOpacity
style={styles.triggerButton}
onPress={showFeedbackForm}
accessibilityLabel={text.triggerAriaLabel}
>
<Image source={{ uri: feedbackIcon }} style={styles.triggerIcon} />
<Text style={styles.triggerText} testID="sentry-feedback-button">
{text.triggerLabel}
</Text>
</TouchableOpacity>
);
}
}