Don't cache temporary images

This commit is contained in:
Ali 2021-06-15 15:06:48 +04:00
parent 374dc79d6d
commit f8ceb1d461
4 changed files with 42 additions and 20 deletions

View File

@ -3,6 +3,6 @@ import UIKit
import Display
import AsyncDisplayKit
public func createGradientBackgroundNode(useSharedAnimationPhase: Bool = false) -> GradientBackgroundNode {
return GradientBackgroundNode(useSharedAnimationPhase: useSharedAnimationPhase)
public func createGradientBackgroundNode(colors: [UIColor]? = nil, useSharedAnimationPhase: Bool = false) -> GradientBackgroundNode {
return GradientBackgroundNode(colors: colors, useSharedAnimationPhase: useSharedAnimationPhase)
}

View File

@ -192,6 +192,7 @@ public final class GradientBackgroundNode: ASDisplayNode {
return generateGradient(size: size, colors: colors, positions: positions)
}
private var colors: [UIColor]
private var phase: Int = 0
public let contentView: UIImageView
@ -213,13 +214,6 @@ public final class GradientBackgroundNode: ASDisplayNode {
private var validLayout: CGSize?
private var colors: [UIColor] = [
UIColor(rgb: 0x7FA381),
UIColor(rgb: 0xFFF5C5),
UIColor(rgb: 0x336F55),
UIColor(rgb: 0xFBE37D)
]
private struct PhaseTransitionKey: Hashable {
var width: Int
var height: Int
@ -234,9 +228,16 @@ public final class GradientBackgroundNode: ASDisplayNode {
private let useSharedAnimationPhase: Bool
static var sharedPhase: Int = 0
public init(useSharedAnimationPhase: Bool = false) {
public init(colors: [UIColor]? = nil, useSharedAnimationPhase: Bool = false) {
self.useSharedAnimationPhase = useSharedAnimationPhase
self.contentView = UIImageView()
let defaultColors: [UIColor] = [
UIColor(rgb: 0x7FA381),
UIColor(rgb: 0xFFF5C5),
UIColor(rgb: 0x336F55),
UIColor(rgb: 0xFBE37D)
]
self.colors = colors ?? defaultColors
super.init()
@ -395,10 +396,23 @@ public final class GradientBackgroundNode: ASDisplayNode {
}
public func updateColors(colors: [UIColor]) {
self.colors = colors
self.invalidated = true
if let size = self.validLayout {
self.updateLayout(size: size, transition: .immediate)
var updated = false
if self.colors.count != colors.count {
updated = true
} else {
for i in 0 ..< self.colors.count {
if !self.colors[i].isEqual(colors[i]) {
updated = true
break
}
}
}
if updated {
self.colors = colors
self.invalidated = true
if let size = self.validLayout {
self.updateLayout(size: size, transition: .immediate)
}
}
}

View File

@ -434,8 +434,15 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
self.botStart = botStart
self.peekData = peekData
self.chatBackgroundNode = WallpaperBackgroundNode(context: context, useSharedAnimationPhase: true)
self.wallpaperReady.set(chatBackgroundNode.isReady)
var useSharedAnimationPhase = false
switch mode {
case .standard(false):
useSharedAnimationPhase = true
default:
break
}
self.chatBackgroundNode = WallpaperBackgroundNode(context: context, useSharedAnimationPhase: useSharedAnimationPhase)
self.wallpaperReady.set(self.chatBackgroundNode.isReady)
var locationBroadcastPanelSource: LocationBroadcastPanelSource
var groupCallPanelSource: GroupCallPanelSource

View File

@ -391,15 +391,16 @@ public final class WallpaperBackgroundNode: ASDisplayNode {
}
if gradientColors.count >= 3 {
let mappedColors = gradientColors.map { color -> UIColor in
return UIColor(rgb: color)
}
if self.gradientBackgroundNode == nil {
let gradientBackgroundNode = createGradientBackgroundNode(useSharedAnimationPhase: self.useSharedAnimationPhase)
let gradientBackgroundNode = createGradientBackgroundNode(colors: mappedColors, useSharedAnimationPhase: self.useSharedAnimationPhase)
self.gradientBackgroundNode = gradientBackgroundNode
self.insertSubnode(gradientBackgroundNode, aboveSubnode: self.contentNode)
gradientBackgroundNode.addSubnode(self.patternImageNode)
}
self.gradientBackgroundNode?.updateColors(colors: gradientColors.map { color -> UIColor in
return UIColor(rgb: color)
})
self.gradientBackgroundNode?.updateColors(colors: mappedColors)
self.contentNode.backgroundColor = nil
self.contentNode.contents = nil