diff --git a/packages/app-mobile/components/screens/ConfigScreen/ConfigScreen.tsx b/packages/app-mobile/components/screens/ConfigScreen/ConfigScreen.tsx index 659fe9b56..9ac3f973a 100644 --- a/packages/app-mobile/components/screens/ConfigScreen/ConfigScreen.tsx +++ b/packages/app-mobile/components/screens/ConfigScreen/ConfigScreen.tsx @@ -115,10 +115,7 @@ class ConfigScreenComponent extends BaseScreenComponent { - this.props.dispatch({ - type: 'NAV_GO', - routeName: 'ProfileSwitcher', - }); + void NavService.go('ProfileSwitcher'); }; private fixSearchEngineIndexButtonPress_ = async () => { @@ -206,6 +203,42 @@ class ConfigScreenComponent extends BaseScreenComponent 0; + } + + private promptSaveChanges(): Promise { + return new Promise(resolve => { + if (this.hasUnsavedChanges()) { + const dialogTitle: string|null = null; + Alert.alert( + dialogTitle, + _('There are unsaved changes.'), + [{ + text: _('Save changes'), + onPress: async () => { + await this.saveButton_press(); + resolve(); + }, + }, + { + text: _('Discard changes'), + onPress: () => resolve(), + }], + ); + } else { + resolve(); + } + }); + } + + private handleNavigateToNewScren = async (): Promise => { + await this.promptSaveChanges(); + + // Continue navigation + return false; + }; + private handleBackButtonPress = (): boolean => { const goBack = async () => { BackButtonService.removeHandler(this.handleBackButtonPress); @@ -218,24 +251,11 @@ class ConfigScreenComponent extends BaseScreenComponent 0) { - const dialogTitle: string|null = null; - Alert.alert( - dialogTitle, - _('There are unsaved changes.'), - [{ - text: _('Save changes'), - onPress: async () => { - await this.saveButton_press(); - await goBack(); - }, - }, - { - text: _('Discard changes'), - onPress: goBack, - }], - ); - + if (this.hasUnsavedChanges()) { + void (async () => { + await this.promptSaveChanges(); + await goBack(); + })(); return true; } @@ -255,12 +275,14 @@ class ConfigScreenComponent extends BaseScreenComponent void, options: any = null) { @@ -600,7 +622,7 @@ class ConfigScreenComponent extends BaseScreenComponent {mainComponent}