@@ -3,7 +3,6 @@ import { captureFeedback, getCurrentScope, lastEventId, logger } from '@sentry/c
33import * as React from 'react' ;
44import type { KeyboardTypeOptions } from 'react-native' ;
55import {
6- Alert ,
76 Image ,
87 Keyboard ,
98 KeyboardAvoidingView ,
@@ -17,12 +16,13 @@ import {
1716 View
1817} from 'react-native' ;
1918
19+ import { isWeb , notWeb } from '../utils/environment' ;
2020import { NATIVE } from '../wrapper' ;
2121import { sentryLogo } from './branding' ;
2222import { defaultConfiguration } from './defaults' ;
2323import defaultStyles from './FeedbackWidget.styles' ;
2424import type { FeedbackGeneralConfiguration , FeedbackTextConfiguration , FeedbackWidgetProps , FeedbackWidgetState , FeedbackWidgetStyles , ImagePickerConfiguration } from './FeedbackWidget.types' ;
25- import { isValidEmail } from './utils' ;
25+ import { base64ToUint8Array , feedbackAlertDialog , isValidEmail } from './utils' ;
2626
2727/**
2828 * @beta
@@ -75,12 +75,12 @@ export class FeedbackWidget extends React.Component<FeedbackWidgetProps, Feedbac
7575 const trimmedDescription = description ?. trim ( ) ;
7676
7777 if ( ( this . props . isNameRequired && ! trimmedName ) || ( this . props . isEmailRequired && ! trimmedEmail ) || ! trimmedDescription ) {
78- Alert . alert ( text . errorTitle , text . formError ) ;
78+ feedbackAlertDialog ( text . errorTitle , text . formError ) ;
7979 return ;
8080 }
8181
8282 if ( this . props . shouldValidateEmail && ( this . props . isEmailRequired || trimmedEmail . length > 0 ) && ! isValidEmail ( trimmedEmail ) ) {
83- Alert . alert ( text . errorTitle , text . emailError ) ;
83+ feedbackAlertDialog ( text . errorTitle , text . emailError ) ;
8484 return ;
8585 }
8686
@@ -107,13 +107,13 @@ export class FeedbackWidget extends React.Component<FeedbackWidgetProps, Feedbac
107107 }
108108 captureFeedback ( userFeedback , attachments ? { attachments } : undefined ) ;
109109 onSubmitSuccess ( { name : trimmedName , email : trimmedEmail , message : trimmedDescription , attachments : attachments } ) ;
110- Alert . alert ( text . successMessageText ) ;
110+ feedbackAlertDialog ( text . successMessageText , '' ) ;
111111 onFormSubmitted ( ) ;
112112 this . _didSubmitForm = true ;
113113 } catch ( error ) {
114114 const errorString = `Feedback form submission failed: ${ error } ` ;
115115 onSubmitError ( new Error ( errorString ) ) ;
116- Alert . alert ( text . errorTitle , text . genericError ) ;
116+ feedbackAlertDialog ( text . errorTitle , text . genericError ) ;
117117 logger . error ( `Feedback form submission failed: ${ error } ` ) ;
118118 }
119119 } ;
@@ -124,15 +124,15 @@ export class FeedbackWidget extends React.Component<FeedbackWidgetProps, Feedbac
124124 if ( imagePickerConfiguration . imagePicker ) {
125125 const launchImageLibrary = imagePickerConfiguration . imagePicker . launchImageLibraryAsync
126126 // expo-image-picker library is available
127- ? ( ) => imagePickerConfiguration . imagePicker . launchImageLibraryAsync ( { mediaTypes : [ 'images' ] } )
127+ ? ( ) => imagePickerConfiguration . imagePicker . launchImageLibraryAsync ( { mediaTypes : [ 'images' ] , base64 : isWeb ( ) } )
128128 // react-native-image-picker library is available
129129 : imagePickerConfiguration . imagePicker . launchImageLibrary
130- ? ( ) => imagePickerConfiguration . imagePicker . launchImageLibrary ( { mediaType : 'photo' } )
130+ ? ( ) => imagePickerConfiguration . imagePicker . launchImageLibrary ( { mediaType : 'photo' , includeBase64 : isWeb ( ) } )
131131 : null ;
132132 if ( ! launchImageLibrary ) {
133133 logger . warn ( 'No compatible image picker library found. Please provide a valid image picker library.' ) ;
134134 if ( __DEV__ ) {
135- Alert . alert (
135+ feedbackAlertDialog (
136136 'Development note' ,
137137 'No compatible image picker library found. Please provide a compatible version of `expo-image-picker` or `react-native-image-picker`.' ,
138138 ) ;
@@ -142,18 +142,29 @@ export class FeedbackWidget extends React.Component<FeedbackWidgetProps, Feedbac
142142
143143 const result = await launchImageLibrary ( ) ;
144144 if ( result . assets && result . assets . length > 0 ) {
145- const filename = result . assets [ 0 ] . fileName ;
146- const imageUri = result . assets [ 0 ] . uri ;
147- NATIVE . getDataFromUri ( imageUri ) . then ( ( data ) => {
145+ if ( isWeb ( ) ) {
146+ const filename = result . assets [ 0 ] . fileName ;
147+ const imageUri = result . assets [ 0 ] . uri ;
148+ const base64 = result . assets [ 0 ] . base64 ;
149+ const data = base64ToUint8Array ( base64 ) ;
148150 if ( data != null ) {
149151 this . setState ( { filename, attachment : data , attachmentUri : imageUri } ) ;
150152 } else {
151- logger . error ( 'Failed to read image data from uri:' , imageUri ) ;
153+ logger . error ( 'Failed to read image data on the web' ) ;
152154 }
153- } )
154- . catch ( ( error ) => {
155+ } else {
156+ const filename = result . assets [ 0 ] . fileName ;
157+ const imageUri = result . assets [ 0 ] . uri ;
158+ NATIVE . getDataFromUri ( imageUri ) . then ( ( data ) => {
159+ if ( data != null ) {
160+ this . setState ( { filename, attachment : data , attachmentUri : imageUri } ) ;
161+ } else {
162+ logger . error ( 'Failed to read image data from uri:' , imageUri ) ;
163+ }
164+ } ) . catch ( ( error ) => {
155165 logger . error ( 'Failed to read image data from uri:' , imageUri , 'error: ' , error ) ;
156166 } ) ;
167+ }
157168 }
158169 } else {
159170 // Defaulting to the onAddScreenshot callback
@@ -215,9 +226,10 @@ export class FeedbackWidget extends React.Component<FeedbackWidgetProps, Feedbac
215226 < KeyboardAvoidingView
216227 behavior = { Platform . OS === 'ios' ? 'padding' : 'height' }
217228 style = { [ styles . container , { padding : 0 } ] }
229+ enabled = { notWeb ( ) }
218230 >
219231 < ScrollView bounces = { false } >
220- < TouchableWithoutFeedback onPress = { Keyboard . dismiss } >
232+ < TouchableWithoutFeedback onPress = { notWeb ( ) ? Keyboard . dismiss : undefined } >
221233 < View style = { styles . container } >
222234 < View style = { styles . titleContainer } >
223235 < Text style = { styles . title } > { text . formTitle } </ Text >
0 commit comments