Please provide the following:
- SDK Version: v38.0.0
- Platforms(Android/iOS/web/all): web
I am developping a function for QRCode scanning for mobile and web.
On mobile it works perfectly but on web it’s another story.
Indeed Camera.getAvailableCameraTypesAsync()
with Chrome on Windows 10 looks to be buggy: with a standard PC owning one camera the function returns a null array.
It is puzzling since it works well with Chrome on my Microsoft Surface on Windows 10 (there are two cameras).
Here is the code
import React, { useState, useEffect } from 'react';
import { Platform, View, TouchableOpacity } from 'react-native';
import { FAB, Text } from 'react-native-paper';
import { Camera } from 'expo-camera';
export default function CoreCamera() {
const [hasPermission, setHasPermission] = useState(null);
const [type, setType] = useState(Camera.Constants.Type.back);
const [types, setTypes] = useState(null);
useEffect(() => {
(async () => {
const types = await Camera.getAvailableCameraTypesAsync();
alert(JSON.stringify(types));
setTypes(types);
if (Platform.OS === 'web') {
setHasPermission(true);
} else {
const { status } = await Camera.requestPermissionsAsync();
setHasPermission(status === 'granted');
}
})();
}, []);
if (hasPermission === null) {
return <View />;
}
if (hasPermission === false) {
return <Text>No access to camera</Text>;
}
return (
<View style={{ flex: 1 }}>
<Camera style={{ flex: 1 }} type={type}>
<View
style={{
flex: 1,
backgroundColor: 'transparent',
flexDirection: 'row',
}}
>
<TouchableOpacity
style={{
flex: 0.1,
alignSelf: 'flex-end',
alignItems: 'center',
}}
onPress={() => {
setType(
type === Camera.Constants.Type.back
? Camera.Constants.Type.front
: Camera.Constants.Type.back,
);
}}
>
<FAB
style={{ marginBottom: 20 }}
icon="camera-switch"
/>
</TouchableOpacity>
</View>
</Camera>
</View>
);
}
Any ideas for a workaround or when a fix will be released ?
I am totally blocked …
Many thanks !