Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose coordinator's children in protocol #242

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Sources/XCoordinator/AnyCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class AnyCoordinator<RouteType: Route, TransitionType: TransitionProtocol
private let _prepareTransition: (RouteType) -> TransitionType
private let _viewController: () -> UIViewController?
private let _rootViewController: () -> TransitionType.RootViewController
private let _children: () -> [Presentable]
private let _presented: (Presentable?) -> Void
private let _setRoot: (UIWindow) -> Void
private let _addChild: (Presentable) -> Void
Expand All @@ -55,6 +56,7 @@ public class AnyCoordinator<RouteType: Route, TransitionType: TransitionProtocol
self._prepareTransition = coordinator.prepareTransition
self._viewController = { coordinator.viewController }
self._rootViewController = { coordinator.rootViewController }
self._children = { coordinator.children }
self._presented = coordinator.presented
self._setRoot = coordinator.setRoot
self._addChild = coordinator.addChild
Expand All @@ -72,6 +74,10 @@ public class AnyCoordinator<RouteType: Route, TransitionType: TransitionProtocol
public var viewController: UIViewController! {
_viewController()
}

public var children: [Presentable] {
_children()
}

// MARK: Methods

Expand Down
5 changes: 0 additions & 5 deletions Sources/XCoordinator/BaseCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ open class BaseCoordinator<RouteType: Route, TransitionType: TransitionProtocol>
private var removeParentChildren: () -> Void = {}
private var gestureRecognizerTargets = [GestureRecognizerTarget]()

///
/// The child coordinators that are currently in the view hierarchy.
/// When performing a transition, children are automatically added and removed from this array
/// depending on whether they are in the view hierarchy.
///
public private(set) var children = [Presentable]()

// MARK: Computed properties
Expand Down
7 changes: 7 additions & 0 deletions Sources/XCoordinator/Coordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ public typealias ContextPresentationHandler = (TransitionContext) -> Void
///
public protocol Coordinator: Router, TransitionPerformer {

///
/// The child coordinators that are currently in the view hierarchy.
/// When performing a transition, children are automatically added and removed from this array
/// depending on whether they are in the view hierarchy.
///
var children: [Presentable] { get }

///
/// This method prepares transitions for routes.
/// It especially decides, which transitions are performed for the triggered routes.
Expand Down