Skip to content
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

Open
devon94 opened this issue Sep 20, 2024 · 2 comments
Assignees

Comments

@devon94
Copy link
Contributor

devon94 commented Sep 20, 2024

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:

  1. Navigate to the camera tab (Grant permissions if needed)
  2. Navigate back to first tab
  3. Navigate back to the camera tab

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 above

https://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 and captureDeviceInput 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.

func initCamera() {
guard cameraShouldInit else {
return
}
cameraShouldInit = false
self.initializeCaptureSessionInput()
}

Adding a cameraShouldInit = false when the code below runs helps with the guard.

public override func removeFromSuperview() {
lifecycleManager?.unregisterAppLifecycleListener(self)
self.stopSession()
UIDevice.current.endGeneratingDeviceOrientationNotifications()
NotificationCenter.default.removeObserver(self, name: UIDevice.orientationDidChangeNotification, object: nil)
super.removeFromSuperview()
}

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.

if captureDeviceInput?.device.position == presetCamera {
return
}

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-env-info 1.2.0 environment info:
    System:
      OS: macOS 14.4.1
      Shell: 5.9 - /bin/zsh
    Binaries:
      Node: 20.16.0 - /opt/homebrew/opt/node@20/bin/node
      Yarn: 1.22.22 - /opt/homebrew/bin/yarn
      npm: 10.8.1 - /opt/homebrew/opt/node@20/bin/npm
    Managers:
      CocoaPods: 1.15.2 - /opt/homebrew/bin/pod
    SDKs:
      iOS SDK:
        Platforms: DriverKit 23.5, iOS 17.5, macOS 14.5, tvOS 17.5, visionOS 1.2, watchOS 10.5
      Android SDK:
        API Levels: 31, 34
        Build Tools: 34.0.0, 35.0.0
        System Images: android-34 | Google APIs ARM 64 v8a
    IDEs:
      Xcode: 15.4/15F31d - /usr/bin/xcodebuild
    npmPackages:
      expo: ~51.0.28 => 51.0.32 
      expo-router: ~3.5.23 => 3.5.23 
      react: 18.2.0 => 18.2.0 
      react-dom: 18.2.0 => 18.2.0 
      react-native: 0.74.5 => 0.74.5 
      react-native-web: ~0.19.10 => 0.19.12 
    Expo Workflow: bare

Expo Doctor Diagnostics

✔ Check Expo config for common issues
✔ Check package.json for common issues
✔ Check native tooling versions
✔ Check if the project meets version requirements for submission to app stores
✔ Check dependencies for packages that should not be installed directly
✔ Check for common project setup issues
✔ Check for app config fields that may not be synced in a non-CNG project
✔ Check for issues with metro config
✔ Check npm/ yarn versions
✔ Check Expo config (app.json/ app.config.js) schema
✔ Check that packages match versions required by installed Expo SDK
✔ Check for legacy global CLI installed locally
✔ Check that native modules do not use incompatible support packages
✔ Check that native modules use compatible support package versions for installed Expo SDK

Didn't find any issues with the project!
@devon94 devon94 added the needs validation Issue needs to be validated label Sep 20, 2024
@expo-bot expo-bot added needs review Issue is ready to be reviewed by a maintainer and removed needs validation Issue needs to be validated labels Sep 20, 2024
@devon94 devon94 changed the title [expo-camera] Camera does not remount properly when using new architecture [expo-camera] [ios] Camera does not remount properly when using new architecture Sep 20, 2024
@alanjhughes alanjhughes self-assigned this Sep 23, 2024
@expo-bot
Copy link
Collaborator

Thank you for filing this issue!
This comment acknowledges we believe this may be a bug and there’s enough information to investigate it.
However, we can’t promise any sort of timeline for resolution. We prioritize issues based on severity, breadth of impact, and alignment with our roadmap. If you’d like to help move it more quickly, you can continue to investigate it more deeply and/or you can open a pull request that fixes the cause.

@github-actions github-actions bot removed the needs review Issue is ready to be reviewed by a maintainer label Sep 23, 2024
@mogusbi
Copy link

mogusbi commented Oct 17, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants