You can do something like this using the reference:
<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>
takePicture() {
this.Camera.capture()
.then((data) => console.log(data))
.catch(err => console.error(err));
}
ref
returns a reference to the component. In the above example you are storing reference of the component Camera
in this.Camera
( you can name it whatever like this.xyz
or whatever). Now you can access all the methods of Camera
component using this.Camera
. In the above example capture
is a method of Camera
component and you can call it like this this.Camera.capture()
.
You can think of it like this, for easier understanding:
Camera = { // your <Camera /> component
capture: function(){ console.log('CAPTURE')}
}
myCamera = Camera // ref is doing something like this("myCamera" replaces "this.Camera", "Camera" replaces 'cam" )
myCamera.capture() // now you can call methods of Camera Object