mirror of
https://github.com/exyte/Macaw.git
synced 2024-09-11 05:05:23 +03:00
Merge pull request #525 from f3dm76/taks/animationLayers
Force display layers while animating
This commit is contained in:
commit
f745c9a732
@ -18,6 +18,7 @@ class AnimationProducer {
|
||||
let animation: ContentsAnimation
|
||||
let layer: CALayer
|
||||
weak var cache: AnimationCache?
|
||||
let topRenderers: [NodeRenderer]
|
||||
let startDate: Date
|
||||
let finishDate: Date
|
||||
let completion: (() -> Void)?
|
||||
@ -259,10 +260,32 @@ class AnimationProducer {
|
||||
return
|
||||
}
|
||||
|
||||
var rootRenderer: NodeRenderer? = renderer
|
||||
while rootRenderer?.parentRenderer != nil {
|
||||
rootRenderer = rootRenderer?.parentRenderer
|
||||
}
|
||||
let allRenderers = rootRenderer?.getAllChildrenRecursive()
|
||||
|
||||
var animationRenderers = [NodeRenderer]()
|
||||
if let groupRenderer = renderer as? GroupRenderer {
|
||||
animationRenderers.append(contentsOf: groupRenderer.renderers)
|
||||
}
|
||||
let bottomRenderer = animationRenderers.min { $0.zPosition < $1.zPosition }
|
||||
|
||||
var topRenderers = [NodeRenderer]()
|
||||
if let bottomRenderer = bottomRenderer, let allRenderers = allRenderers {
|
||||
for renderer in allRenderers {
|
||||
if renderer.zPosition > bottomRenderer.zPosition {
|
||||
topRenderers.append(renderer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let animationDesc = ContentAnimationDesc(
|
||||
animation: contentsAnimation,
|
||||
layer: layer,
|
||||
cache: cache,
|
||||
topRenderers: topRenderers,
|
||||
startDate: Date(),
|
||||
finishDate: Date(timeInterval: contentsAnimation.duration, since: startDate),
|
||||
completion: completion
|
||||
@ -274,13 +297,13 @@ class AnimationProducer {
|
||||
displayLink = MDisplayLink()
|
||||
displayLink?.startUpdates { [weak self] in
|
||||
DispatchQueue.main.async {
|
||||
self?.updateContentAnimations()
|
||||
self?.updateContentAnimations(context)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc func updateContentAnimations() {
|
||||
func updateContentAnimations(_ context: AnimationContext) {
|
||||
if contentsAnimations.isEmpty {
|
||||
displayLink?.invalidate()
|
||||
displayLink = .none
|
||||
@ -340,6 +363,12 @@ class AnimationProducer {
|
||||
animation.pausedProgress = progress
|
||||
}
|
||||
}
|
||||
|
||||
for renderer in animationDesc.topRenderers {
|
||||
let layer = animationDesc.cache?.layerForNodeRenderer(renderer, context, animation: animationDesc.animation)
|
||||
layer?.setNeedsDisplay()
|
||||
layer?.displayIfNeeded()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,14 +21,14 @@ class AnimationUtils {
|
||||
class func absoluteClip(_ nodeRenderer: NodeRenderer?) -> Locus? {
|
||||
// shouldn't this be a superposition of all parents' clips?
|
||||
let node = nodeRenderer?.node()
|
||||
if let _ = node?.clip {
|
||||
return node?.clip
|
||||
if let nodeClip = node?.clip {
|
||||
return nodeClip
|
||||
}
|
||||
|
||||
var parentRenderer = nodeRenderer?.parentRenderer
|
||||
while parentRenderer != nil {
|
||||
if let _ = parentRenderer?.node()?.clip {
|
||||
return parentRenderer?.node()?.clip
|
||||
if let parentClip = parentRenderer?.node()?.clip {
|
||||
return parentClip
|
||||
}
|
||||
|
||||
parentRenderer = parentRenderer?.parentRenderer
|
||||
|
@ -350,6 +350,20 @@ class NodeRenderer {
|
||||
disposables.dispose()
|
||||
}
|
||||
}
|
||||
|
||||
func getAllChildrenRecursive() -> [NodeRenderer] {
|
||||
return getAllChildren(self)
|
||||
}
|
||||
|
||||
private func getAllChildren(_ nodeRenderer: NodeRenderer) -> [NodeRenderer] {
|
||||
var result = [nodeRenderer]
|
||||
if let groupRenderer = nodeRenderer as? GroupRenderer {
|
||||
for child in groupRenderer.renderers {
|
||||
result.append(contentsOf: getAllChildren(child))
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
protocol AnimationObserver {
|
||||
|
Loading…
Reference in New Issue
Block a user