After I have installed react-native-vision-camera using expo, I can not open the camera.
Here is my code:
const ScanProduct =({navigation})=>{
// Camera
const devices = useCameraDevices('wide-angle-camera')
const device = devices.back
React.useEffect(()=>{
requestCameraPermission
},[])
// Handler
const requestCameraPermission = React.useCallback(async ()=>{
const permission = await Camera.requestCameraPermission();
if(permission === 'denied') await Linking.openSettings()
},[])
function renderCamera(){
if(device == null){
return(
<View
style={{
flex:1,
}}
/>
)
} else{
return(
<View
style={{
flex:1
}}
>
<Camera
style={{flex:1}}
device={device}
isActive={true}
enableZoomGesture
/>
</View>
)
}
}
return(
<View>
{/*Camera*/}
{renderCamera()}
</View>
)
}
Between I run the code on my iphone using Expo Go app and the app can run smoothly except the code camera above giving me this error TypeError: Cannot read property 'getAvailableCameraDevices' of null.
Anyone can help me out is highly appreciated
2
Answers
Perhaps you didn’t call the requestCameraPermission properly in use effect, missed to add ()!?
Also, you do not need to use "else", as "if" already has the return statement.
or I would rather
Also below should work without </>
Or just
This error seems like a build issue. After installing the npm package and add the plugin in you app.json
Then you need to rebuild your app by typing. Don’t forget to change the platform and profile attributes based on your need.