import React from 'react';
import { Button, ScrollView, View, Text } from 'react-native';
import { withNavigation } from '@react-navigation/core';
import { Themed } from '@react-navigation/native';
import { createStackNavigator } from 'react-navigation-stack';
const getColorOfEvent = evt => {
switch (evt) {
case 'willFocus':
return 'purple';
case 'didFocus':
return 'blue';
case 'willBlur':
return 'brown';
default:
return 'black';
}
};
class FocusTagWithNav extends React.Component {
state = { mode: 'didBlur' };
componentDidMount() {
this.props.navigation.addListener('willFocus', () => {
this.setMode('willFocus');
});
this.props.navigation.addListener('willBlur', () => {
this.setMode('willBlur');
});
this.props.navigation.addListener('didFocus', () => {
this.setMode('didFocus');
});
this.props.navigation.addListener('didBlur', () => {
this.setMode('didBlur');
});
}
setMode = mode => {
if (!this._isUnmounted) {
this.setState({ mode });
}
};
componentWillUnmount() {
this._isUnmounted = true;
}
render() {
const key = this.props.navigation.state.key;
return (
{key} {String(this.state.mode)}
);
}
}
const FocusTag = withNavigation(FocusTagWithNav);
class SampleScreen extends React.Component {
static navigationOptions = ({ navigation }) => ({
title: 'Lorem Ipsum',
headerRight: navigation.getParam('nextPage') ? (