Skip to content

Commit

Permalink
Refocus input based on nav index instead of willFocus event
Browse files Browse the repository at this point in the history
The willFocus event by the navigator doesn't work properly (it doesn't
fire when screen has been navigated to) so use the nav index from state
instead to refocus the text input.
  • Loading branch information
timothyej committed Jan 3, 2020
1 parent f2eabe5 commit 3e016f0
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/screens/CreatePineAddressScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ const styles = StyleSheet.create({
defaultPineAddressHostname: state.settings.defaultPineAddressHostname,
pineAddressHostname: state.settings.pineAddressHostname,
bitcoinNetwork: state.settings.bitcoin.network,
hasCreatedBackup: state.settings.user.hasCreatedBackup
hasCreatedBackup: state.settings.user.hasCreatedBackup,
navIndex: state.nav.index
}))
class CreatePineAddressScreen extends Component {
static navigationOptions = ({ navigation }) => {
Expand Down Expand Up @@ -106,20 +107,16 @@ class CreatePineAddressScreen extends Component {
componentDidMount() {
const { navigation } = this.props;

this._willFocusListener = navigation.addListener('willFocus', this.componentWillFocus.bind(this));

navigation.setParams({ canSubmit: false });
navigation.setParams({ submit: this._onSubmit.bind(this) });
navigation.setParams({ cancel: this._cancel.bind(this) });
}

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

componentWillFocus() {
if (this._input) {
setTimeout(() => this._input.focus(), 300);
componentDidUpdate(prevProps) {
if (this.props.navIndex === 0 && prevProps.navIndex > 0) {
if (this._input && !this._input.isFocused()) {
setTimeout(() => this._input.focus(), 300);
}
}
}

Expand Down Expand Up @@ -272,6 +269,7 @@ class CreatePineAddressScreen extends Component {
CreatePineAddressScreen.propTypes = {
dispatch: PropTypes.func,
navigation: PropTypes.any,
navIndex: PropTypes.number,
keys: PropTypes.object,
defaultPineAddressHostname: PropTypes.string,
pineAddressHostname: PropTypes.string,
Expand Down

0 comments on commit 3e016f0

Please sign in to comment.