0

I am using react-navigation to navigate through screens. In the main screen I use expo-camera and the onFacesDetected callback within the Camera component as follows:

import { Camera }  from 'expo-camera';
import { useState} from 'react';

const [faceData, setFaceData] = useState([]);

function MainScreen({ navigation }){

 return(
 <Camera
  ref={CAM} style={CSS.cameraStyle}
  type={Camera.Constants.Type.front}
  faceDetectorSettings={{camSett}}
  onFacesDetected={(e)=> setFaceData(e.faces)}
  >
  {doSomeWith(faceData)}
 </Camera>
 )

};

The issue is that every time a face is detected a render is triggered (as expected, since I'm updating the faceData state) and the camera gets closed and opened nonstop on every render. If I render the Camera component without a Stack.Screen this issue don't happens and the renders triggers normally onFacesDetected callback. How can I fix this problem keeping the Camera as part of a navigation screen?

EnzoBH
  • 1
  • 1

1 Answers1

0

Managed to solve it by defining the states that the MainScreen updates within the MainScreen component.

EnzoBH
  • 1
  • 1