I am trying to use the camera for a rect native app using 'react-native-camera'. I keep getting the following error when I'm trying to navigate to the camera screen.
Here's my code:
import React,{Component} from 'react';
import {SafeAreaView,StyleSheet,TouchableOpacity,TextInput,View,Text,StatusBar,Image} from 'react-native';
import {createAppContainer} from 'react-navigation';
import {createStackNavigator} from 'react-navigation-stack';
import UserMainScreen from './UserMainScreen.js';
import Camera from 'react-native-camera';
import {RNCamera} from 'react-native-camera';
class CameraScreen extends Component{
render(){
return(
<View style={cam_styles.container}>
<Camera ref={cam=>{this.camera = cam;}} style={cam_styles.preview} aspect = {Camera.constants.Aspect.fill}>
<Text style={cam_styles.capture} onPress={this.takePicture.bind(this)}>[CAPTURE]</Text>
</Camera>
</View>
);
}
takePicture(){
const options ={};
this.camera.capture({metadata: options})
.then(data=>console.log(data))
.catch(error=>console.log(error));
}
}
const cam_styles = StyleSheet.create({
container: {
flex:1,
flexDirection: 'row',
},
preview:{
flex:1,
justifyContent: 'flex-end',
alignItems:'center'
},
capture:{
flex:0,
backgroundColor: '#fff',
borderRadius: 5,
color:'#000',
padding:10,
margin:40
}
});
const MainNavigator = createStackNavigator({
Home: UserMainScreen,
Login : LoginScreen,
Camera : CameraScreen,
},
{
initialRouteName: 'Login',
headerMode: 'none',
}
);
const AppContainer = createAppContainer(MainNavigator);
class Login extends Component{
render (){
return (
<AppContainer />
);
}
}
export default Login;
This is the error I keep getting.I tried removing the aspect attribute but I get a Invariant Violation: Element type is invalid: expected a string (for built-in components) or class/function but got undefined. Check the render method of CameraScreen
With my current code this is the error log I get. How do I solve this?
TypeError: undefined is not an object (evaluating '_reactNativeCamera.Camera.constants')
This error is located at:
in CameraScreen (at SceneView.js:9)
in SceneView (at StackViewLayout.tsx:900)
in RCTView (at createAnimatedComponent.js:151)
in AnimatedComponent (at StackViewCard.tsx:106)
in RCTView (at createAnimatedComponent.js:151)
in AnimatedComponent (at screens.native.js:71)
in Screen (at StackViewCard.tsx:93)
in Card (at createPointerEventsContainer.tsx:95)
in Container (at StackViewLayout.tsx:975)
in RCTView (at screens.native.js:101)
in ScreenContainer (at StackViewLayout.tsx:384)
in RCTView (at createAnimatedComponent.js:151)
in AnimatedComponent (at StackViewLayout.tsx:374)
in PanGestureHandler (at StackViewLayout.tsx:367)
in StackViewLayout (at withOrientation.js:30)
in withOrientation (at StackView.tsx:104)
in RCTView (at Transitioner.tsx:267)
in Transitioner (at StackView.tsx:41)
in StackView (at createNavigator.js:80)
in Navigator (at createKeyboardAwareNavigator.js:12)
in KeyboardAwareNavigator (at createAppContainer.js:430)
in NavigationContainer (at Login.js:97)
in Login
in RCTView (at AppContainer.js:101)
in RCTView (at AppContainer.js:119)
in AppContainer (at renderApplication.js:39)
CameraScreen#render
Login.js:42:100
renderRoot
[native code]:0
runRootCallback
[native code]:0
unstable_runWithPriority
scheduler.development.js:643:23
callFunctionReturnFlushedQueue
[native code]:0