Skip to content
This repository has been archived by the owner on Sep 23, 2024. It is now read-only.

Commit

Permalink
Send presentation event when actually showing a tab
Browse files Browse the repository at this point in the history
  • Loading branch information
sampettersson committed Aug 20, 2021
1 parent 00c769e commit 3068e73
Showing 1 changed file with 48 additions and 36 deletions.
84 changes: 48 additions & 36 deletions Presentation/Journey/TabbedJourney.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@ extension UIViewController {
vc.updatePresentationTitle(for: presentation.presentable)

let transformedResult = presentation.transform(result)

let presentationEvent = PresentationEvent.willPresent(
.init(vc.presentationDescription),
from: .init(self.presentationDescription),
styleName: "default"
)

presentablePresentationEventHandler(presentationEvent, #file, #function, #line)

let embeddedVC = vc.embededInNavigationController(presentation.options)

Expand All @@ -53,7 +45,7 @@ extension UIViewController {
}
}

public class TabbedJourney: JourneyPresentation {
public struct TabbedJourney: JourneyPresentation {
public var onDismiss: (Error?) -> ()

public var style: PresentationStyle
Expand All @@ -66,6 +58,39 @@ public class TabbedJourney: JourneyPresentation {

public let presentable: AnyPresentable<UITabBarController, Disposable>

static func becameActive(_ from: UIViewController, activeViewController: UIViewController) {
let presentationEvent = PresentationEvent.willPresent(
.init(activeViewController.presentationDescription),
from: .init(from.presentationDescription),
styleName: "default"
)

presentablePresentationEventHandler(presentationEvent, #file, #function, #line)
}

static func resignedActive(_ from: UIViewController, activeViewController: UIViewController) {
viewControllerWasPresented(activeViewController)

let presentationEvent = PresentationEvent.didCancel(
.init(activeViewController.presentationDescription),
from: .init(from.presentationDescription)
)

presentablePresentationEventHandler(presentationEvent, #file, #function, #line)
}

static func activeHandler(_ tabBarController: UITabBarController) -> Disposable {
tabBarController.signal(for: \.selectedViewController).compactMap { viewController in
viewController
}.onValueDisposePrevious { viewController in
Self.becameActive(tabBarController, activeViewController: viewController)

return Disposer {
Self.resignedActive(tabBarController, activeViewController: viewController)
}
}
}

public init<Tab1: JourneyPresentation>(
@JourneyBuilder _ tab1: @escaping () -> Tab1,
style: PresentationStyle = .default,
Expand All @@ -83,6 +108,8 @@ public class TabbedJourney: JourneyPresentation {
tabBarController.viewControllers = [viewController].filter { $0 as? ContinuerPresentable.ContinuerViewController == nil }
configurer()

bag += Self.activeHandler(tabBarController)

return (tabBarController, bag)
})

Expand Down Expand Up @@ -121,11 +148,11 @@ public class TabbedJourney: JourneyPresentation {

tabBarController.viewControllers = [tab1ViewController, tab2ViewController].filter { $0 as? ContinuerPresentable.ContinuerViewController == nil }

viewControllerWasPresented(tab1ViewController)
configurer1()
viewControllerWasPresented(tab2ViewController)
configurer2()

bag += Self.activeHandler(tabBarController)

return (tabBarController, bag)
})

Expand Down Expand Up @@ -168,13 +195,12 @@ public class TabbedJourney: JourneyPresentation {

tabBarController.viewControllers = [tab1ViewController, tab2ViewController, tab3ViewController].filter { $0 as? ContinuerPresentable.ContinuerViewController == nil }

viewControllerWasPresented(tab1ViewController)
configurer1()
viewControllerWasPresented(tab2ViewController)
configurer2()
viewControllerWasPresented(tab3ViewController)
configurer3()

bag += Self.activeHandler(tabBarController)

return (tabBarController, bag)
})

Expand Down Expand Up @@ -221,15 +247,13 @@ public class TabbedJourney: JourneyPresentation {

tabBarController.viewControllers = [tab1ViewController, tab2ViewController, tab3ViewController, tab4ViewController].filter { $0 as? ContinuerPresentable.ContinuerViewController == nil }

viewControllerWasPresented(tab1ViewController)
configurer1()
viewControllerWasPresented(tab2ViewController)
configurer2()
viewControllerWasPresented(tab3ViewController)
configurer3()
viewControllerWasPresented(tab4ViewController)
configurer4()

bag += Self.activeHandler(tabBarController)

return (tabBarController, bag)
})

Expand Down Expand Up @@ -280,17 +304,14 @@ public class TabbedJourney: JourneyPresentation {

tabBarController.viewControllers = [tab1ViewController, tab2ViewController, tab3ViewController, tab4ViewController, tab5ViewController].filter { $0 as? ContinuerPresentable.ContinuerViewController == nil }

viewControllerWasPresented(tab1ViewController)
configurer1()
viewControllerWasPresented(tab2ViewController)
configurer2()
viewControllerWasPresented(tab3ViewController)
configurer3()
viewControllerWasPresented(tab4ViewController)
configurer4()
viewControllerWasPresented(tab5ViewController)
configurer5()

bag += Self.activeHandler(tabBarController)

return (tabBarController, bag)
})

Expand Down Expand Up @@ -345,19 +366,15 @@ public class TabbedJourney: JourneyPresentation {

tabBarController.viewControllers = [tab1ViewController, tab2ViewController, tab3ViewController, tab4ViewController, tab5ViewController, tab6ViewController].filter { $0 as? ContinuerPresentable.ContinuerViewController == nil }

viewControllerWasPresented(tab1ViewController)
configurer1()
viewControllerWasPresented(tab2ViewController)
configurer2()
viewControllerWasPresented(tab3ViewController)
configurer3()
viewControllerWasPresented(tab4ViewController)
configurer4()
viewControllerWasPresented(tab5ViewController)
configurer5()
viewControllerWasPresented(tab6ViewController)
configurer6()

bag += Self.activeHandler(tabBarController)

return (tabBarController, bag)
})

Expand Down Expand Up @@ -416,21 +433,16 @@ public class TabbedJourney: JourneyPresentation {

tabBarController.viewControllers = [tab1ViewController, tab2ViewController, tab3ViewController, tab4ViewController, tab5ViewController, tab6ViewController, tab7ViewController].filter { $0 as? ContinuerPresentable.ContinuerViewController == nil }

viewControllerWasPresented(tab1ViewController)
configurer1()
viewControllerWasPresented(tab2ViewController)
configurer2()
viewControllerWasPresented(tab3ViewController)
configurer3()
viewControllerWasPresented(tab4ViewController)
configurer4()
viewControllerWasPresented(tab5ViewController)
configurer5()
viewControllerWasPresented(tab6ViewController)
configurer6()
viewControllerWasPresented(tab7ViewController)
configurer7()

bag += Self.activeHandler(tabBarController)

return (tabBarController, bag)
})

Expand Down

0 comments on commit 3068e73

Please sign in to comment.