Skip to content

Commit

Permalink
[master] - 'Modals need to be able to be persisted if they are the fi…
Browse files Browse the repository at this point in the history
…rst screen too - TT'
  • Loading branch information
Tyler-Keith-Thompson committed Nov 8, 2019
1 parent 501448c commit 1eb0acd
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Workflow/Workflow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public class Workflow: LinkedList<FlowRepresentableMetaData>, ExpressibleByArray
#endif
removeInstances()
instances.append(contentsOf: map { _ in nil })
var rootView:Any?
_ = first?.traverse { node in
var metadata = node.value
var flowRepresentable = metadata.flowRepresentableType.instance()
Expand All @@ -148,6 +149,7 @@ public class Workflow: LinkedList<FlowRepresentableMetaData>, ExpressibleByArray
onFinish: onFinish)
}
} else if (!shouldLoad && metadata.staysInViewStack(args) == .hiddenInitially) {
rootView = flowRepresentable
self.presenter?.launch(view: flowRepresentable,
from: from,
withLaunchStyle: flowRepresentable.preferredLaunchStyle,
Expand All @@ -162,7 +164,7 @@ public class Workflow: LinkedList<FlowRepresentableMetaData>, ExpressibleByArray

guard let first = firstLoadedInstance else { return nil }

presenter?.launch(view: first.value, from: from, withLaunchStyle: launchStyle, animated: true, completion: nil)
presenter?.launch(view: first.value, from: rootView ?? from, withLaunchStyle: launchStyle, animated: true, completion: nil)
return firstLoadedInstance
}

Expand Down
55 changes: 53 additions & 2 deletions WorkflowTests/UIKitPresenterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ class UIKitPresenterTests: XCTestCase {
(UIApplication.topViewController() as? FR1)?.proceedInWorkflow()
waitUntil(UIApplication.topViewController() is FR3)
XCTAssert(UIApplication.topViewController() is FR3)
(UIApplication.topViewController()?.navigationController)?.backButton?.simulateTouch()
(UIApplication.topViewController()?.navigationController)?.popViewController(animated: false)
waitUntil(UIApplication.topViewController() is FR2)
XCTAssert(UIApplication.topViewController() is FR2)
}
Expand Down Expand Up @@ -709,7 +709,7 @@ class UIKitPresenterTests: XCTestCase {
(UIApplication.topViewController() as? FR1)?.proceedInWorkflow("blah")
waitUntil(UIApplication.topViewController() is FR3)
XCTAssert(UIApplication.topViewController() is FR3)
(UIApplication.topViewController()?.navigationController)?.backButton?.simulateTouch()
(UIApplication.topViewController()?.navigationController)?.popViewController(animated: false)
waitUntil(UIApplication.topViewController() is FR2)
XCTAssert(UIApplication.topViewController() is FR2)
}
Expand Down Expand Up @@ -772,6 +772,32 @@ class UIKitPresenterTests: XCTestCase {
XCTAssert(UIApplication.topViewController() is FR2)
}

func testModalWorkflowWhichSkipsFirstScreen_ButKeepsItInTheViewStack() {
class FR1: TestViewController {
override func shouldLoad(with args: Any?) -> Bool {
_ = super.shouldLoad(with: args)
return false
}
}
class FR2: UIWorkflowItem<Never>, FlowRepresentable {
static func instance() -> AnyFlowRepresentable { FR2() }
}
class FR3: TestViewController { }

let root = UIViewController()
loadView(controller: root)

root.launchInto(Workflow()
.thenPresent(FR1.self, staysInViewStack: .hiddenInitially)
.thenPresent(FR2.self)
.thenPresent(FR3.self), withLaunchStyle: .modally)
waitUntil(UIApplication.topViewController() is FR2)
XCTAssert(UIApplication.topViewController() is FR2)
UIApplication.topViewController()?.dismiss(animated: false)
waitUntil(UIApplication.topViewController() is FR1)
XCTAssert(UIApplication.topViewController() is FR1)
}

func testModalWorkflowWhichDoesNotSkipAScreen_ButRemovesItFromTheViewStack() {
class FR1: TestViewController { }
class FR2: UIWorkflowItem<Never>, FlowRepresentable {
Expand Down Expand Up @@ -799,6 +825,31 @@ class UIKitPresenterTests: XCTestCase {
XCTAssert(UIApplication.topViewController() is FR1)
}


func testModalWorkflowWhichDoesNotSkipFirstScreen_ButRemovesItFromTheViewStack() {
class FR1: TestViewController { }
class FR2: UIWorkflowItem<Never>, FlowRepresentable {
static func instance() -> AnyFlowRepresentable { FR2() }
}
class FR3: TestViewController { }

let root = UIViewController()
loadView(controller: root)

root.launchInto(Workflow()
.thenPresent(FR1.self, staysInViewStack: .removedAfterProceeding)
.thenPresent(FR2.self)
.thenPresent(FR3.self), withLaunchStyle: .modally)
waitUntil(UIApplication.topViewController() is FR1)
XCTAssert(UIApplication.topViewController() is FR1)
(UIApplication.topViewController() as? FR1)?.proceedInWorkflow()
waitUntil(UIApplication.topViewController() is FR2)
XCTAssert(UIApplication.topViewController() is FR2)
UIApplication.topViewController()?.dismiss(animated: false)
waitUntil(UIApplication.topViewController() === root)
XCTAssert(UIApplication.topViewController() === root)
}

func testModalWorkflowWhichSkipsAScreen_ButKeepsItInTheViewStackUsingAClsure() {
class FR1: TestViewController { }
class FR2: UIWorkflowItem<Never>, FlowRepresentable {
Expand Down

0 comments on commit 1eb0acd

Please sign in to comment.