Skip to content

Commit

Permalink
Show a discard changes prompt in the custom fields list
Browse files Browse the repository at this point in the history
  • Loading branch information
hichamboushaba committed Oct 28, 2024
1 parent c84d664 commit a4b30cd
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ final class CustomFieldsListHostingController: UIHostingController<CustomFieldsL
}
}

extension CustomFieldsListHostingController {
override func shouldPopOnBackButton() -> Bool {
if viewModel.hasChanges {
presentBackNavigationActionSheet()
return false
}
return true
}

override func shouldPopOnSwipeBack() -> Bool {
return shouldPopOnBackButton()
}
}

private extension CustomFieldsListHostingController {
func configureNavigation() {
title = Localization.title
Expand Down Expand Up @@ -95,6 +109,12 @@ private extension CustomFieldsListHostingController {
func dismissInProgressController() {
dismiss(animated: true)
}

func presentBackNavigationActionSheet() {
UIAlertController.presentDiscardChangesActionSheet(viewController: self, onDiscard: { [weak self] in
self?.navigationController?.popViewController(animated: true)
})
}
}

struct CustomFieldsListView: View {
Expand Down

0 comments on commit a4b30cd

Please sign in to comment.