import React, { useRef, useState, useEffect } from 'react';
import { StyleSheet, View, Text } from 'react-native';
import { RNCamera } from 'react-native-camera';
const Registration = () => {
const cameraRef = useRef(null);
const [cameraReady, setCameraReady] = useState(false);
useEffect(() => {
// Handle camera initialization and permissions here
if (cameraRef.current) {
setCameraReady(true);
}
}, [cameraRef]);
const handleCameraReady = () => {
setCameraReady(true);
};
return (
<View style={styles.container}>
{cameraReady ? (
<RNCamera
ref={cameraRef}
style={styles.preview}
type={RNCamera.Constants.Type.back}
flashMode={RNCamera.Constants.FlashMode.on}
androidCameraPermissionOptions={{
title: 'Permission to use camera',
message: 'We need your permission to use your camera',
buttonPositive: 'Ok',
buttonNegative: 'Cancel',
}}
onCameraReady={handleCameraReady}
/>
) : (
<Text>Camera is initializing...</Text>
)}
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'column',
backgroundColor: 'black',
},
preview: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
});
export default Registration;
Getting error in react native v0.76 when try to use react-native-camera Review My Error is Below
Attempt to invoke vitual method ‘com.facebook.react.uimanager.events.EventDispatcher.com.facebook.react.uimanager.UiManagerModule.getEventDispatcher()’ on a null object reference
2
Answers
I have this same error, The difficult part is knowing which plugin is causing the problem, since I have 70 installed, it is increasingly difficult to work with react-native
I got this resolved by adding the permissions in the android.manifest file:
<uses-permission android:name="android.permission.CAMERA" />