Skip to content

Commit 56a113e

Browse files
committed
Show selected screenshot
1 parent 38a6085 commit 56a113e

File tree

4 files changed

+177
-117
lines changed

4 files changed

+177
-117
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,20 @@ const defaultStyles: FeedbackFormStyles = {
4545
backgroundColor: '#eee',
4646
padding: 15,
4747
borderRadius: 5,
48-
marginBottom: 20,
4948
alignItems: 'center',
49+
flex: 1,
50+
},
51+
screenshotContainer: {
52+
flexDirection: 'row',
53+
alignItems: 'center',
54+
width: '100%',
55+
marginBottom: 20,
56+
},
57+
screenshotThumbnail: {
58+
width: 50,
59+
height: 50,
60+
borderRadius: 5,
61+
marginRight: 10,
5062
},
5163
screenshotText: {
5264
color: '#333',

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

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
4040
description: '',
4141
filename: undefined,
4242
attachment: undefined,
43+
attachmentUri: undefined,
4344
};
4445

4546
public constructor(props: FeedbackFormProps) {
@@ -59,6 +60,7 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
5960
description: FeedbackForm._savedState.description || '',
6061
filename: FeedbackForm._savedState.filename || undefined,
6162
attachment: FeedbackForm._savedState.attachment || undefined,
63+
attachmentUri: FeedbackForm._savedState.attachmentUri || undefined,
6264
};
6365
}
6466

@@ -141,7 +143,7 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
141143
const imageUri = result.assets[0].uri;
142144
NATIVE.getDataFromUri(imageUri).then((data) => {
143145
if (data != null) {
144-
this.setState({ filename, attachment: data }, this._saveFormState);
146+
this.setState({ filename, attachment: data, attachmentUri: imageUri }, this._saveFormState);
145147
} else {
146148
logger.error('Failed to read image data from uri:', imageUri);
147149
}
@@ -154,11 +156,12 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
154156
// Defaulting to the onAddScreenshot callback
155157
const { onAddScreenshot } = { ...defaultConfiguration, ...this.props };
156158
onAddScreenshot((filename: string, attachement: Uint8Array) => {
157-
this.setState({ filename, attachment: attachement }, this._saveFormState);
159+
// TODO: Add support for image uri when using onAddScreenshot
160+
this.setState({ filename, attachment: attachement, attachmentUri: undefined }, this._saveFormState);
158161
});
159162
}
160163
} else {
161-
this.setState({ filename: undefined, attachment: undefined }, this._saveFormState);
164+
this.setState({ filename: undefined, attachment: undefined, attachmentUri: undefined }, this._saveFormState);
162165
}
163166
}
164167

@@ -244,13 +247,21 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
244247
multiline
245248
/>
246249
{(config.enableScreenshot || imagePickerConfiguration.imagePicker) && (
247-
<TouchableOpacity style={styles.screenshotButton} onPress={this.onScreenshotButtonPress}>
248-
<Text style={styles.screenshotText}>
249-
{!this.state.filename && !this.state.attachment
250-
? text.addScreenshotButtonLabel
251-
: text.removeScreenshotButtonLabel}
252-
</Text>
253-
</TouchableOpacity>
250+
<View style={styles.screenshotContainer}>
251+
{this.state.attachmentUri && (
252+
<Image
253+
source={{ uri: this.state.attachmentUri }}
254+
style={styles.screenshotThumbnail}
255+
/>
256+
)}
257+
<TouchableOpacity style={styles.screenshotButton} onPress={this.onScreenshotButtonPress}>
258+
<Text style={styles.screenshotText}>
259+
{!this.state.filename && !this.state.attachment
260+
? text.addScreenshotButtonLabel
261+
: text.removeScreenshotButtonLabel}
262+
</Text>
263+
</TouchableOpacity>
264+
</View>
254265
)}
255266
<TouchableOpacity style={styles.submitButton} onPress={this.handleFeedbackSubmit}>
256267
<Text style={styles.submitText}>{text.submitButtonLabel}</Text>
@@ -279,6 +290,7 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
279290
description: '',
280291
filename: undefined,
281292
attachment: undefined,
293+
attachmentUri: undefined,
282294
};
283295
};
284296
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ export interface FeedbackFormStyles {
237237
cancelButton?: ViewStyle;
238238
cancelText?: TextStyle;
239239
screenshotButton?: ViewStyle;
240+
screenshotContainer?: ViewStyle;
241+
screenshotThumbnail?: ImageStyle;
240242
screenshotText?: TextStyle;
241243
titleContainer?: ViewStyle;
242244
sentryLogo?: ImageStyle;
@@ -252,4 +254,5 @@ export interface FeedbackFormState {
252254
description: string;
253255
filename?: string;
254256
attachment?: string | Uint8Array;
257+
attachmentUri?: string;
255258
}

0 commit comments

Comments
 (0)