首页 > 解决方案 > 升级到 Expo 42(从 39)(React Native)后原生相机渲染损坏

问题描述

我正在使用本机相机(iOS/Android)调用如下:

  async function takePhoto() {
    const photo = await ImagePicker.launchCameraAsync(cameraOptions);
    if (photo.cancelled) {
      return '';
    }
    return photo.uri;
  }

自从从 Expo 39 升级到 42 后,它就坏了(见截图)

人像 风景

在我看来,它正在以模式打开。我不知道在哪里改变这个。

预期行为:在 iOS 下全屏显示相机作为本机相机

更新:20210730:同时它已作为错误/问题打开: https ://github.com/expo/expo/issues/13614

任何想法,建议 - 特别是在解决方法方面?

非常感谢。

标签: iosreact-nativeexpo

解决方案


我已经完成了从 EXPO SDK 37 到 EXPO SDK 42 的大规模升级。不得不改变很多关于相机、位置和权限的事情。

使用以下内容时我没有遇到这种行为(我看不到您的导入语句或您的包版本,但这是我已经实现的并且没有遇到任何问题)


// Import statements...
import * as ImagePicker from 'expo-image-picker';
import * as FileSystem from 'expo-file-system';
import { Camera } from 'expo-camera';

// Code within Component
    const takePicture = async () => {

        // You MUST ask for permissions first.
        const permissions = {
            [Camera]: await Camera.requestPermissionsAsync()
        };

        // If denied let the user know its required.
        if (permissions[Camera].status !== 'granted') {
            return Promise.reject(new Error('Camera Permission Required'));
        }

        // Then let them launch the camera and perform any other task
        await ImagePicker.launchCameraAsync({
            allowsEditing: false
        })
        .then(({ uri }) => imageProcesser(uri))
        .then(res => onImageAdded(res))
        .catch((e) => console.log(e));
    };

// These are my concerning package versions
 "expo-camera": "^11.2.2"
 "expo-file-system": "~11.1.3",
 "expo-image-picker": "~10.2.2",
 "expo": "^42.0.3"

推荐阅读