【发布时间】:2020-03-10 21:39:23
【问题描述】:
我正在尝试编写以下js代码,用于在re-natal中使用react-native-camera拍照:
<RNCamera
ref={ref => {
this.camera = ref;
}}
style={styles.preview}
type={RNCamera.Constants.Type.back}
flashMode={RNCamera.Constants.FlashMode.on}
/>
<View style={{ flex: 0, flexDirection: 'row', justifyContent: 'center' }}>
<TouchableOpacity onPress={this.takePicture.bind(this)} style={styles.capture}>
<Text style={{ fontSize: 14 }}> SNAP </Text>
</TouchableOpacity>
</View>
takePicture = async() => {
if (this.camera) {
const options = { quality: 0.5, base64: true };
const data = await this.camera.takePictureAsync(options);
console.log(data.uri);
}
};
我有以下 clojurescript 代码:
(defn take-picture [camera]
(go (let [picture (<! (.takePictureAsync camera {:quality 0.5 :base-64 true}))]
(prn "uri is " (.-uri picture))
)))
(defn camera- []
(fn []
[safe-area-view
[camera {
:ref (fn [cam] (this-as this (set! (.-Camera this) cam)))
:style {:width 500 :height 500 :justify-content "flex-end" :align-items "center" :border-color "black" :min-height "10%"}
:type (-> ReactNativeCamera .-RNCamera .-Constants .-Type .-back)
}]
[view {:style {:justify-content "center"}}
[touchable-opacity {:on-press take-picture
:style {:margin 5 :background-color "#999" :padding 10 :border-radius 5}
}
[text "Take Pic"]
]]
]))
但是在点击触发拍照功能的可触摸不透明度时,我收到以下错误:camera.takePictureAsync is not a function
我做错了什么?
【问题讨论】:
-
如果 console.log 是相机变量,你会得到什么?这可以给你提示
-
(prn camera) 给出#object[Class [object Object]],但是当我这样做时(js/console.log camera),应用程序冻结。
-
嗯......这肯定是 clojure :( 我看到可疑的是你从哪里得到那个相机对象 :| 也许 :on-press 应该有一个调用拍照和传递的内联函数ref 对象,你应该看看你是如何传递那个 ref
标签: react-native clojurescript react-native-camera re-natal