Open oliviermartin opened 1 month ago
Guten Tag, Hans here. Thank you for your detailed report! It looks like you are experiencing a valid issue with the
However, I noticed that you didn’t try to reproduce this issue in the VisionCamera Example app. This is important for us to understand if it is an issue specific to your app or a potential bug in the library itself. Please give it a try and let us know the results.
Also, if you could provide more logs surrounding the initialization process or any errors you might see, it would greatly help mrousavy in diagnosing the issue further. You can gather them by running adb logcat
if you're using Android.
Feel free to follow up after trying the example app. Cheers! 🍻
Note: If you think I made a mistake, please ping
@mrousavy
to take a look.
I have just tried VisionCamera Example app. The application is in full screen.
I did modify the example app to be closer to my case and it seems to work (ie: the
--- a/package/example/src/CameraPage.tsx
+++ b/package/example/src/CameraPage.tsx
@@ -195,11 +195,12 @@ export function CameraPage({ navigation }: Props): React.ReactElement {
return (
<View style={styles.container}>
{device != null ? (
+ <View style={styles.camera_view}>
<PinchGestureHandler onGestureEvent={onPinchGesture} enabled={isActive}>
- <Reanimated.View onTouchEnd={onFocusTap} style={StyleSheet.absoluteFill}>
+ <Reanimated.View onTouchEnd={onFocusTap} style={styles.camera}>
<TapGestureHandler onEnded={onDoubleTap} numberOfTaps={2}>
<ReanimatedCamera
- style={StyleSheet.absoluteFill}
+ style={styles.camera}
device={device}
isActive={isActive}
ref={camera}
@@ -232,6 +233,7 @@ export function CameraPage({ navigation }: Props): React.ReactElement {
</TapGestureHandler>
</Reanimated.View>
</PinchGestureHandler>
+ </View>
) : (
<View style={styles.emptyContainer}>
<Text style={styles.text}>Your phone does not have a Camera.</Text>
@@ -289,9 +291,15 @@ export function CameraPage({ navigation }: Props): React.ReactElement {
const styles = StyleSheet.create({
container: {
- flex: 1,
- backgroundColor: 'black',
+ flex: 1, alignItems: 'center', justifyContent: 'center',
+ backgroundColor: 'red',
+ },
+ camera_view: {
+ paddingBottom: 20,
+ alignItems: 'center',
+ justifyContent: 'center',
},
+ camera: {width: 150, height: 300, zIndex: 0},
captureButton: {
position: 'absolute',
alignSelf: 'center',
But the VisionCamera Example app is much more complex than my test app. I do not know whether I missed something.
cc: @mrousavy
I have been trying to reduce VisionCamera Example app code to simpler test app. I managed few times to duplicate the issue with a minimal version of VisionCamera Example app but not as often as with my app.
I would guess it is a timing / race condition issue somewhere in react-native
or react-native-vision-camera
when the camera is initialized - more likely react-native-vision-camera
as I would have guessed people would have seen it more if it was a generic react-native issue. When the screen is reloaded with a camera already initialized, the issue disappears.
For my test app, I used latest react-native and I have enabled new react native architecture.
I'm having the same problem that the layout is set wrong occasionally (around 20% of the time) there is some race issue going on..
I had on camera view component
const device = useCameraDevice('back'); const [ hasCameraRights, setHasCameraRights ] = useState(false);
useEffect(() => { (async () => { const cameraPermitted = await PermissionsAndroid.check('android.permission.CAMERA'); if (cameraPermitted) { setHasCameraRights(true); } })(); }, []);
if(!hasCameraRight)
return
if (!device) {
return
After I removed that hasCameraRights check it started working correctly, so it has something to do with layout change timings.
I am also experiencing this. I am on RN 0.72.17
on version react-native-vision-camera: 4.3.1
.
I was attempting to get the camera to sit below a header but I was experiencing this exact problem where the camera pops to the top left. This only happened on android, a Pixel 3a API 33 for me, and didnt happen every single time but it would happen 1 in 10 renders of the camera.
I created a very very simple test project on RN 0.76.1
using version react-native-vision-camera: 4.6.1
to test if the issue occurred on the latest versions as well.
Reproducible code -> https://github.com/FraserKemp/CameraReproduceCase
Again I tested on Pixel 3a API 33.
I am also experiencing this. I am on RN
0.72.17
on versionreact-native-vision-camera: 4.3.1
.I was attempting to get the camera to sit below a header but I was experiencing this exact problem where the camera pops to the top left. This only happened on android, a Pixel 3a API 33 for me, and didnt happen every single time but it would happen 1 in 10 renders of the camera.
I created a very very simple test project on RN
0.76.1
using versionreact-native-vision-camera: 4.6.1
to test if the issue occurred on the latest versions as well.Reproducible code -> https://github.com/FraserKemp/CameraReproduceCase
Again I tested on Pixel 3a API 33.
I did not test your code, but it's similar when I had problems. I'm sure if you take that rights check away it will work. In my case I removed the right check and added it outside to the camera open event before initializing the component. You could also add some right check wrapper and only initialize the camera component after have rights.
I just found some strange... workaround? I have code like this
<View style={{ flex: 1 }} >
{ hasPermission ? <Camera {...someProps} /> : <NoPermissionView /> }
</View>
After some hours of debugging, I added { borderColor: "transparent", borderWidth: 0 }
to <View />
style, and the issue was solved. I am not sure why or how this works, but it does in my case. Maybe it will help someone.
UPD 1: It looks like borderWidth: 0
isn't necessary.
I was experiencing the same issue. This was only happening on initial render.
Once I navigate away from and back to camera the layout is correct.
@setafd your hack solved the issue for me. TY!
What's happening?
In my simple app, the first time I start it, the is located at the top left corner of the screen while I expect it to be in the middle of the screen.
But when coming back on the screen, the is now located in the middle of the screen.
What I see:
On the screen reload:
Reproduceable Code
Relevant log output
Camera Device
Device
Samsung Galaxy A20e (Android 11)
VisionCamera Version
4.5.3
Can you reproduce this issue in the VisionCamera Example app?
I didn't try (⚠️ your issue might get ignored & closed if you don't try this)
Additional information