Skip to content
This repository has been archived by the owner on Aug 13, 2021. It is now read-only.

Commit

Permalink
Ensure that system animations take effect during view controller tran…
Browse files Browse the repository at this point in the history
…sitions.

Reviewers: O2 Material Motion, O4 Material Apple platform reviewers, #material_motion, markwei

Reviewed By: O2 Material Motion, O4 Material Apple platform reviewers, #material_motion, markwei

Tags: #material_motion

Differential Revision: http://codereview.cc/D3092
  • Loading branch information
Jeff Verkoeyen committed Apr 24, 2017
1 parent dab2e7d commit 9b23470
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/transitions/TransitionContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,28 @@ extension TransitionContext {
self.runtime = MotionRuntime(containerView: containerView())
self.replicator.containerView = containerView()

pokeSystemAnimations()

let terminators = transition.willBeginTransition(withContext: self, runtime: self.runtime)
runtime.whenAllAtRest(terminators) { [weak self] in
self?.terminate()
}
}

// UIKit transitions will not animate any of the system animations (status bar changes, notably)
// unless we have at least one implicit UIView animation. Material Motion doesn't use implicit
// animations out of the box, so to ensure that system animations still occur we create an
// invisible throwaway view and apply an animation to it.
private func pokeSystemAnimations() {
let throwawayView = UIView()
containerView().addSubview(throwawayView)
UIView.animate(withDuration: transitionDuration(using: context), animations: {
throwawayView.frame = throwawayView.frame.offsetBy(dx: 1, dy: 0)
}, completion: { didComplete in
throwawayView.removeFromSuperview()
})
}

private func terminate() {
guard runtime != nil else { return }
let completedInOriginalDirection = direction.value == initialDirection
Expand Down

0 comments on commit 9b23470

Please sign in to comment.