title: React-navigation's TabNavigator - detect when tab is going out of the screen
body: <p>I'm working on a React Native app with 3 tabs. Since I'm presenting a camera feed in one of them I need to know when it's going out of the screen just to stop it. Since <code>componentWillUnmount</code> and <code>componentDidUnmount</code> are not called in this situation, I tried to use the <code>tabBarOnPress</code>. However if I'm in e.g. Tab1 screen, I can detect only clicks on the first Tab screen. So I'm able to detect when the screen receives focus, but I can't detect when it loses it. How can I achieve this? </p>
  
  <p>This is what I already tried to do: </p>
  
  <pre><code>export const MyApp = TabNavigator({
    First: {
      screen: FirstTab
    },
    Second: {
      screen: SecondTab
    },
    Third: {
      screen: ThirdTab
    }},
    {
      tabBarPosition: 'bottom',
      swipeEnabled: false,
      backBehavior: 'none',
      animationEnabled: true,
      lazy: true,
      tabBarOptions: {
        activeTintColor: 'blue',
        inactiveTintColor: 'black',
        style: {
          backgroundColor: 'white'
        },
        indicatorStyle: {
          backgroundColor: 'white'
        }
      },
      navigationOptions: ({ navigation }) =&gt; ({
              tabBarOnPress: (scene, jumpToIndex) =&gt; {
                  if (typeof navigation.state.params.updateState!=="undefined"){
                        navigation.state.params.updateState();
                      }
              },
          }),
    }
  );
  
  
  export default class First extends Component {
  
    constructor(props) {
      super(props);
    }
  
    componentDidMount() {
      this.props.navigation.setParams({
        updateState: this.updateState
      })
    }
  
    updateState=()=&gt;{
      Alert.alert('state updated')
    }
  
  }
  </code></pre>
  
  <p>Unfortunately this still calls <code>updateState()</code> only when touching the first tab. When touching other tabs I get this error:
  <a href="https://i.stack.imgur.com/JAcnh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JAcnh.png" alt="error screenshot"></a></p>