Skip to content

Commit af6828d

Browse files
pmusolinojkmassel
authored andcommitted
Resolved switch to review tab crash when receiving a push notification with app inactive
1 parent 6b26df6 commit af6828d

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

WooCommerce/Classes/Extensions/UINavigationController+Woo.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,16 @@ extension UINavigationController {
1818

1919
scrollView.setContentOffset(.zero, animated: animated)
2020
}
21+
22+
/// Completion block for popToRootViewController
23+
/// UINavigationController API doesn't offer any options for this.
24+
/// However by using the CoreAnimation framework it's possible to add a completion block to the underlying animation
25+
///
26+
func popToRootViewController(animated: Bool, handler: @escaping ()->()) {
27+
CATransaction.begin()
28+
CATransaction.setCompletionBlock(handler)
29+
popToRootViewController(animated: animated)
30+
CATransaction.commit()
31+
}
32+
2133
}

WooCommerce/Classes/ViewRelated/MainTabBarController.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,12 @@ final class MainTabBarController: UITabBarController {
143143

144144
/// Switches the TabBarcController to the specified Tab
145145
///
146-
func navigateTo(_ tab: WooTab, animated: Bool = false) {
146+
func navigateTo(_ tab: WooTab, animated: Bool = false, completion: (() -> Void)? = nil) {
147147
selectedIndex = tab.visibleIndex()
148148
if let navController = selectedViewController as? UINavigationController {
149-
navController.popToRootViewController(animated: animated)
149+
navController.popToRootViewController(animated: animated) {
150+
completion?()
151+
}
150152
}
151153
}
152154
}
@@ -249,18 +251,17 @@ extension MainTabBarController {
249251

250252
/// Switches to the Reviews tab and pops to the root view controller
251253
///
252-
static func switchToReviewsTab() {
253-
navigateTo(.reviews)
254+
static func switchToReviewsTab(completion: (() -> Void)? = nil) {
255+
navigateTo(.reviews, completion: completion)
254256
}
255257

256258
/// Switches the TabBarController to the specified Tab
257259
///
258-
private static func navigateTo(_ tab: WooTab, animated: Bool = false) {
260+
private static func navigateTo(_ tab: WooTab, animated: Bool = false, completion: (() -> Void)? = nil) {
259261
guard let tabBar = AppDelegate.shared.tabBarController else {
260262
return
261263
}
262-
263-
tabBar.navigateTo(tab, animated: animated)
264+
tabBar.navigateTo(tab, animated: animated, completion: completion)
264265
}
265266

266267
/// Returns the "Top Visible Child" of the specified type
@@ -295,13 +296,12 @@ extension MainTabBarController {
295296
/// Switches to the Notifications Tab, and displays the details for the specified Notification ID.
296297
///
297298
static func presentNotificationDetails(for noteID: Int) {
298-
switchToReviewsTab()
299-
300-
guard let reviewsViewController: ReviewsViewController = childViewController() else {
301-
return
299+
switchToReviewsTab {
300+
guard let reviewsViewController: ReviewsViewController = childViewController() else {
301+
return
302+
}
303+
reviewsViewController.presentDetails(for: noteID)
302304
}
303-
304-
reviewsViewController.presentDetails(for: noteID)
305305
}
306306

307307
/// Switches to the My Store Tab, and presents the Settings .

0 commit comments

Comments
 (0)