react-native-camera/docs/react-navigation.md
Ronaldo Lima 54b03328b1 feat(docs): Add docusaurus (#2293)
* initial bootstrap on documentation

* Add EXPO_USAGE and MIgrating page

* add all pages

* add sponsors section to index

* theme

* configs

* clipboard button

* remove blog from docker

* start API.md

* minor updates
2019-06-02 16:20:35 -03:00

1002 B

id title sidebar_label
react-navigation React Navigation React Navigation

React-navigation does not unmount components when switching between tabs. So when you leave and return back to the screen with the camera component it will just be black view. So a good solution is to use componentDidMount and added two listeners willFocus and willBlur to help you mount and unmount the views.

componentDidMount() {
   const { navigation } = this.props;
   navigation.addListener('willFocus', () =>
     this.setState({ focusedScreen: true })
   );
   navigation.addListener('willBlur', () =>
     this.setState({ focusedScreen: false })
   );
 }

 render() {
   const { hasCameraPermission, focusedScreen } = this.state;
   if (hasCameraPermission === null) {
     return <View />;
   } else if (hasCameraPermission === false) {
     return <Text>No access to camera</Text>;
   } else if (focusedScreen){
     return (this.cameraView());
   } else {
     return <View />;
   }
 }