use strict';
import React, { Component } from 'react';
import {
AppRegistry,
Dimensions,
StyleSheet,
Text,
TouchableHighlight,
View
} from 'react-native';
import Camera from 'react-native-camera';
class BadInstagramCloneApp extends Component {
render() {
return (
<View style={styles.container}>
<Camera
ref={(cam) => {
this.camera = cam;
}}
style={styles.preview}
aspect={Camera.constants.Aspect.fill}>
<Text style={styles.capture} onPress={this.takePicture.bind(this)}>[CAPTURE]</Text>
</Camera>
</View>
);
}
takePicture() {
this.camera.capture()
.then((data) => console.log(data))
.catch(err => console.error(err));
}
}
const styles = StyleSheet.create({
container: {
flex: 1
},
preview: {
flex: 1,
justifyContent: 'flex-end',
alignItems: 'center',
height: Dimensions.get('window').height,
width: Dimensions.get('window').width
},
capture: {
flex: 0,
backgroundColor: '#fff',
borderRadius: 5,
color: '#000',
padding: 10,
margin: 40
}
});
AppRegistry.registerComponent('AwesomeProject',() => BadInstagramCloneApp);
我用下面的步骤来解决问题: 删除node_modules文件夹 - 室射频node_modules & & NPM安装 复位打包缓存 - RM -fr $ TMPDIR/react- *或node_modules /react-native/packager/packager.sh --reset-cache 清除守卫员手表 - 守望员手表全部删除 从零开始重新创建项目 但我仍然收到错误消息。反应机摄像头未定义
你配置了'反应,本机camera'组件的本机端? –