我正在尝试编写以下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
我做错了什么?