My goal is to use the react-native-camera and simply show a picture on the same screen, if a picture has been taken. I'm trying to save the picture source as "imageURI". If it exists, I want to show it, if a picture hasn't been taken yet, just show text saying No Image Yet. I've got the camera working, since I can trace the app is saving pictures to the disk. Having trouble with the following:
- How to assign the capture functions data to a variable when I take the picture, that I can call later (imageURI).
Don't know how to do an if statement in Javascript to check if a variable exists yet.
import Camera from 'react-native-camera'; export default class camerahere extends Component { _takePicture () { this.camera.capture((err, data) => { if (err) return; imageURI = data; }); } render() { if ( typeof imageURI == undefined) { image = <Text> No Image Yet </Text> } else { image = <Image source={{uri: imageURI, isStatic:true}} style={{width: 100, height: 100}} /> } return ( <View style={styles.container}> <Camera captureTarget={Camera.constants.CaptureTarget.disk} ref={(cam) => { this.camera = cam; }} style={styles.preview} aspect={Camera.constants.Aspect.fill}> {button} <TouchableHighlight onPress={this._takePicture.bind(this)}> <View style={{height:50,width:50,backgroundColor:"pink"}}></View> </TouchableHighlight> </Camera>