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

Ensure completion handler is called #76

Merged
merged 2 commits into from
Sep 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

##### Bug Fixes

* None
* Fix an issue where the completion handler does not get called when transitioning.
[Will McGinty](https://github.com/willmcginty)
[#76](https://github.com/BottleRocketStudios/iOS-UtiliKit/pull/76)

## 1.6.0 (2019-08-29)

Expand Down
5 changes: 3 additions & 2 deletions Sources/UtiliKit/Container/ContainerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private extension ContainerViewController {
prepareForTransitioning(from: source, to: destination, animated: true)
defer { delegate?.containerViewController(self, didBeginTransitioningFrom: source, to: destination) }

let context = configuredTransitionContext(from: source, to: destination)
let context = configuredTransitionContext(from: source, to: destination, completion: completion)
let animator = delegate?.containerViewController(self, animationControllerForTransitionFrom: source, to: destination) ?? DefaultContainerTransitionAnimator()
let interactor = delegate?.containerViewController(self, interactionControllerForTransitionFrom: source, to: destination)

Expand All @@ -114,12 +114,13 @@ private extension ContainerViewController {
//MARK: Helper
private extension ContainerViewController {

func configuredTransitionContext(from source: UIViewController, to destination: UIViewController) -> ContainerTransitionContext {
func configuredTransitionContext(from source: UIViewController, to destination: UIViewController, completion: ((Bool) -> Void)? = nil) -> ContainerTransitionContext {
let context = ContainerTransitionContext(containerView: view, fromViewController: source, toViewController: destination)
context.completion = { [weak self] finished in
guard let self = self else { return }
self.finishTransitioning(from: source, to: destination, success: finished, animated: true)
self.delegate?.containerViewController(self, didFinishTransitioningFrom: source, to: destination)
completion?(finished)
}

return context
Expand Down