mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 22:55:00 +00:00
no message
This commit is contained in:
@@ -31,7 +31,7 @@ enum ActivityIndicatorSpeed {
|
||||
final class ActivityIndicator: ASDisplayNode {
|
||||
var type: ActivityIndicatorType {
|
||||
didSet {
|
||||
switch type {
|
||||
switch self.type {
|
||||
case let .navigationAccent(theme):
|
||||
self.indicatorNode.image = PresentationResourcesRootController.navigationIndefiniteActivityImage(theme)
|
||||
case let .custom(color, diameter, lineWidth):
|
||||
@@ -40,6 +40,14 @@ final class ActivityIndicator: ASDisplayNode {
|
||||
}
|
||||
}
|
||||
|
||||
private var currentInHierarchy = false
|
||||
|
||||
override var isHidden: Bool {
|
||||
didSet {
|
||||
self.updateAnimation()
|
||||
}
|
||||
}
|
||||
|
||||
private let speed: ActivityIndicatorSpeed
|
||||
|
||||
private let indicatorNode: ASImageNode
|
||||
@@ -67,29 +75,48 @@ final class ActivityIndicator: ASDisplayNode {
|
||||
self.addSubnode(self.indicatorNode)
|
||||
}
|
||||
|
||||
private var isAnimating = false {
|
||||
didSet {
|
||||
if self.isAnimating != oldValue {
|
||||
if self.isAnimating {
|
||||
let basicAnimation = CABasicAnimation(keyPath: "transform.rotation.z")
|
||||
basicAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
|
||||
switch self.speed {
|
||||
case .regular:
|
||||
basicAnimation.duration = 0.5
|
||||
case .slow:
|
||||
basicAnimation.duration = 0.7
|
||||
}
|
||||
basicAnimation.fromValue = NSNumber(value: Float(0.0))
|
||||
basicAnimation.toValue = NSNumber(value: Float.pi * 2.0)
|
||||
basicAnimation.repeatCount = Float.infinity
|
||||
basicAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
|
||||
basicAnimation.beginTime = 1.0
|
||||
|
||||
self.indicatorNode.layer.add(basicAnimation, forKey: "progressRotation")
|
||||
} else {
|
||||
self.indicatorNode.layer.removeAnimation(forKey: "progressRotation")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func updateAnimation() {
|
||||
self.isAnimating = !self.isHidden && self.currentInHierarchy
|
||||
}
|
||||
|
||||
override func willEnterHierarchy() {
|
||||
super.willEnterHierarchy()
|
||||
|
||||
let basicAnimation = CABasicAnimation(keyPath: "transform.rotation.z")
|
||||
basicAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
|
||||
switch self.speed {
|
||||
case .regular:
|
||||
basicAnimation.duration = 0.5
|
||||
case .slow:
|
||||
basicAnimation.duration = 0.7
|
||||
}
|
||||
basicAnimation.fromValue = NSNumber(value: Float(0.0))
|
||||
basicAnimation.toValue = NSNumber(value: Float.pi * 2.0)
|
||||
basicAnimation.repeatCount = Float.infinity
|
||||
basicAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
|
||||
|
||||
self.indicatorNode.layer.add(basicAnimation, forKey: "progressRotation")
|
||||
self.currentInHierarchy = true
|
||||
self.updateAnimation()
|
||||
}
|
||||
|
||||
override func didExitHierarchy() {
|
||||
super.didExitHierarchy()
|
||||
|
||||
self.indicatorNode.layer.removeAnimation(forKey: "progressRotation")
|
||||
self.currentInHierarchy = false
|
||||
self.updateAnimation()
|
||||
}
|
||||
|
||||
override func calculateSizeThatFits(_ constrainedSize: CGSize) -> CGSize {
|
||||
|
||||
Reference in New Issue
Block a user