-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[expo-camera] [ios] Camera does not remount properly when using new architecture #31597
Comments
Thank you for filing this issue! |
This is definitely an issue with the new architecture, with my app exhibiting the same behaviours. If you try to record a video, the app will crash straight away |
Minimal reproducible example
https://github.com/devon94/expo-camera-new-arch-repro
What platform(s) does this occur on?
iOS
Where did you reproduce the issue?
in a development build
Summary
When using expo camera with the new architechture enabled on ios, the second time the camera mounts the preview does not start up.
To repro you can run the reproduction repo on device (
yarn expo run:ios --device
). Once running do the following:You'll also notice the camera doesn't start up. If you pass the
onCameraReady
Prop you will also notice it is never called. To see how it worked in the old arch you can set this to false and rerun the app with the same scenario abovehttps://github.com/devon94/expo-camera-new-arch-repro/blob/a66789efe60aa86ab9261b4ebb2e67a0ddc72908/app.json#L48
I did some light debugging and hopefully i'm on the right path.
I noticed a new CameraView was being created each time react-native mounted the component on the old arch, which means all variables including
cameraShouldInit
andcaptureDeviceInput
were set to their defaults allowing the initialization logic to run again.On the new arch, it seems like
cameraShouldInit
is set once which causes the guard in the code below to always return each time.expo/packages/expo-camera/ios/Current/CameraView.swift
Lines 158 to 164 in 2ebcab0
Adding a
cameraShouldInit = false
when the code below runs helps with the guard.expo/packages/expo-camera/ios/Current/CameraView.swift
Lines 686 to 692 in 2ebcab0
But it still fails the check in the code below because
captureDeviceInput
is persisted causing the camera to skip initialization and show a black view.expo/packages/expo-camera/ios/Current/CameraView.swift
Lines 754 to 756 in 2ebcab0
Flipping the input device currently fixes the issue and brings the camera back to life because it changes both
cameraShouldInit
and makes the following check work.I'm not 100% sure the best way to fix this, initially I thought of just resetting some of those variables when
removeFromSuperview
is called but not sure if that messes up other things.Environment
Expo Doctor Diagnostics
The text was updated successfully, but these errors were encountered: