Skip to content

Commit 1b2dd0a

Browse files
Fix Order Details presentation on phone (#16331)
2 parents b47f493 + 89992ef commit 1b2dd0a

File tree

5 files changed

+35
-13
lines changed

5 files changed

+35
-13
lines changed

RELEASE-NOTES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- [**] We added support for collecting in-person payments (including Tap To Pay) using Stripe Payment Gateway extension in the UK. [https://github.com/woocommerce/woocommerce-ios/pull/16287]
77
- [*] Improve card payments onboarding error handling to show network errors correctly [https://github.com/woocommerce/woocommerce-ios/pull/16304]
88
- [*] Authenticate the admin page automatically for sites with SSO enabled in custom fields, in-person payment setup, and editing tax rates flows. [https://github.com/woocommerce/woocommerce-ios/pull/16318]
9+
- [*] Fix order details presentation when opened from booking details [https://github.com/woocommerce/woocommerce-ios/pull/16331]
910
- [*] Show POS feedback surveys for eligible merchants [https://github.com/woocommerce/woocommerce-ios/pull/16325]
1011
- [*] Fix product variation selection for order creation [https://github.com/woocommerce/woocommerce-ios/pull/16317]
1112

WooCommerce/Classes/ViewRelated/Orders/Order Details/OrderDetailsViewController.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ final class OrderDetailsViewController: UIViewController {
110110
override var shouldShowOfflineBanner: Bool {
111111
true
112112
}
113+
114+
func isPresentingViewModelOrder(_ viewModel: OrderDetailsViewModel) -> Bool {
115+
return self.viewModel.order.orderID == viewModel.order.orderID
116+
}
117+
118+
func isQuickOrderNavigationSupported() -> Bool {
119+
viewModels.count > 1
120+
}
113121
}
114122

115123
// MARK: - TableView Configuration

WooCommerce/Classes/ViewRelated/Orders/OrderListViewController.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,14 @@ extension OrderListViewController {
626626
/// Adds ability to select any order
627627
/// Used when opening an order with deep link
628628
/// - Parameter orderID: ID of the order to select in the list.
629+
/// - Parameter isTriggeredByUserAction: Reflects if the order selection was triggered by a manual user action and not a view lifecycle update
630+
/// Practically if the `isTriggeredByUserAction` is true, then the order details will be force presented
631+
/// even if `selectedOrderID` is the same as the new `orderID`
629632
/// - Returns: Whether the order to select is in the list already (i.e. the order has been fetched and exists locally).
630-
func selectOrderFromListIfPossible(for orderID: Int64) -> Bool {
633+
func selectOrderFromListIfPossible(
634+
for orderID: Int64,
635+
isTriggeredByUserAction: Bool = false,
636+
) -> Bool {
631637
guard let dataSource else {
632638
return false
633639
}
@@ -637,7 +643,7 @@ extension OrderListViewController {
637643
let orderNotAlreadySelected = selectedOrderID != orderID
638644
let indexPath = dataSource.indexPath(for: identifier)
639645
let indexPathNotAlreadySelected = selectedIndexPath != indexPath
640-
let shouldSwitchDetails = orderNotAlreadySelected || indexPathNotAlreadySelected
646+
let shouldSwitchDetails = orderNotAlreadySelected || indexPathNotAlreadySelected || isTriggeredByUserAction
641647
if shouldSwitchDetails {
642648
showOrderDetails(detailsViewModel.order)
643649
}

WooCommerce/Classes/ViewRelated/Orders/OrdersRootViewController.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,10 @@ final class OrdersRootViewController: UIViewController {
165165
/// - Returns: Whether the order to select is in the list already (i.e. the order has been fetched and exists locally).
166166
@discardableResult
167167
func selectOrderFromListIfPossible(for orderID: Int64) -> Bool {
168-
ordersViewController.selectOrderFromListIfPossible(for: orderID)
168+
ordersViewController.selectOrderFromListIfPossible(
169+
for: orderID,
170+
isTriggeredByUserAction: true
171+
)
169172
}
170173

171174
/// Called when an order is shown externally (outside of `OrderListViewController`) and the order should be

WooCommerce/Classes/ViewRelated/Orders/OrdersSplitViewWrapperController.swift

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,26 +129,30 @@ private extension OrdersSplitViewWrapperController {
129129
// shown should replace the topViewController, to avoid having to tap back through several Order Details
130130
// screens in the navigation stack. The back button should always go to the Order List.
131131
// The up and down arrows are enabled when there is more than one item in `viewModels`.
132-
guard isQuickOrderNavigationSupported(viewModels: viewModels),
133-
let viewModel = viewModels[safe: currentIndex],
134-
let secondaryNavigationController = ordersSplitViewController.viewController(for: .secondary) as? UINavigationController,
135-
secondaryNavigationController.topViewController is OrderDetailsViewController else {
132+
guard
133+
let viewModel = viewModels[safe: currentIndex],
134+
let secondaryNavigationController = ordersSplitViewController.viewController(for: .secondary) as? UINavigationController,
135+
let existingOrderDetailsViewController = secondaryNavigationController.topViewController as? OrderDetailsViewController,
136+
existingOrderDetailsViewController.isQuickOrderNavigationSupported() == orderDetailsViewController.isQuickOrderNavigationSupported()
137+
else {
136138
// When showing an order without quick navigation, it simply sets the order details to the secondary view.
137139
let orderDetailsNavigationController = WooNavigationController(rootViewController: orderDetailsViewController)
138140
showSecondaryView(orderDetailsNavigationController)
139141
onCompletion?(true)
140142
return
141143
}
142144

143-
secondaryNavigationController.replaceTopViewController(with: orderDetailsViewController, animated: false)
144-
ordersViewController.onOrderSelected(id: viewModel.order.orderID)
145+
if !existingOrderDetailsViewController.isPresentingViewModelOrder(viewModel) {
146+
secondaryNavigationController.replaceTopViewController(
147+
with: orderDetailsViewController,
148+
animated: false
149+
)
150+
ordersViewController.onOrderSelected(id: viewModel.order.orderID)
151+
}
152+
145153
ordersSplitViewController.show(.secondary)
146154
onCompletion?(true)
147155
}
148-
149-
func isQuickOrderNavigationSupported(viewModels: [OrderDetailsViewModel]) -> Bool {
150-
viewModels.count > 1
151-
}
152156
}
153157

154158
private extension OrdersSplitViewWrapperController {

0 commit comments

Comments
 (0)