mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-11-07 09:20:08 +00:00
Support blurred RadialStatusNode
This commit is contained in:
parent
22bbf738fa
commit
54e048b610
@ -1,48 +1,6 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import UIKit
|
import UIKit
|
||||||
import AsyncDisplayKit
|
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 Foundation
|
||||||
import UIKit
|
import UIKit
|
||||||
import AsyncDisplayKit
|
import AsyncDisplayKit
|
||||||
|
import Display
|
||||||
|
|
||||||
public enum RadialStatusNodeState: Equatable {
|
public enum RadialStatusNodeState: Equatable {
|
||||||
case none
|
case none
|
||||||
@ -191,13 +192,18 @@ public final class RadialStatusNode: ASControlNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private let enableBlur: Bool
|
||||||
|
|
||||||
public private(set) var state: RadialStatusNodeState = .none
|
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 contentNode: RadialStatusContentNode?
|
||||||
private var nextContentNode: RadialStatusContentNode?
|
private var nextContentNode: RadialStatusContentNode?
|
||||||
|
|
||||||
public init(backgroundNodeColor: UIColor) {
|
public init(backgroundNodeColor: UIColor, enableBlur: Bool = false) {
|
||||||
|
self.enableBlur = enableBlur
|
||||||
self.backgroundNodeColor = backgroundNodeColor
|
self.backgroundNodeColor = backgroundNodeColor
|
||||||
|
|
||||||
super.init()
|
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) {
|
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
|
var updated = false
|
||||||
if let color = color, let currentColor = currentColor {
|
if let color = color, let currentColor = currentColor {
|
||||||
@ -299,11 +305,16 @@ public final class RadialStatusNode: ASControlNode {
|
|||||||
if updated {
|
if updated {
|
||||||
if let color = color {
|
if let color = color {
|
||||||
if let backgroundNode = self.backgroundNode {
|
if let backgroundNode = self.backgroundNode {
|
||||||
backgroundNode.color = color
|
backgroundNode.updateColor(color: color, transition: .immediate)
|
||||||
|
self.currentBackgroundNodeColor = color
|
||||||
|
|
||||||
completion()
|
completion()
|
||||||
} else {
|
} else {
|
||||||
let backgroundNode = RadialStatusBackgroundNode(color: color, synchronous: synchronous)
|
let backgroundNode = NavigationBackgroundNode(color: color, enableBlur: self.enableBlur)
|
||||||
|
self.currentBackgroundNodeColor = color
|
||||||
|
|
||||||
backgroundNode.frame = self.bounds
|
backgroundNode.frame = self.bounds
|
||||||
|
backgroundNode.update(size: backgroundNode.bounds.size, cornerRadius: backgroundNode.bounds.size.height / 2.0, transition: .immediate)
|
||||||
self.backgroundNode = backgroundNode
|
self.backgroundNode = backgroundNode
|
||||||
self.insertSubnode(backgroundNode, at: 0)
|
self.insertSubnode(backgroundNode, at: 0)
|
||||||
|
|
||||||
@ -318,6 +329,7 @@ public final class RadialStatusNode: ASControlNode {
|
|||||||
}
|
}
|
||||||
} else if let backgroundNode = self.backgroundNode {
|
} else if let backgroundNode = self.backgroundNode {
|
||||||
self.backgroundNode = nil
|
self.backgroundNode = nil
|
||||||
|
self.currentBackgroundNodeColor = nil
|
||||||
if animated {
|
if animated {
|
||||||
backgroundNode.layer.animateScale(from: 1.0, to: 0.01, duration: 0.2, removeOnCompletion: false)
|
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)
|
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() {
|
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 {
|
if let contentNode = self.contentNode {
|
||||||
contentNode.frame = self.bounds
|
contentNode.frame = self.bounds
|
||||||
}
|
}
|
||||||
|
|||||||
@ -52,7 +52,7 @@ final class SettingsThemeWallpaperNode: ASDisplayNode {
|
|||||||
self.displayLoading = displayLoading
|
self.displayLoading = displayLoading
|
||||||
self.imageNode.contentAnimations = [.subsequentUpdates]
|
self.imageNode.contentAnimations = [.subsequentUpdates]
|
||||||
|
|
||||||
self.statusNode = RadialStatusNode(backgroundNodeColor: overlayBackgroundColor)
|
self.statusNode = RadialStatusNode(backgroundNodeColor: overlayBackgroundColor, enableBlur: true)
|
||||||
let progressDiameter: CGFloat = 50.0
|
let progressDiameter: CGFloat = 50.0
|
||||||
self.statusNode.frame = CGRect(x: 0.0, y: 0.0, width: progressDiameter, height: progressDiameter)
|
self.statusNode.frame = CGRect(x: 0.0, y: 0.0, width: progressDiameter, height: progressDiameter)
|
||||||
self.statusNode.isUserInteractionEnabled = false
|
self.statusNode.isUserInteractionEnabled = false
|
||||||
@ -170,7 +170,7 @@ final class SettingsThemeWallpaperNode: ASDisplayNode {
|
|||||||
switch wallpaper {
|
switch wallpaper {
|
||||||
case .builtin:
|
case .builtin:
|
||||||
self.imageNode.alpha = 1.0
|
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()))
|
let apply = self.imageNode.asyncLayout()(TransformImageArguments(corners: corners, imageSize: CGSize(), boundingSize: size, intrinsicInsets: UIEdgeInsets()))
|
||||||
apply()
|
apply()
|
||||||
self.isLoadedDisposable.set(nil)
|
self.isLoadedDisposable.set(nil)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user