使用expo-camera库编写React Native应用程序。我需要匹配支持的摄像头宽高比和屏幕尺寸,但是来自the expo-camera documentation的getSupportedRatiosAsync()函数返回这个错误:
[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
...下面是一个最小的代码示例:
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
};
};此函数是否已弃用?我应该以不同的方式导入它吗?
发布于 2021-03-20 01:04:30
看起来expo-camera隐式地创建了一个this.camera,它可以用来调用这个函数:const camRatios = await this.camera.getSupportedRatiosAsync();
https://stackoverflow.com/questions/66712172
复制相似问题