[英]React Native - camera.getSupportedRatiosAsync() is not a function
Writing a React Native app using the expo-camera
library.使用
expo-camera
库编写一个 React Native 应用程序。 I need to match a supported aspect ratio of the camera to the screen size but the getSupportedRatiosAsync()
function from the expo-camera documentation is returning this error:我需要将相机支持的纵横比与屏幕尺寸相匹配,但来自expo-camera 文档的
getSupportedRatiosAsync()
function 返回此错误:
[Unhandled promise rejection: TypeError: camera.getSupportedRatiosAsync is not a function. (In 'camera.getSupportedRatiosAsync()', 'camera.getSupportedRatiosAsync' is undefined)]
Stack trace:
node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:63:36 in tryCatch
node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:293:29 in invoke
node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:63:36 in tryCatch
node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:154:27 in invoke
node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:164:18 in PromiseImpl.resolve.then$argument_0
node_modules/react-native/node_modules/promise/setimmediate/core.js:37:13 in tryCallOne
node_modules/react-native/node_modules/promise/setimmediate/core.js:123:24 in setImmediate$argument_0
node_modules/react-native/Libraries/Core/Timers/JSTimers.js:130:14 in _callTimer
node_modules/react-native/Libraries/Core/Timers/JSTimers.js:181:14 in _callImmediatesPass
node_modules/react-native/Libraries/Core/Timers/JSTimers.js:441:30 in callImmediates
node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:387:6 in __callImmediates
node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:135:6 in __guard$argument_0
node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:364:10 in __guard
node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:134:4 in flushedQueue
[native code]:null in flushedQueue
[native code]:null in invokeCallbackAndReturnFlushedQueue
...
Here's a minimal example of the code:这是代码的最小示例:
import React from 'react';
import { Camera } from 'expo-camera';
import * as Permissions from 'expo-permissions';
export default class RecordingScreen extends React.Component {
camera = null;
state = {
hasCameraPermission: null,
camRatio: "16:9"
};
async componentDidMount() {
const camera = await Permissions.askAsync(Permissions.CAMERA);
const audio = await Permissions.askAsync(Permissions.AUDIO_RECORDING);
const hasCameraPermission = (camera.status === 'granted' && audio.status === 'granted');
this.setState({ hasCameraPermission });
const camRatios = await camera.getSupportedRatiosAsync();
};
render() {
//Rendering code here
};
};
Has this function been deprecated?这个 function 是否已被弃用? Should I be importing it differently?
我应该以不同的方式导入它吗?
It seems that expo-camera
creates a this.camera
implicitly which can be used to call this function: const camRatios = await this.camera.getSupportedRatiosAsync();
似乎
expo-camera
隐式创建了一个this.camera
可以用来调用这个 function: const camRatios = await this.camera.getSupportedRatiosAsync();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.