Skip to content

Conversation

@mirsahib
Copy link

This PR introduces two key improvements to the camera functionality in with-camera/App.tsx:

  1. Camera Re-initialization on Focus:

    • Change: Implemented useFocusEffect from expo-router to increment a cameraKey state variable whenever the
      screen gains focus. The CameraView component now uses this cameraKey as its key prop.
    • Purpose: This is an effective solution to ensure the CameraView component is re-mounted and
      re-initialized when the user navigates back to this screen. This addresses potential issues where the
      camera might not function correctly after being unfocused or backgrounded, providing a more robust user
      experience. The use of useCallback with useFocusEffect is also good practice for performance.
  2. CameraView Children Limitation Fix:

    • Change: The CameraView component and its associated shutter controls (View component) are now wrapped
      within a React Fragment (<></>).
    • Purpose: This correctly addresses the limitation that CameraView does not support children. By making
      the CameraView and the controls siblings within a fragment, you can then use absolute positioning for
      the controls, ensuring they render correctly on top of the camera feed without causing inconsistent
      behavior or crashes.
    • Potential Fix
 WARN  The <CameraView> component does not support children. This may lead to inconsistent behaviour or crashes. If you want to render content on top of the Camera, consider using absolute positioning.

  Re-initializes CameraView on screen focus using useFocusEffect and wraps CameraView with controls in a
  fragment to address children limitation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant