Skip to content

Commit

Permalink
Proposal Issue 9407
Browse files Browse the repository at this point in the history
  • Loading branch information
JosueEchandiaAsto committed Jun 14, 2022
1 parent 0a33d88 commit 6f988d6
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/pages/iou/steps/IOUAmountPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import {
View,
InteractionManager,
AppState,
} from 'react-native';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
Expand Down Expand Up @@ -54,6 +55,7 @@ const defaultProps = {
};

class IOUAmountPage extends React.Component {

constructor(props) {
super(props);

Expand All @@ -65,11 +67,13 @@ class IOUAmountPage extends React.Component {

this.state = {
amount: props.selectedAmount,
appState: AppState.currentState,
};
}

componentDidMount() {
this.focusTextInput();
this.addAppStateSubscription();
}

componentDidUpdate(prevProps) {
Expand All @@ -80,6 +84,10 @@ class IOUAmountPage extends React.Component {
this.focusTextInput();
}

componentWillUnmount(){
this.appStateSubscription.remove();
}

/**
* Focus text input
*/
Expand All @@ -96,6 +104,25 @@ class IOUAmountPage extends React.Component {
});
}

/**
* Add EventListener of AppState
*/
addAppStateSubscription(){
this.appStateSubscription = AppState.addEventListener(
"change",
nextAppState => {
if (
this.state.appState.match(/inactive|background/) &&
nextAppState === "active"
) {
//App has come to the foreground!
this.focusTextInput();
}
this.setState({ appState: nextAppState });
},
);
}

/**
* @param {String} amount
* @returns {Number}
Expand Down

0 comments on commit 6f988d6

Please sign in to comment.