Skip to content

Commit

Permalink
Don't apply new layout if currently animating captionView
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhillc committed Sep 23, 2018
1 parent aee5ef8 commit d0dd718
Showing 1 changed file with 48 additions and 48 deletions.
96 changes: 48 additions & 48 deletions Source/Classes/Views/AXCaptionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -240,68 +240,68 @@ import UIKit
}

if self.animateCaptionInfoChanges && self.needsCaptionLayoutAnim {
// ensure that this block runs in its own animation context (container may animate)
DispatchQueue.main.async { [weak self] in
guard let `self` = self else {
return
}

let animateOut: () -> Void = {
self.titleLabel.alpha = 0
self.descriptionLabel.alpha = 0
self.creditLabel.alpha = 0
}
if !self.isCaptionAnimatingOut {
self.isCaptionAnimatingOut = true

let animateOutCompletion: (_ finished: Bool) -> Void = { (finished) in
if !finished {
// ensure that this block runs in its own animation context (container may animate)
DispatchQueue.main.async { [weak self] in
guard let `self` = self else {
return
}

applySizingAttributes()
self.isCaptionAnimatingOut = false
}

let animateIn: () -> Void = {
self.titleLabel.alpha = 1
self.descriptionLabel.alpha = 1
self.creditLabel.alpha = 1
}

let animateInCompletion: (_ finished: Bool) -> Void = { (finished) in
if !finished {
return
let animateOut: () -> Void = {
self.titleLabel.alpha = 0
self.descriptionLabel.alpha = 0
self.creditLabel.alpha = 0
}

self.isCaptionAnimatingIn = false
}

if self.isCaptionAnimatingOut {
return
}

self.isCaptionAnimatingOut = true
UIView.animate(withDuration: AXConstants.frameAnimDuration / 2,
delay: 0,
options: [.beginFromCurrentState, .curveEaseOut],
animations: animateOut) { (finished) in
let animateOutCompletion: (_ finished: Bool) -> Void = { (finished) in
if !finished {
return
}

applySizingAttributes()
self.isCaptionAnimatingOut = false
}

if self.isCaptionAnimatingIn {
return
let animateIn: () -> Void = {
self.titleLabel.alpha = 1
self.descriptionLabel.alpha = 1
self.creditLabel.alpha = 1
}

let animateInCompletion: (_ finished: Bool) -> Void = { (finished) in
if !finished {
return
}

self.isCaptionAnimatingIn = false
}

animateOutCompletion(finished)
UIView.animate(withDuration: AXConstants.frameAnimDuration / 2,
delay: 0,
options: [.beginFromCurrentState, .curveEaseIn],
animations: animateIn,
completion: animateInCompletion)
options: [.beginFromCurrentState, .curveEaseOut],
animations: animateOut) { (finished) in
if self.isCaptionAnimatingIn {
return
}

animateOutCompletion(finished)
self.isCaptionAnimatingIn = true
UIView.animate(withDuration: AXConstants.frameAnimDuration / 2,
delay: 0,
options: [.beginFromCurrentState, .curveEaseIn],
animations: animateIn,
completion: animateInCompletion)
}
}

self.needsCaptionLayoutAnim = false
}

self.needsCaptionLayoutAnim = false

} else {
applySizingAttributes()
if !self.isCaptionAnimatingIn && !self.isCaptionAnimatingOut {
applySizingAttributes()
}
}

self.isFirstLayout = false
Expand Down

0 comments on commit d0dd718

Please sign in to comment.