mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Fix animation
This commit is contained in:
parent
6a1edbfdaa
commit
17b7ebc3d6
@ -335,8 +335,12 @@ public final class ChatMessageShadowNode: ASDisplayNode {
|
||||
self.contentNode.image = shadowImage
|
||||
}
|
||||
|
||||
public func updateLayout(backgroundFrame: CGRect, animator: ControlledTransitionAnimator) {
|
||||
animator.updateFrame(layer: self.contentNode.layer, frame: CGRect(origin: CGPoint(x: backgroundFrame.minX - 10.0, y: backgroundFrame.minY - 10.0), size: CGSize(width: backgroundFrame.width + 20.0, height: backgroundFrame.height + 20.0)), completion: nil)
|
||||
}
|
||||
|
||||
public func updateLayout(backgroundFrame: CGRect, transition: ContainedViewLayoutTransition) {
|
||||
transition.updateFrame(node: self.contentNode, frame: CGRect(origin: CGPoint(x: backgroundFrame.minX - 10.0, y: backgroundFrame.minY - 10.0), size: CGSize(width: backgroundFrame.width + 20.0, height: backgroundFrame.height + 20.0)))
|
||||
transition.updateFrame(layer: self.contentNode.layer, frame: CGRect(origin: CGPoint(x: backgroundFrame.minX - 10.0, y: backgroundFrame.minY - 10.0), size: CGSize(width: backgroundFrame.width + 20.0, height: backgroundFrame.height + 20.0)), completion: nil)
|
||||
}
|
||||
}
|
||||
|
||||
@ -552,7 +556,7 @@ public final class ChatMessageBubbleBackdrop: ASDisplayNode {
|
||||
var backgroundFrame = backgroundContent.frame
|
||||
backgroundFrame.origin.x += rect.minX
|
||||
backgroundFrame.origin.y += rect.minY
|
||||
backgroundContent.update(rect: backgroundFrame, within: containerSize, transition: .animated(duration: animator.duration, curve: .spring))
|
||||
backgroundContent.update(rect: backgroundFrame, within: containerSize, animator: animator)
|
||||
}
|
||||
}
|
||||
animator.updateFrame(layer: self.layer, frame: value, completion: { _ in
|
||||
|
@ -830,6 +830,31 @@ public extension ContainedViewLayoutTransition {
|
||||
}
|
||||
}
|
||||
|
||||
func updateContentsRect(layer: CALayer, contentsRect: CGRect, completion: ((Bool) -> Void)? = nil) {
|
||||
if layer.contentsRect == contentsRect {
|
||||
if let completion = completion {
|
||||
completion(true)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
switch self {
|
||||
case .immediate:
|
||||
layer.contentsRect = contentsRect
|
||||
if let completion = completion {
|
||||
completion(true)
|
||||
}
|
||||
case let .animated(duration, curve):
|
||||
let previousContentsRect = layer.contentsRect
|
||||
layer.contentsRect = contentsRect
|
||||
layer.animate(from: NSValue(cgRect: previousContentsRect), to: NSValue(cgRect: contentsRect), keyPath: "contentsRect", timingFunction: curve.timingFunction, duration: duration, mediaTimingFunction: curve.mediaTimingFunction, completion: { result in
|
||||
if let completion = completion {
|
||||
completion(result)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func animateTransformScale(node: ASDisplayNode, from fromScale: CGFloat, additive: Bool = false, completion: ((Bool) -> Void)? = nil) {
|
||||
let t = node.layer.transform
|
||||
let currentScale = sqrt((t.m11 * t.m11) + (t.m12 * t.m12) + (t.m13 * t.m13))
|
||||
@ -1512,6 +1537,7 @@ public protocol ControlledTransitionAnimator: AnyObject {
|
||||
func updateBounds(layer: CALayer, bounds: CGRect, completion: ((Bool) -> Void)?)
|
||||
func updateFrame(layer: CALayer, frame: CGRect, completion: ((Bool) -> Void)?)
|
||||
func updateCornerRadius(layer: CALayer, cornerRadius: CGFloat, completion: ((Bool) -> Void)?)
|
||||
func updateContentsRect(layer: CALayer, contentsRect: CGRect, completion: ((Bool) -> Void)?)
|
||||
}
|
||||
|
||||
protocol AnyValueProviding {
|
||||
@ -1908,6 +1934,21 @@ public final class ControlledTransition {
|
||||
completion: completion
|
||||
))
|
||||
}
|
||||
|
||||
public func updateContentsRect(layer: CALayer, contentsRect: CGRect, completion: ((Bool) -> Void)?) {
|
||||
if layer.contentsRect == contentsRect {
|
||||
return
|
||||
}
|
||||
let fromValue = layer.presentation()?.contentsRect ?? layer.contentsRect
|
||||
layer.contentsRect = contentsRect
|
||||
self.add(animation: ControlledTransitionProperty(
|
||||
layer: layer,
|
||||
path: "contentsRect",
|
||||
fromValue: fromValue,
|
||||
toValue: contentsRect,
|
||||
completion: completion
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
public final class LegacyAnimator: ControlledTransitionAnimator {
|
||||
@ -1963,6 +2004,10 @@ public final class ControlledTransition {
|
||||
public func updateCornerRadius(layer: CALayer, cornerRadius: CGFloat, completion: ((Bool) -> Void)?) {
|
||||
self.transition.updateCornerRadius(layer: layer, cornerRadius: cornerRadius, completion: completion)
|
||||
}
|
||||
|
||||
public func updateContentsRect(layer: CALayer, contentsRect: CGRect, completion: ((Bool) -> Void)?) {
|
||||
self.transition.updateContentsRect(layer: layer, contentsRect: contentsRect, completion: completion)
|
||||
}
|
||||
}
|
||||
|
||||
public let animator: ControlledTransitionAnimator
|
||||
|
@ -2837,8 +2837,8 @@ class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePreviewItemNode
|
||||
|
||||
strongSelf.backgroundNode.updateLayout(size: backgroundFrame.size, transition: animation)
|
||||
animation.animator.updateFrame(layer: strongSelf.backgroundWallpaperNode.layer, frame: backgroundFrame, completion: nil)
|
||||
strongSelf.shadowNode.updateLayout(backgroundFrame: backgroundFrame, transition: animation.transition)
|
||||
strongSelf.backgroundWallpaperNode.updateFrame(backgroundFrame, transition: animation.transition)
|
||||
strongSelf.shadowNode.updateLayout(backgroundFrame: backgroundFrame, animator: animation.animator)
|
||||
strongSelf.backgroundWallpaperNode.updateFrame(backgroundFrame, animator: animation.animator)
|
||||
}
|
||||
|
||||
if let _ = strongSelf.backgroundNode.type {
|
||||
|
@ -659,12 +659,12 @@ final class ChatMessageInteractiveFileNode: ASDisplayNode {
|
||||
case let .success(text, isPending):
|
||||
textString = NSAttributedString(string: text, font: textFont, textColor: messageTheme.primaryTextColor)
|
||||
|
||||
#if DEBUG
|
||||
/*#if DEBUG
|
||||
var isPending = isPending
|
||||
if "".isEmpty {
|
||||
isPending = true
|
||||
}
|
||||
#endif
|
||||
#endif*/
|
||||
|
||||
if isPending {
|
||||
let modifiedString = NSMutableAttributedString(attributedString: textString!)
|
||||
@ -1116,7 +1116,7 @@ final class ChatMessageInteractiveFileNode: ASDisplayNode {
|
||||
let _ = waveformView.update(
|
||||
transition: waveformTransition.withUserData(ComponentHostViewSkipSettingFrame()),
|
||||
component: AnyComponent(AudioWaveformComponent(
|
||||
backgroundColor: waveformColor,
|
||||
backgroundColor: isTranscriptionInProgress ? messageTheme.mediaInactiveControlColor : waveformColor,
|
||||
foregroundColor: messageTheme.mediaActiveControlColor,
|
||||
shimmerColor: isTranscriptionInProgress ? messageTheme.mediaActiveControlColor : nil,
|
||||
samples: audioWaveform?.samples ?? Data(),
|
||||
|
@ -44,6 +44,7 @@ public protocol WallpaperBubbleBackgroundNode: ASDisplayNode {
|
||||
|
||||
func update(rect: CGRect, within containerSize: CGSize, transition: ContainedViewLayoutTransition)
|
||||
func update(rect: CGRect, within containerSize: CGSize, transition: CombinedTransition)
|
||||
func update(rect: CGRect, within containerSize: CGSize, animator: ControlledTransitionAnimator)
|
||||
func offset(value: CGPoint, animationCurve: ContainedViewLayoutTransitionCurve, duration: Double)
|
||||
func offsetSpring(value: CGFloat, duration: Double, damping: CGFloat)
|
||||
}
|
||||
@ -262,6 +263,23 @@ final class WallpaperBackgroundNodeImpl: ASDisplayNode, WallpaperBackgroundNode
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func update(rect: CGRect, within containerSize: CGSize, animator: ControlledTransitionAnimator) {
|
||||
self.currentLayout = (rect, containerSize)
|
||||
|
||||
let shiftedContentsRect = CGRect(origin: CGPoint(x: rect.minX / containerSize.width, y: rect.minY / containerSize.height), size: CGSize(width: rect.width / containerSize.width, height: rect.height / containerSize.height))
|
||||
|
||||
animator.updateFrame(layer: self.contentNode.layer, frame: self.bounds, completion: nil)
|
||||
animator.updateContentsRect(layer: self.contentNode.layer, contentsRect: shiftedContentsRect, completion: nil)
|
||||
if let cleanWallpaperNode = self.cleanWallpaperNode {
|
||||
animator.updateFrame(layer: cleanWallpaperNode.layer, frame: self.bounds, completion: nil)
|
||||
animator.updateContentsRect(layer: cleanWallpaperNode.layer, contentsRect: shiftedContentsRect, completion: nil)
|
||||
}
|
||||
if let gradientWallpaperNode = self.gradientWallpaperNode {
|
||||
animator.updateFrame(layer: gradientWallpaperNode.layer, frame: self.bounds, completion: nil)
|
||||
animator.updateContentsRect(layer: gradientWallpaperNode.layer, contentsRect: shiftedContentsRect, completion: nil)
|
||||
}
|
||||
}
|
||||
|
||||
func update(rect: CGRect, within containerSize: CGSize, transition: CombinedTransition) {
|
||||
self.currentLayout = (rect, containerSize)
|
||||
@ -1177,6 +1195,23 @@ final class WallpaperBackgroundNodeMergedImpl: ASDisplayNode, WallpaperBackgroun
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func update(rect: CGRect, within containerSize: CGSize, animator: ControlledTransitionAnimator) {
|
||||
self.currentLayout = (rect, containerSize)
|
||||
|
||||
let shiftedContentsRect = CGRect(origin: CGPoint(x: rect.minX / containerSize.width, y: rect.minY / containerSize.height), size: CGSize(width: rect.width / containerSize.width, height: rect.height / containerSize.height))
|
||||
|
||||
animator.updateFrame(layer: self.contentNode.layer, frame: self.bounds, completion: nil)
|
||||
animator.updateContentsRect(layer: self.contentNode.layer, contentsRect: shiftedContentsRect, completion: nil)
|
||||
if let cleanWallpaperNode = self.cleanWallpaperNode {
|
||||
animator.updateFrame(layer: cleanWallpaperNode.layer, frame: self.bounds, completion: nil)
|
||||
animator.updateContentsRect(layer: cleanWallpaperNode.layer, contentsRect: shiftedContentsRect, completion: nil)
|
||||
}
|
||||
if let gradientWallpaperNode = self.gradientWallpaperNode {
|
||||
animator.updateFrame(layer: gradientWallpaperNode.layer, frame: self.bounds, completion: nil)
|
||||
animator.updateContentsRect(layer: gradientWallpaperNode.layer, contentsRect: shiftedContentsRect, completion: nil)
|
||||
}
|
||||
}
|
||||
|
||||
func update(rect: CGRect, within containerSize: CGSize, transition: CombinedTransition) {
|
||||
self.currentLayout = (rect, containerSize)
|
||||
|
Loading…
x
Reference in New Issue
Block a user