I need to add image picker in my app. I've created small class for image picker logic:
import {launchImageLibrary, launchCamera} from 'react-native-image-picker';export default class ImagePickerService { static openPickerLibrary( setImageUrl: Dispatch<SetStateAction<string | null | undefined>>, setModalVisible: Dispatch<SetStateAction<boolean>>, ) { launchImageLibrary( {mediaType: 'photo', includeBase64: true}, (response: any) => { if (response.didCancel) { console.log('User cancelled image picker'); } else if (response.error) { console.log('ImagePicker Error: ', response.error); } else { setImageUrl(`data:image/jpeg;base64,${response.base64}`); setModalVisible(false); } }, ); } static openPickerCamera( setImageUrl: Dispatch<SetStateAction<string | null | undefined>>, setModalVisible: Dispatch<SetStateAction<boolean>>, ) { launchCamera({mediaType: 'photo', includeBase64: true}, (response: any) => { if (response.didCancel) { console.log('User cancelled image picker'); } else if (response.error) { console.log('ImagePicker Error: ', response.error); } else { setImageUrl(`data:image/jpeg;base64,${response.base64}`); setModalVisible(false); } }); }}
Then I call these methods this way:
<ModalButton label="Take photo" onPress={() => ImagePickerService.openPickerCamera(setImageUrl, setPickerVisible) }/><ModalButton label="Choose photo" onPress={() => ImagePickerService.openPickerLibrary(setImageUrl, setPickerVisible) }/>
Picker library works great. But picker camera doesn't open. Only the modal window closes and nothing else. Also there aren't any errors in console.
I don't understand why this happens. I have all permissions in AndroidManifest. Also I have tried this string and it didn't help:
android:requestLegacyExternalStorage="true"
Also I have tried these features and they also didn't help:
<uses-feature android:name="android.hardware.camera" android:required="false" /><uses-feature android:name="android.hardware.camera.front" android:required="false" />
How can I fix this problem?