Skip to content

Commit c77702e

Browse files
authored
Merge 4408071 into b209ad6
2 parents b209ad6 + 4408071 commit c77702e

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@
4444
...
4545
<FeedbackForm/>
4646
```
47+
or auto-inject it by calling the `showFeedbackForm`:
48+
```jsx
49+
import { showFeedbackForm } from '@sentry/react-native';
50+
...
51+
<Button
52+
title="Show feedback form"
53+
onPress={() => {
54+
showFeedbackForm(_props.navigation);
55+
}}
56+
/>
57+
```
4758

4859
- Export `Span` type from `@sentry/types` ([#4345](https://github.com/getsentry/sentry-react-native/pull/4345))
4960

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

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { captureFeedback, getCurrentScope, lastEventId } from '@sentry/core';
1+
import { captureFeedback, getCurrentScope, lastEventId, logger } from '@sentry/core';
22
import type { SendFeedbackParams } from '@sentry/types';
33
import * as React from 'react';
44
import type { KeyboardTypeOptions } from 'react-native';
@@ -19,6 +19,31 @@ import { defaultConfiguration } from './defaults';
1919
import defaultStyles from './FeedbackForm.styles';
2020
import type { FeedbackFormProps, FeedbackFormState, FeedbackFormStyles,FeedbackGeneralConfiguration, FeedbackTextConfiguration } from './FeedbackForm.types';
2121

22+
let feedbackFormHandler: (() => void) | null = null;
23+
24+
const setFeedbackFormHandler = (handler: () => void): void => {
25+
feedbackFormHandler = handler;
26+
};
27+
28+
const clearFeedbackFormHandler = (): void => {
29+
feedbackFormHandler = null;
30+
};
31+
32+
type Navigation = {
33+
navigate: (screen: string, params?: Record<string, unknown>) => void;
34+
};
35+
36+
export const showFeedbackForm = (navigation: Navigation): void => {
37+
setFeedbackFormHandler(() => {
38+
navigation?.navigate?.('FeedbackForm');
39+
});
40+
if (feedbackFormHandler) {
41+
feedbackFormHandler();
42+
} else {
43+
logger.error('FeedbackForm handler is not set. Please ensure it is initialized.');
44+
}
45+
};
46+
2247
/**
2348
* @beta
2449
* Implements a feedback form screen that sends feedback to Sentry using Sentry.captureFeedback.
@@ -45,6 +70,13 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
4570
};
4671
}
4772

73+
/**
74+
* Clear the handler when the component unmounts
75+
*/
76+
public componentWillUnmount(): void {
77+
clearFeedbackFormHandler();
78+
}
79+
4880
public handleFeedbackSubmit: () => void = () => {
4981
const { name, email, description } = this.state;
5082
const { onFormClose } = this._config;

packages/core/src/js/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,4 @@ export type { TimeToDisplayProps } from './tracing';
8585

8686
export { Mask, Unmask } from './replay/CustomMask';
8787

88-
export { FeedbackForm } from './feedback/FeedbackForm';
88+
export { FeedbackForm, showFeedbackForm } from './feedback/FeedbackForm';

samples/react-native/src/Screens/ErrorsScreen.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
} from 'react-native';
1313

1414
import * as Sentry from '@sentry/react-native';
15+
import { showFeedbackForm } from '@sentry/react-native';
1516

1617
import { setScopeProperties } from '../setScopeProperties';
1718
import { StackNavigationProp } from '@react-navigation/stack';
@@ -226,6 +227,12 @@ const ErrorsScreen = (_props: Props) => {
226227
_props.navigation.navigate('FeedbackForm');
227228
}}
228229
/>
230+
<Button
231+
title="Feedback form (autoinject)"
232+
onPress={() => {
233+
showFeedbackForm(_props.navigation);
234+
}}
235+
/>
229236
<Button
230237
title="Send user feedback"
231238
onPress={() => {

0 commit comments

Comments
 (0)