0

I am using react-native-camera and when I open it I cant go back with the hardware button, so I decided to create a button EXIT so when user clicks on it should go back to the previous view. The problem is that I am only using one class! so how can I navigate to the same class but different view?

Here is the way I tried:

import { createStackNavigator, createAppContainer } from "react-navigation";

<View style={styles.barcode_bottomOverlay}>
                    <TouchableOpacity onPress={() => this.props.navigation.navigate('ThisPage', { data })}>
                        <Text>Exit</Text>
                    </TouchableOpacity>

1 Answers1

0

You may have conditionnal rendering on state variable. and just make a setState when user click exit button ?

constructor(props) {
    super(props);
    this.state = {
      showCameraView : true,
    };
  }
 render() {
    if(this.state.showCameraView) {
        return <CameraViewComponentWithExitButton />
    }

    return <OtherElementsToDisplay />
  }