我正在将我的相机作为一个功能组件做出反应,但文档说
要使用 Camera 公开的方法,必须创建一个组件
ref并使用它来调用它们。
但在反应文档中,它说我不能ref在功能组件中使用。
如果这与useRef? 我正在尝试让相机拍照并将其保存到我的手机内存中。
<Camera
style={{ flex: 1 }}
type={type}
useCamera2Api={true}
ratio={"16:9"}
//to take a picture
ref={ref => {
this.camera = ref;
}}
>
Run Code Online (Sandbox Code Playgroud)
...
<TouchableOpacity
style={{
alignSelf: 'flex-end',
alignItems: 'center',
backgroundColor: 'transparent',
}}
onPress={() => async () => {
if (this.camera) {
let photo = await this.camera.takePictureAsync();
}}
>
<FontAwesome
name="camera"
style={{ color: "#fff", fontSize: 40 }}
/>
</TouchableOpacity>
Run Code Online (Sandbox Code Playgroud) 试图减少任何变化的变量并使用我的代码的新拉取。它们不是node-module包或package-lock.json. 我运行npm install我得到这个错误:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: undefined@undefined
npm ERR! Found: react-native-screens@2.15.2
npm ERR! node_modules/react-native-screens
npm ERR! react-native-screens@"~2.15.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react-native-screens@"^1.0.0 || ^1.0.0-alpha" from react-navigation-drawer@1.4.0
npm ERR! node_modules/react-navigation-drawer
npm ERR! react-navigation-drawer@"^1.4.0" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm …Run Code Online (Sandbox Code Playgroud)