Expo Camera预览组件开始以黑屏显示黑屏 [英] Expo Camera preview component started displaying black screen out of the blue

查看:171
本文介绍了Expo Camera预览组件开始以黑屏显示黑屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

npm包"expo-camera"中的相机预览"组件只显示黑屏,什么都没有显示.我什至创建了一个全新的托管Expo项目,仅此代码:

  import从'react'导入React;从'react-native'导入{StyleSheet,Text,View};从"expo-camera"导入{Camera};导出默认函数App(){返回 (<查看样式= {styles.container}><相机/></View>);}const styles = StyleSheet.create({容器: {弹性:1,backgroundColor:#fff",alignItems:'中心',justifyContent:中心",},}); 

这是我的package.json文件:

  {"main":"node_modules/expo/AppEntry.js",脚本":{"start":博览会开始","android":"expo start --android","ios":"expo start --ios","web":"expo start --web","eject":展览会弹出"},依赖关系":{"expo":"^ 35.0.0","expo-camera":"^ 7.0.0","react":"16.8.3","react-dom":"16.8.3","react-native":"https://github.com/expo/react-native/archive/sdk-35.0.0.tar.gz","react-native-web":"^ 0.11.7"},"devDependencies":{"babel-preset-expo":"^ 7.1.0"},私人":true} 

这是我的app.json:

  {博览会":{"name":"testcamera","slug":"testcamera","privacy":"public","sdkVersion":"35.0.0",平台":["ios",安卓",网络"],"version":"1.0.0","orientation":肖像","icon":"./assets/icon.png",飞溅":{"image":"./assets/splash.png","resizeMode":包含","backgroundColor":"#ffffff"},更新": {"fallbackToCacheTimeout":0},"assetBundlePatterns":["**/*"],"ios":{"supportsTablet":true}}} 

它只是突然停止工作.我做的最后一件事是发布Expo项目,并且在此之前就可以了.

解决方案

带有钩子和功能组件的工作示例,请求权限:

https://snack.expo.io/@djalik/camera

The Camera preview component from the npm package 'expo-camera' doesn't show anything but a black screen. I've even created a brand new managed Expo project with nothing but this code:

import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { Camera } from 'expo-camera';

export default function App() {
  return (
    <View style={styles.container}>
      <Camera />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

This is my package.json file:

{
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject"
  },
  "dependencies": {
    "expo": "^35.0.0",
    "expo-camera": "^7.0.0",
    "react": "16.8.3",
    "react-dom": "16.8.3",
    "react-native": "https://github.com/expo/react-native/archive/sdk-35.0.0.tar.gz",
    "react-native-web": "^0.11.7"
  },
  "devDependencies": {
    "babel-preset-expo": "^7.1.0"
  },
  "private": true
}

And this is my app.json:

{
  "expo": {
    "name": "testcamera",
    "slug": "testcamera",
    "privacy": "public",
    "sdkVersion": "35.0.0",
    "platforms": [
      "ios",
      "android",
      "web"
    ],
    "version": "1.0.0",
    "orientation": "portrait",
    "icon": "./assets/icon.png",
    "splash": {
      "image": "./assets/splash.png",
      "resizeMode": "contain",
      "backgroundColor": "#ffffff"
    },
    "updates": {
      "fallbackToCacheTimeout": 0
    },
    "assetBundlePatterns": [
      "**/*"
    ],
    "ios": {
      "supportsTablet": true
    }
  }
}

It just stopped working out of the blue. Last thing I did was publish the Expo project, and it was working before that.

解决方案

Working example with hook and functional component, request permissions:

https://snack.expo.io/@djalik/camera

这篇关于Expo Camera预览组件开始以黑屏显示黑屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆