Skip to content

Commit d7d6565

Browse files
committed
Add canBeDismissed property on NewOrderViewModel
1 parent 623f608 commit d7d6565

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

WooCommerce/Classes/ViewRelated/Orders/Order Creation/NewOrder.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ final class NewOrderHostingController: UIHostingController<NewOrder> {
4444
///
4545
extension NewOrderHostingController {
4646
override func shouldPopOnBackButton() -> Bool {
47-
guard !viewModel.hasChanges else {
47+
guard viewModel.canBeDismissed || !viewModel.hasChanges else {
4848
presentDiscardChangesActionSheet(onDiscard: { [weak self] in
4949
self?.discardOrderAndPop()
5050
})
@@ -62,7 +62,7 @@ extension NewOrderHostingController {
6262
///
6363
extension NewOrderHostingController: UIAdaptivePresentationControllerDelegate {
6464
func presentationControllerShouldDismiss(_ presentationController: UIPresentationController) -> Bool {
65-
return !viewModel.hasChanges
65+
return viewModel.canBeDismissed || !viewModel.hasChanges
6666
}
6767

6868
func presentationControllerDidAttemptToDismiss(_ presentationController: UIPresentationController) {

WooCommerce/Classes/ViewRelated/Orders/Order Creation/NewOrderViewModel.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,18 @@ final class NewOrderViewModel: ObservableObject {
2828
/// Indicates whether user has made any changes
2929
///
3030
var hasChanges: Bool {
31-
orderSynchronizer.order != OrderFactory.emptyNewOrder && flow == .creation
31+
switch flow {
32+
case .creation:
33+
return orderSynchronizer.order != OrderFactory.emptyNewOrder
34+
case .editing(let initialOrder):
35+
return orderSynchronizer.order != initialOrder
36+
}
37+
}
38+
39+
/// Indicates whether view can be dismissed. If the value is `false` - confirmation alert will be displayd depending on `hasChanges` value.
40+
///
41+
var canBeDismissed: Bool {
42+
flow == .creation
3243
}
3344

3445
/// Indicates whether the cancel button is visible.

0 commit comments

Comments
 (0)