该插件是react-native-camera变种, react-native-camera作者已经弃用,重新上架的新的插件,网上基本上没有使用的帖子本人边github关键词搜索边参考官方文档===》指路react-native-vision-camera官方文档
大致调整出一个可以录像/拍照的demo 供大家参考~
适用于:扫码场景,相机作为铺底(我所运用的场景)
代码如下:
import React, { forwardRef, useRef, useImperativeHandle } from "react";
import { View, Text, Image } from "react-native";
import { Camera, useCameraDevices } from "react-native-vision-camera";
const CameraScreen = forwardRef((props, ref) => {
useImperativeHandle(ref, () => ({
//暴露可供父组件调用函数的hooks
takePhoto,
takeVideoStart,
takeVideoStop,
}));
const camera = useRef(null);
const devices = useCameraDevices();
const device = devices.back; //默认后置摄像