Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(feedback): Show selected screenshot #4545

Merged
merged 15 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/core/src/js/feedback/FeedbackWidget.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,20 @@ const defaultStyles: FeedbackWidgetStyles = {
backgroundColor: '#eee',
padding: 15,
borderRadius: 5,
marginBottom: 20,
alignItems: 'center',
flex: 1,
},
screenshotContainer: {
flexDirection: 'row',
alignItems: 'center',
width: '100%',
marginBottom: 20,
},
screenshotThumbnail: {
width: 50,
height: 50,
borderRadius: 5,
marginRight: 10,
},
screenshotText: {
color: '#333',
Expand Down
38 changes: 25 additions & 13 deletions packages/core/src/js/feedback/FeedbackWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class FeedbackWidget extends React.Component<FeedbackWidgetProps, Feedbac
description: '',
filename: undefined,
attachment: undefined,
attachmentUri: undefined,
};

private _didSubmitForm: boolean = false;
Expand All @@ -60,6 +61,7 @@ export class FeedbackWidget extends React.Component<FeedbackWidgetProps, Feedbac
description: FeedbackWidget._savedState.description || '',
filename: FeedbackWidget._savedState.filename || undefined,
attachment: FeedbackWidget._savedState.attachment || undefined,
attachmentUri: FeedbackWidget._savedState.attachmentUri || undefined,
};
}

Expand Down Expand Up @@ -144,24 +146,25 @@ export class FeedbackWidget extends React.Component<FeedbackWidgetProps, Feedbac
const imageUri = result.assets[0].uri;
NATIVE.getDataFromUri(imageUri).then((data) => {
if (data != null) {
this.setState({ filename, attachment: data });
this.setState({ filename, attachment: data, attachmentUri: imageUri });
} else {
logger.error('Failed to read image data from uri:', imageUri);
}
})
.catch((error) => {
logger.error('Failed to read image data from uri:', imageUri, 'error: ', error);
});
.catch((error) => {
logger.error('Failed to read image data from uri:', imageUri, 'error: ', error);
});
}
} else {
// Defaulting to the onAddScreenshot callback
const { onAddScreenshot } = { ...defaultConfiguration, ...this.props };
onAddScreenshot((filename: string, attachement: Uint8Array) => {
this.setState({ filename, attachment: attachement });
// TODO: Add support for image uri when using onAddScreenshot
this.setState({ filename, attachment: attachement, attachmentUri: undefined });
});
}
} else {
this.setState({ filename: undefined, attachment: undefined });
this.setState({ filename: undefined, attachment: undefined, attachmentUri: undefined });
}
}

Expand Down Expand Up @@ -262,13 +265,21 @@ export class FeedbackWidget extends React.Component<FeedbackWidgetProps, Feedbac
multiline
/>
{(config.enableScreenshot || imagePickerConfiguration.imagePicker) && (
<TouchableOpacity style={styles.screenshotButton} onPress={this.onScreenshotButtonPress}>
<Text style={styles.screenshotText}>
{!this.state.filename && !this.state.attachment
? text.addScreenshotButtonLabel
: text.removeScreenshotButtonLabel}
</Text>
</TouchableOpacity>
<View style={styles.screenshotContainer}>
{this.state.attachmentUri && (
<Image
source={{ uri: this.state.attachmentUri }}
style={styles.screenshotThumbnail}
/>
)}
<TouchableOpacity style={styles.screenshotButton} onPress={this.onScreenshotButtonPress}>
<Text style={styles.screenshotText}>
{!this.state.filename && !this.state.attachment
? text.addScreenshotButtonLabel
: text.removeScreenshotButtonLabel}
</Text>
</TouchableOpacity>
</View>
)}
<TouchableOpacity style={styles.submitButton} onPress={this.handleFeedbackSubmit}>
<Text style={styles.submitText}>{text.submitButtonLabel}</Text>
Expand Down Expand Up @@ -296,6 +307,7 @@ export class FeedbackWidget extends React.Component<FeedbackWidgetProps, Feedbac
description: '',
filename: undefined,
attachment: undefined,
attachmentUri: undefined,
};
};
}
3 changes: 3 additions & 0 deletions packages/core/src/js/feedback/FeedbackWidget.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ export interface FeedbackWidgetStyles {
cancelButton?: ViewStyle;
cancelText?: TextStyle;
screenshotButton?: ViewStyle;
screenshotContainer?: ViewStyle;
screenshotThumbnail?: ImageStyle;
screenshotText?: TextStyle;
titleContainer?: ViewStyle;
sentryLogo?: ImageStyle;
Expand All @@ -252,4 +254,5 @@ export interface FeedbackWidgetState {
description: string;
filename?: string;
attachment?: string | Uint8Array;
attachmentUri?: string;
}
Loading
Loading