Focus/blur

This commit is contained in:
Diego Mello 2020-05-28 10:14:20 -03:00
parent 4f010e5e37
commit 452620c02c
4 changed files with 20 additions and 11 deletions

View File

@ -183,7 +183,7 @@ class MessageBox extends Component {
EventEmiter.addEventListener(KEY_COMMAND, this.handleCommands); EventEmiter.addEventListener(KEY_COMMAND, this.handleCommands);
} }
this.didFocusListener = navigation.addListener('didFocus', () => { this.unsubscribeFocus = navigation.addListener('focus', () => {
if (this.tracking && this.tracking.resetTracking) { if (this.tracking && this.tracking.resetTracking) {
this.tracking.resetTracking(); this.tracking.resetTracking();
} }
@ -268,8 +268,8 @@ class MessageBox extends Component {
if (this.getSlashCommands && this.getSlashCommands.stop) { if (this.getSlashCommands && this.getSlashCommands.stop) {
this.getSlashCommands.stop(); this.getSlashCommands.stop();
} }
if (this.didFocusListener && this.didFocusListener.remove) { if (this.unsubscribeFocus) {
this.didFocusListener.remove(); this.unsubscribeFocus();
} }
if (isTablet) { if (isTablet) {
EventEmiter.removeListener(KEY_COMMAND, this.handleCommands); EventEmiter.removeListener(KEY_COMMAND, this.handleCommands);

View File

@ -83,7 +83,7 @@ class RoomInfoView extends React.Component {
} }
const { navigation } = this.props; const { navigation } = this.props;
this.willFocusListener = navigation.addListener('focus', () => { this.unsubscribeFocus = navigation.addListener('focus', () => {
if (this.isLivechat) { if (this.isLivechat) {
this.loadVisitor(); this.loadVisitor();
} }
@ -94,8 +94,8 @@ class RoomInfoView extends React.Component {
if (this.subscription && this.subscription.unsubscribe) { if (this.subscription && this.subscription.unsubscribe) {
this.subscription.unsubscribe(); this.subscription.unsubscribe();
} }
if (this.willFocusListener) { if (this.unsubscribeFocus) {
this.willFocusListener(); this.unsubscribeFocus();
} }
} }

View File

@ -57,7 +57,7 @@ class List extends React.Component {
animated: false animated: false
}; };
this.init(); this.init();
this.didFocusListener = props.navigation.addListener('didFocus', () => { this.unsubscribeFocus = props.navigation.addListener('focus', () => {
if (this.mounted) { if (this.mounted) {
this.setState({ animated: true }); this.setState({ animated: true });
} else { } else {
@ -163,8 +163,8 @@ class List extends React.Component {
if (this.onEndReached && this.onEndReached.stop) { if (this.onEndReached && this.onEndReached.stop) {
this.onEndReached.stop(); this.onEndReached.stop();
} }
if (this.didFocusListener && this.didFocusListener.remove) { if (this.unsubscribeFocus) {
this.didFocusListener.remove(); this.unsubscribeFocus();
} }
console.countReset(`${ this.constructor.name }.render calls`); console.countReset(`${ this.constructor.name }.render calls`);
} }

View File

@ -61,8 +61,8 @@ class ShareListView extends React.Component {
serverInfo: null serverInfo: null
}; };
this.setHeader(); this.setHeader();
this.didFocusListener = props.navigation.addListener('didFocus', () => BackHandler.addEventListener('hardwareBackPress', this.handleBackPress)); this.unsubscribeFocus = props.navigation.addListener('focus', () => BackHandler.addEventListener('hardwareBackPress', this.handleBackPress));
this.willBlurListener = props.navigation.addListener('willBlur', () => BackHandler.addEventListener('hardwareBackPress', this.handleBackPress)); this.unsubscribeBlur = props.navigation.addListener('blur', () => BackHandler.addEventListener('hardwareBackPress', this.handleBackPress));
} }
componentDidMount() { componentDidMount() {
@ -129,6 +129,15 @@ class ShareListView extends React.Component {
return false; return false;
} }
componentWillUnmount() {
if (this.unsubscribeFocus) {
this.unsubscribeFocus();
}
if (this.unsubscribeBlur) {
this.unsubscribeBlur();
}
}
setHeader = () => { setHeader = () => {
const { searching } = this.state; const { searching } = this.state;
const { navigation, theme } = this.props; const { navigation, theme } = this.props;