@@ -20,8 +20,8 @@ import {
2020import { sentryLogo } from './branding' ;
2121import { defaultConfiguration } from './defaults' ;
2222import defaultStyles from './FeedbackForm.styles' ;
23- import type { FeedbackFormProps , FeedbackFormState , FeedbackFormStyles , FeedbackGeneralConfiguration , FeedbackTextConfiguration } from './FeedbackForm.types' ;
24- import { isValidEmail } from './utils' ;
23+ import type { FeedbackFormProps , FeedbackFormState , FeedbackFormStyles , FeedbackGeneralConfiguration , FeedbackTextConfiguration , ImagePickerConfiguration } from './FeedbackForm.types' ;
24+ import { base64ToUint8Array , isValidEmail } from './utils' ;
2525
2626/**
2727 * @beta
@@ -100,12 +100,38 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
100100 }
101101 } ;
102102
103- public onScreenshotButtonPress : ( ) => void = ( ) => {
103+ public onScreenshotButtonPress : ( ) => void = async ( ) => {
104104 if ( ! this . state . filename && ! this . state . attachment ) {
105- const { onAddScreenshot } = { ...defaultConfiguration , ...this . props } ;
106- onAddScreenshot ( ( filename : string , attachement : Uint8Array ) => {
107- this . setState ( { filename, attachment : attachement } ) ;
108- } ) ;
105+ const imagePickerConfiguration : ImagePickerConfiguration = this . props ;
106+ if ( imagePickerConfiguration . imagePicker && imagePickerConfiguration . imagePicker . launchImageLibraryAsync ) {
107+ // expo-image-picker library is available
108+ const result = await imagePickerConfiguration . imagePicker . launchImageLibraryAsync ( {
109+ mediaTypes : [ 'images' ] , base64 : true
110+ } ) ;
111+ if ( ! result . canceled ) {
112+ const filename = result . assets [ 0 ] . fileName ;
113+ const attachement = base64ToUint8Array ( result . assets [ 0 ] . base64 ) ;
114+ this . setState ( { filename, attachment : attachement } ) ;
115+ }
116+ } else if ( imagePickerConfiguration . imagePicker && imagePickerConfiguration . imagePicker . launchImageLibrary ) {
117+ // react-native-image-picker library is available
118+ const result = await imagePickerConfiguration . imagePicker . launchImageLibrary ( {
119+ mediaType : 'photo' , includeBase64 : true
120+ } ) ;
121+ if ( ! result . didCancel && ! result . errorCode ) {
122+ const filename = result . assets [ 0 ] . fileName ;
123+ const attachement = base64ToUint8Array ( result . assets [ 0 ] . base64 ) ;
124+ this . setState ( { filename, attachment : attachement } ) ;
125+ }
126+ } else {
127+ logger . warn ( 'No image picker library found. Please provide an image picker library to use this feature.' ) ;
128+
129+ // Defaulting to the onAddScreenshot callback
130+ const { onAddScreenshot } = { ...defaultConfiguration , ...this . props } ;
131+ onAddScreenshot ( ( filename : string , attachement : Uint8Array ) => {
132+ this . setState ( { filename, attachment : attachement } ) ;
133+ } ) ;
134+ }
109135 } else {
110136 this . setState ( { filename : undefined , attachment : undefined } ) ;
111137 }
@@ -118,6 +144,7 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
118144 const { name, email, description } = this . state ;
119145 const { onFormClose } = this . props ;
120146 const config : FeedbackGeneralConfiguration = this . props ;
147+ const imagePickerConfiguration : ImagePickerConfiguration = this . props ;
121148 const text : FeedbackTextConfiguration = this . props ;
122149 const styles : FeedbackFormStyles = { ...defaultStyles , ...this . props . styles } ;
123150 const onCancel = ( ) : void => {
@@ -191,7 +218,7 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
191218 onChangeText = { ( value ) => this . setState ( { description : value } ) }
192219 multiline
193220 />
194- { config . enableScreenshot && (
221+ { ( config . enableScreenshot || imagePickerConfiguration . imagePicker ) && (
195222 < TouchableOpacity style = { styles . screenshotButton } onPress = { this . onScreenshotButtonPress } >
196223 < Text style = { styles . screenshotText } >
197224 { ! this . state . filename && ! this . state . attachment
0 commit comments