Skip to content

Commit

Permalink
Fix for unwinding in tabs with navigation stacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Domas Nutautas committed May 21, 2020
1 parent 338c75a commit 6bdbc2e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions Sources/StoryFlow/Flow/Helpers/Unwinding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ extension UIViewController {
Thread.onMain {
if canHandle(updateType, from: source) {
return self
} else if let vc = navStack?.first(where: { $0.canHandle(updateType, from: source) }) {
} else if let vc = navStacks.first(where: { $0.canHandle(updateType, from: source) }) {
return vc
} else if let vc = tabs?.first(where: { $0.canHandle(updateType, from: source) }) {
} else if let vc = tabs.first(where: { $0.canHandle(updateType, from: source) }) {
return vc
} else {
return (parent ?? presentingViewController)?.unwindVc(for: updateType, from: source)
Expand Down Expand Up @@ -47,16 +47,16 @@ private extension UIViewController {
}
}

func firstChild<T>(_ t: T.Type) -> T? {
self as? T ?? children.first { $0.firstChild(t) != nil }?.firstChild(t)
func allChild<T>(_ t: T.Type) -> [T] {
[self as? T].compactMap { $0 } + children.flatMap { $0.allChild(t) }
}

var navStack: [UIViewController]? {
firstChild(UINavigationController.self)?.viewControllers.reversed()
var navStacks: [UIViewController] {
allChild(UINavigationController.self).flatMap { $0.viewControllers.reversed() }
}

var tabs: [UIViewController]? {
firstChild(UITabBarController.self)?.viewControllers
var tabs: [UIViewController] {
allChild(UITabBarController.self).flatMap { $0.viewControllers ?? [] }
}

func isVc(for updateType: Any.Type) -> Bool {
Expand Down
2 changes: 1 addition & 1 deletion StoryFlowTests/ImplicitFlowTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ class ImplicitFlowTests: XCTestCase {
nav.setViewControllers([to, UIViewController()], animated: false)

let tab = UITabBarController().visible()
tab.setViewControllers([from, nav], animated: false)
tab.setViewControllers([UINavigationController(rootViewController: from), nav], animated: false)

let output = T()

Expand Down

0 comments on commit 6bdbc2e

Please sign in to comment.