0

expo-camera使用该库编写 React Native 应用程序。我需要将受支持的相机纵横比与屏幕尺寸相匹配,但expo-camera 文档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
    };
};

此功能是否已弃用?我应该以不同的方式导入它吗?

4

1 回答 1

0

似乎隐式地expo-camera创建了一个this.camera可用于调用此函数的函数: const camRatios = await this.camera.getSupportedRatiosAsync();

于 2021-03-19T17:04:30.373 回答