Skip to content

Commit

Permalink
Merge pull request #87 from BottleRocketStudios/containerTweaks
Browse files Browse the repository at this point in the history
Container tweaks
  • Loading branch information
wmcginty committed Dec 18, 2019
2 parents 0f1f7bd + 29dfa9a commit 7d71e75
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

##### Enhancements

* None
* Make it possible to override functions in container, which aid in `ManagedChild` managemet.
[Will McGinty](https://github.com/willmcginty)
[#87](https://github.com/BottleRocketStudios/iOS-UtiliKit/pull/82)

##### Bug Fixes

Expand Down
24 changes: 12 additions & 12 deletions Sources/UtiliKit/Container/ContainerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,14 @@ open class ContainerViewController: UIViewController {
guard shouldAutomaticallyTransitionOnLoad, let initial = managedChildren.first else { return }
transition(to: initial.viewController)
}
}

//MARK: Public Interface
extension ContainerViewController {

open func transitionToControllerForChild(withIdentifier identifier: AnyHashable, completion: ((Bool) -> Void)? = nil) {
managedChildren.first { identifier == $0.identifier }.map { transitionToController(for: $0, completion: completion) }
// MARK: Public Interface
open func child(at index: Int) -> ManagedChild? {
guard index >= managedChildren.startIndex && index < managedChildren.endIndex else { return nil }
return managedChildren[index]
}

open func transitionToController(for child: ManagedChild, completion: ((Bool) -> Void)? = nil) {
open func addManagedChildIfNeeded(_ child: ManagedChild) {
if !managedChildren.contains { $0.viewController === child.viewController } {
managedChildren.insert(child, at: managedChildren.startIndex)
}
Expand All @@ -67,13 +65,15 @@ extension ContainerViewController {
managedChildren.removeAll { $0.identifier == child.identifier }
managedChildren.insert(child, at: managedChildren.startIndex)
}

transition(to: child.viewController, completion: completion)
}

open func child(at index: Int) -> ManagedChild? {
guard index >= managedChildren.startIndex && index < managedChildren.endIndex else { return nil }
return managedChildren[index]
open func transitionToControllerForChild(withIdentifier identifier: AnyHashable, completion: ((Bool) -> Void)? = nil) {
managedChildren.first { identifier == $0.identifier }.map { transitionToController(for: $0, completion: completion) }
}

open func transitionToController(for child: ManagedChild, completion: ((Bool) -> Void)? = nil) {
addManagedChildIfNeeded(child)
transition(to: child.viewController, completion: completion)
}
}

Expand Down

0 comments on commit 7d71e75

Please sign in to comment.