React Native Expo Camera Preview没有显示

时间:2018-10-24 14:13:27

标签: react-native camera expo

我是React Native的新手,我想实现Expo的相机组件以使用它,我遵循了文档中给出的教程,但对我而言不起作用。这是我在Camera js文件中使用的代码:

use Closure;

class Cors {

public function handle($request, Closure $next)
{

    header("Access-Control-Allow-Origin: *");

    // ALLOW OPTIONS METHOD
    $headers = [
        'Access-Control-Allow-Methods'=> 'POST, GET, OPTIONS, PUT, DELETE',
        'Access-Control-Allow-Headers'=> 'Content-Type, X-Auth-Token, Origin'  
    ];
    if($request->getMethod() == "OPTIONS") {
        // The client-side application can set only headers allowed in Access-Control-Allow-Headers
        return Response::make('OK', 200, $headers);
    }

    $response = $next($request);
    foreach($headers as $key => $value)
        $response->header($key, $value);
    return $response;
}

}

并使用native-base将其添加到App.js中的render方法中:

array:1 [▼
  "draws" => Collection {#236 ▼
    #items: array:8 [▼
      0 => Draw {#237 ▼
        #connection: "mysql"
        #table: null
        #primaryKey: "id"
        #keyType: "int"
        +incrementing: true
        #with: []
        #withCount: []
        #perPage: 15
        +exists: true
        +wasRecentlyCreated: false
        #attributes: array:4 [▶]
        #original: array:4 [▶]
        #changes: []
        #casts: []
        #dates: []
        #dateFormat: null
        #appends: []
        #dispatchesEvents: []
        #observables: []
        #relations: []
        #touches: []
        +timestamps: true
        #hidden: []
        #visible: []
        #fillable: []
        #guarded: array:1 [▶]
      }
      1 => Draw {#238 ▶}
      2 => Draw {#239 ▶}
      3 => Draw {#240 ▶}
      4 => Draw {#241 ▶}
      5 => Draw {#242 ▶}
      6 => Draw {#243 ▶}
      7 => Draw {#244 ▶}
    ]
  }
]

可能是什么问题?我似乎无法理解为什么相机预览未显示在应用程序中,而我坚持这样做。任何帮助表示赞赏。

2 个答案:

答案 0 :(得分:1)

相反:const { status } = await Permissions.askAsync(Permissions.CAMERA); 试试这个:

import * as Permissions from "expo-permissions";
...
const { status } = await Permissions.askAsync(Permissions.CAMERA);

答案 1 :(得分:0)

尝试提供一个height参数而不是flex参数,flex对我也不起作用。

<Camera type={this.state.type} style={{height: 300}}/>

这不是一个好的解决方案,但是看到问题在于样式是有问题的。