首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在ClojureScript重新开发中使用react-native-camera

在ClojureScript重新开发中使用react-native-camera
EN

Stack Overflow用户
提问于 2018-01-04 06:29:48
回答 1查看 580关注 0票数 3

有没有人用过'react-native-camera‘组件和react?

我只是在默认的react框架项目中尝试使用react-native-camera组件。

我的代码如下

代码语言:javascript
复制
(ns wmshandheld.android.core
  (:require [reagent.core :as r :refer [atom]]
            [re-frame.core :refer [subscribe dispatch dispatch-sync]]
            [wmshandheld.events]
            [wmshandheld.subs]))

(def ReactNative (js/require "react-native"))
(def ReactNativeCamera (js/require "react-native-camera"))

(def app-registry (.-AppRegistry ReactNative))
(def camera (.-Camera ReactNativeCamera))
(def text (r/adapt-react-class (.-Text ReactNative)))
(def view (r/adapt-react-class (.-View ReactNative)))
(def touchable-highlight (r/adapt-react-class (.-TouchableHighlight ReactNative)))

(defn alert [title]
  (.alert (.-Alert ReactNative) title))

(defn app-root []
  (fn []
    [view {:style {:flex-direction "column" :margin 40 :align-items "center"}}
     [camera {:ref    (fn [cam]
                        (this-as this
                          (set! (.-camera this) cam)))
              :style  {:flex 1 :justify-content "flex-end" :align-items "center"}
              :aspect (.-fill (.-Aspect (.-constants camera)))}
      [text {:style {:flex          0 :background-color "#fff"
                     :border-radius 5 :color "#000"
                     :padding       10 :margin 40}
             :on-press #(alert "HELLO!")}
       "[CAPTURE]"]]]))

(defn init []
      (dispatch-sync [:initialize-db])
      (.registerComponent app-registry "WMSHandheld" #(r/reactify-component app-root)))

但是我得到了这样一个错误。

代码语言:javascript
复制
console.error: "Error rendering component (in wmshandheld.android.core.app_root)"
error
    YellowBox.js:71:16
finishClassComponent
    ReactNativeFiber-dev.js:1667:86
updateClassComponent
    ReactNativeFiber-dev.js:1659:33
beginWork
    ReactNativeFiber-dev.js:1786:44
performUnitOfWork
    ReactNativeFiber-dev.js:2528:33
workLoop
    ReactNativeFiber-dev.js:2554:141
_invokeGuardedCallback
    ReactNativeFiber-dev.js:73:23
invokeGuardedCallback
    ReactNativeFiber-dev.js:47:40
performWork
    ReactNativeFiber-dev.js:2593:41
scheduleUpdateImpl
    ReactNativeFiber-dev.js:2728:101
scheduleUpdate
    ReactNativeFiber-dev.js:2711:38
enqueueSetState
    ReactNativeFiber-dev.js:1514:90
setState
    react.development.js:218:31
<unknown>
    figwheel-bridge.js:88:33
waitForFinalEval
    figwheel-bridge.js:197:21
<unknown>
    figwheel-bridge.js:28:17
fireEvalListenters
    figwheel-bridge.js:27:41
<unknown>
    figwheel-bridge.js:118:24
tryCallOne
    core.js:37:14
<unknown>
    core.js:123:25
<unknown>
    JSTimers.js:301:23
_callTimer
    JSTimers.js:154:6
_callImmediatesPass
    JSTimers.js:202:17
callImmediates
    JSTimers.js:470:11
__callImmediates
    MessageQueue.js:278:4
<unknown>
    MessageQueue.js:145:6
__guard
    MessageQueue.js:265:6
flushedQueue
    MessageQueue.js:144:17
callFunctionReturnFlushedQueue
    MessageQueue.js:119:11

有人知道问题出在哪里吗?如何解决这个问题?在github或gist上使用react-native-camera的一个简单的工作示例将是完美的!

EN

回答 1

Stack Overflow用户

发布于 2018-12-12 14:01:37

如果这有帮助,这是我至少可以让相机在模拟器中显示的方法。我还没有粘贴完整的代码,但是通过在应用根目录中使用[view camera- component ],模拟器显示了后置摄像头组件。希望这能有所帮助

代码语言:javascript
复制
(def ReactNativeCamera (js/require "react-native-camera"))
(def camera (r/adapt-react-class (.-RNCamera ReactNativeCamera)))


(defn camera-component
  []
  (let data {}]
   (fn []
      [view
       [text "hello"]

       [camera {
                :ref (fn [cam] (this-as this (set! (.-Camera this) cam)))
                :style {:flex 1 :justify-content "flex-end" :align-items "center" :border-color "black" :border-width 1 :min-height "10%"}
                :type (-> ReactNativeCamera .-RNCamera .-Constants .-Type .-back)
                :permission-dialog-title "Permission to use camera"
                :permission-dialog-message "Need permission to use camera on your phone"}]])))
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48086114

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档