mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Support blurred RadialStatusNode
This commit is contained in:
parent
22bbf738fa
commit
54e048b610
@ -1,48 +1,6 @@
|
||||
import Foundation
|
||||
import UIKit
|
||||
import AsyncDisplayKit
|
||||
import Display
|
||||
|
||||
private final class RadialStatusBackgroundNodeParameters: NSObject {
|
||||
let color: UIColor
|
||||
|
||||
init(color: UIColor) {
|
||||
self.color = color
|
||||
}
|
||||
}
|
||||
|
||||
final class RadialStatusBackgroundNode: ASDisplayNode {
|
||||
var color: UIColor {
|
||||
didSet {
|
||||
self.setNeedsDisplay()
|
||||
}
|
||||
}
|
||||
|
||||
init(color: UIColor, synchronous: Bool) {
|
||||
self.color = color
|
||||
|
||||
super.init()
|
||||
|
||||
self.displaysAsynchronously = !synchronous
|
||||
self.isLayerBacked = true
|
||||
self.isOpaque = false
|
||||
}
|
||||
|
||||
override func drawParameters(forAsyncLayer layer: _ASDisplayLayer) -> NSObjectProtocol? {
|
||||
return RadialStatusBackgroundNodeParameters(color: self.color)
|
||||
}
|
||||
|
||||
@objc override class func draw(_ bounds: CGRect, withParameters parameters: Any?, isCancelled: () -> Bool, isRasterizing: Bool) {
|
||||
let context = UIGraphicsGetCurrentContext()!
|
||||
|
||||
if !isRasterizing {
|
||||
context.setBlendMode(.copy)
|
||||
context.setFillColor(UIColor.clear.cgColor)
|
||||
context.fill(bounds)
|
||||
}
|
||||
|
||||
if let parameters = parameters as? RadialStatusBackgroundNodeParameters {
|
||||
context.setFillColor(parameters.color.cgColor)
|
||||
context.fillEllipse(in: bounds)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import Foundation
|
||||
import UIKit
|
||||
import AsyncDisplayKit
|
||||
import Display
|
||||
|
||||
public enum RadialStatusNodeState: Equatable {
|
||||
case none
|
||||
@ -190,14 +191,19 @@ public final class RadialStatusNode: ASControlNode {
|
||||
self.transitionToBackgroundColor(self.state.backgroundColor(color: self.backgroundNodeColor), previousContentNode: nil, animated: false, synchronous: false, completion: {})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private let enableBlur: Bool
|
||||
|
||||
public private(set) var state: RadialStatusNodeState = .none
|
||||
|
||||
private var backgroundNode: RadialStatusBackgroundNode?
|
||||
private var backgroundNode: NavigationBackgroundNode?
|
||||
private var currentBackgroundNodeColor: UIColor?
|
||||
|
||||
private var contentNode: RadialStatusContentNode?
|
||||
private var nextContentNode: RadialStatusContentNode?
|
||||
|
||||
public init(backgroundNodeColor: UIColor) {
|
||||
public init(backgroundNodeColor: UIColor, enableBlur: Bool = false) {
|
||||
self.enableBlur = enableBlur
|
||||
self.backgroundNodeColor = backgroundNodeColor
|
||||
|
||||
super.init()
|
||||
@ -287,7 +293,7 @@ public final class RadialStatusNode: ASControlNode {
|
||||
}
|
||||
|
||||
private func transitionToBackgroundColor(_ color: UIColor?, previousContentNode: RadialStatusContentNode?, animated: Bool, synchronous: Bool, completion: @escaping () -> Void) {
|
||||
let currentColor = self.backgroundNode?.color
|
||||
let currentColor = self.currentBackgroundNodeColor
|
||||
|
||||
var updated = false
|
||||
if let color = color, let currentColor = currentColor {
|
||||
@ -299,11 +305,16 @@ public final class RadialStatusNode: ASControlNode {
|
||||
if updated {
|
||||
if let color = color {
|
||||
if let backgroundNode = self.backgroundNode {
|
||||
backgroundNode.color = color
|
||||
backgroundNode.updateColor(color: color, transition: .immediate)
|
||||
self.currentBackgroundNodeColor = color
|
||||
|
||||
completion()
|
||||
} else {
|
||||
let backgroundNode = RadialStatusBackgroundNode(color: color, synchronous: synchronous)
|
||||
let backgroundNode = NavigationBackgroundNode(color: color, enableBlur: self.enableBlur)
|
||||
self.currentBackgroundNodeColor = color
|
||||
|
||||
backgroundNode.frame = self.bounds
|
||||
backgroundNode.update(size: backgroundNode.bounds.size, cornerRadius: backgroundNode.bounds.size.height / 2.0, transition: .immediate)
|
||||
self.backgroundNode = backgroundNode
|
||||
self.insertSubnode(backgroundNode, at: 0)
|
||||
|
||||
@ -318,6 +329,7 @@ public final class RadialStatusNode: ASControlNode {
|
||||
}
|
||||
} else if let backgroundNode = self.backgroundNode {
|
||||
self.backgroundNode = nil
|
||||
self.currentBackgroundNodeColor = nil
|
||||
if animated {
|
||||
backgroundNode.layer.animateScale(from: 1.0, to: 0.01, duration: 0.2, removeOnCompletion: false)
|
||||
previousContentNode?.layer.animateScale(from: 1.0, to: 0.01, duration: 0.2, removeOnCompletion: false)
|
||||
@ -336,7 +348,10 @@ public final class RadialStatusNode: ASControlNode {
|
||||
}
|
||||
|
||||
override public func layout() {
|
||||
self.backgroundNode?.frame = self.bounds
|
||||
if let backgroundNode = self.backgroundNode {
|
||||
backgroundNode.frame = self.bounds
|
||||
backgroundNode.update(size: backgroundNode.bounds.size, cornerRadius: backgroundNode.bounds.size.height / 2.0, transition: .immediate)
|
||||
}
|
||||
if let contentNode = self.contentNode {
|
||||
contentNode.frame = self.bounds
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ final class SettingsThemeWallpaperNode: ASDisplayNode {
|
||||
self.displayLoading = displayLoading
|
||||
self.imageNode.contentAnimations = [.subsequentUpdates]
|
||||
|
||||
self.statusNode = RadialStatusNode(backgroundNodeColor: overlayBackgroundColor)
|
||||
self.statusNode = RadialStatusNode(backgroundNodeColor: overlayBackgroundColor, enableBlur: true)
|
||||
let progressDiameter: CGFloat = 50.0
|
||||
self.statusNode.frame = CGRect(x: 0.0, y: 0.0, width: progressDiameter, height: progressDiameter)
|
||||
self.statusNode.isUserInteractionEnabled = false
|
||||
@ -170,7 +170,7 @@ final class SettingsThemeWallpaperNode: ASDisplayNode {
|
||||
switch wallpaper {
|
||||
case .builtin:
|
||||
self.imageNode.alpha = 1.0
|
||||
self.imageNode.setSignal(settingsBuiltinWallpaperImage(account: context.account))
|
||||
self.imageNode.setSignal(settingsBuiltinWallpaperImage(account: context.account, thumbnail: true))
|
||||
let apply = self.imageNode.asyncLayout()(TransformImageArguments(corners: corners, imageSize: CGSize(), boundingSize: size, intrinsicInsets: UIEdgeInsets()))
|
||||
apply()
|
||||
self.isLoadedDisposable.set(nil)
|
||||
|
Loading…
x
Reference in New Issue
Block a user