@@ -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 { getDataFromUri , isValidEmail } from './utils' ;
2525
2626/**
2727 * @beta
@@ -100,12 +100,46 @@ 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 ) {
107+ const launchImageLibrary = imagePickerConfiguration . imagePicker . launchImageLibraryAsync
108+ // expo-image-picker library is available
109+ ? ( ) => imagePickerConfiguration . imagePicker . launchImageLibraryAsync ( { mediaTypes : [ "images" ] } )
110+ // react-native-image-picker library is available
111+ : imagePickerConfiguration . imagePicker . launchImageLibrary
112+ ? ( ) => imagePickerConfiguration . imagePicker . launchImageLibrary ( { mediaType : "photo" } )
113+ : null ;
114+ if ( ! launchImageLibrary ) {
115+ logger . warn ( 'No compatible image picker library found. Please provide a valid image picker library.' ) ;
116+ if ( __DEV__ ) {
117+ Alert . alert (
118+ 'Development note' ,
119+ 'No compatible image picker library found. Please provide a compatible version of `expo-image-picker` or `react-native-image-picker`.' ,
120+ ) ;
121+ }
122+ return ;
123+ }
124+
125+ const result = await launchImageLibrary ( ) ;
126+ if ( result . assets && result . assets . length > 0 ) {
127+ const filename = result . assets [ 0 ] . fileName ;
128+ const imageUri = result . assets [ 0 ] . uri ;
129+ getDataFromUri ( imageUri ) . then ( ( data ) => {
130+ this . setState ( { filename, attachment : data } ) ;
131+ } )
132+ . catch ( ( error ) => {
133+ logger . error ( "Error:" , error ) ;
134+ } ) ;
135+ }
136+ } else {
137+ // Defaulting to the onAddScreenshot callback
138+ const { onAddScreenshot } = { ...defaultConfiguration , ...this . props } ;
139+ onAddScreenshot ( ( filename : string , attachement : Uint8Array ) => {
140+ this . setState ( { filename, attachment : attachement } ) ;
141+ } ) ;
142+ }
109143 } else {
110144 this . setState ( { filename : undefined , attachment : undefined } ) ;
111145 }
@@ -118,6 +152,7 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
118152 const { name, email, description } = this . state ;
119153 const { onFormClose } = this . props ;
120154 const config : FeedbackGeneralConfiguration = this . props ;
155+ const imagePickerConfiguration : ImagePickerConfiguration = this . props ;
121156 const text : FeedbackTextConfiguration = this . props ;
122157 const styles : FeedbackFormStyles = { ...defaultStyles , ...this . props . styles } ;
123158 const onCancel = ( ) : void => {
@@ -191,7 +226,7 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
191226 onChangeText = { ( value ) => this . setState ( { description : value } ) }
192227 multiline
193228 />
194- { config . enableScreenshot && (
229+ { ( config . enableScreenshot || imagePickerConfiguration . imagePicker ) && (
195230 < TouchableOpacity style = { styles . screenshotButton } onPress = { this . onScreenshotButtonPress } >
196231 < Text style = { styles . screenshotText } >
197232 { ! this . state . filename && ! this . state . attachment
0 commit comments