Expo BarCodeScanner freezes (better said, the camera) when leaving the app

Please provide the following:

  1. SDK Version: 37
  2. Platforms: Android/iOS

I have this BarCodeScanner from Expo placed in a tab:

return (
    <View
      style={{
        flex: 1,
        flexDirection: "column",
        justifyContent: "flex-end",
      }}
    >
      <BarCodeScanner
        onBarCodeScanned={scanned ? undefined : handleBarCodeScanned}
        barCodeTypes={[BarCodeScanner.Constants.BarCodeType.ean13]}
        style={StyleSheet.absoluteFillObject}
      />

      {scanned && (
        <Button title={"Tap to Scan Again"} onPress={() => setScanned(false)} />
      )}
    </View>
  );

When scanned, I’m redirecting to a page like so:

  const handleBarCodeScanned = ({ type, data }) => {
    setScanned(true);
    props.navigation.navigate("EanProduct", {
      ean: data,
    });
  };

It works fine. The problem is, when I leave the app via Homebutton and go back into the app, the camera is frozen. The app has not crashed, I can navigate around, but the camera is frozen.

Is there a work-around to wake the camera back up? Or why is this happening at all? I tried to listen to navigation changes to reload the screen with didFocus for the tabbar

  useEffect(() => {
    const navFocusListener = props.navigation.addListener("didFocus", () => {
      //console.log("reload");
    });

    return () => {
      navFocusListener.remove();
    };
  }, [props.navigation]);

Unfortunately this does not work. The camera stays frozen.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.