Skip to content

Commit

Permalink
better overfullscreen support
Browse files Browse the repository at this point in the history
  • Loading branch information
lkzhao committed Apr 25, 2017
1 parent db5954d commit 3e59870
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
16 changes: 13 additions & 3 deletions Sources/Animator/HeroDefaultAnimator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@ internal extension UIView {
}
}

internal class HeroDefaultAnimator<ViewContext>: HeroAnimator where ViewContext: HeroAnimatorViewContext {
protocol HasInsertOrder: class {
var insertToViewFirst: Bool { get set }
}
internal class HeroDefaultAnimator<ViewContext: HeroAnimatorViewContext>: HeroAnimator, HasInsertOrder {
weak public var context: HeroContext!
var viewContexts: [UIView: ViewContext] = [:]
internal var insertToViewFirst = false

public func seekTo(timePassed: TimeInterval) {
for viewContext in viewContexts.values {
Expand Down Expand Up @@ -78,8 +82,13 @@ internal class HeroDefaultAnimator<ViewContext>: HeroAnimator where ViewContext:
public func animate(fromViews: [UIView], toViews: [UIView]) -> TimeInterval {
var duration: TimeInterval = 0

for v in fromViews { animate(view: v, appearing: false) }
for v in toViews { animate(view: v, appearing: true) }
if insertToViewFirst {
for v in toViews { animate(view: v, appearing: true) }
for v in fromViews { animate(view: v, appearing: false) }
} else {
for v in fromViews { animate(view: v, appearing: false) }
for v in toViews { animate(view: v, appearing: true) }
}

for viewContext in viewContexts.values {
duration = max(duration, viewContext.duration)
Expand All @@ -100,5 +109,6 @@ internal class HeroDefaultAnimator<ViewContext>: HeroAnimator where ViewContext:
vc.clean()
}
viewContexts.removeAll()
insertToViewFirst = false
}
}
16 changes: 9 additions & 7 deletions Sources/Hero.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,17 @@ internal extension Hero {
container.backgroundColor = toView.backgroundColor
}

super.animate()

if case .none = defaultAnimation {
} else if insertToViewFirst {
let toViewSnapshot = context.snapshotView(for: toView)
let fromViewSnapshot = context.snapshotView(for: fromView)
container.insertSubview(toViewSnapshot, belowSubview: fromViewSnapshot)
if fromOverFullScreen {
insertToViewFirst = true
}
for animator in animators {
if let animator = animator as? HasInsertOrder {
animator.insertToViewFirst = insertToViewFirst
}
}

super.animate()

fullScreenSnapshot!.removeFromSuperview()
}

Expand Down

0 comments on commit 3e59870

Please sign in to comment.