mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Don't cache temporary images
This commit is contained in:
parent
374dc79d6d
commit
f8ceb1d461
@ -3,6 +3,6 @@ import UIKit
|
|||||||
import Display
|
import Display
|
||||||
import AsyncDisplayKit
|
import AsyncDisplayKit
|
||||||
|
|
||||||
public func createGradientBackgroundNode(useSharedAnimationPhase: Bool = false) -> GradientBackgroundNode {
|
public func createGradientBackgroundNode(colors: [UIColor]? = nil, useSharedAnimationPhase: Bool = false) -> GradientBackgroundNode {
|
||||||
return GradientBackgroundNode(useSharedAnimationPhase: useSharedAnimationPhase)
|
return GradientBackgroundNode(colors: colors, useSharedAnimationPhase: useSharedAnimationPhase)
|
||||||
}
|
}
|
||||||
|
@ -192,6 +192,7 @@ public final class GradientBackgroundNode: ASDisplayNode {
|
|||||||
return generateGradient(size: size, colors: colors, positions: positions)
|
return generateGradient(size: size, colors: colors, positions: positions)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var colors: [UIColor]
|
||||||
private var phase: Int = 0
|
private var phase: Int = 0
|
||||||
|
|
||||||
public let contentView: UIImageView
|
public let contentView: UIImageView
|
||||||
@ -213,13 +214,6 @@ public final class GradientBackgroundNode: ASDisplayNode {
|
|||||||
|
|
||||||
private var validLayout: CGSize?
|
private var validLayout: CGSize?
|
||||||
|
|
||||||
private var colors: [UIColor] = [
|
|
||||||
UIColor(rgb: 0x7FA381),
|
|
||||||
UIColor(rgb: 0xFFF5C5),
|
|
||||||
UIColor(rgb: 0x336F55),
|
|
||||||
UIColor(rgb: 0xFBE37D)
|
|
||||||
]
|
|
||||||
|
|
||||||
private struct PhaseTransitionKey: Hashable {
|
private struct PhaseTransitionKey: Hashable {
|
||||||
var width: Int
|
var width: Int
|
||||||
var height: Int
|
var height: Int
|
||||||
@ -234,9 +228,16 @@ public final class GradientBackgroundNode: ASDisplayNode {
|
|||||||
private let useSharedAnimationPhase: Bool
|
private let useSharedAnimationPhase: Bool
|
||||||
static var sharedPhase: Int = 0
|
static var sharedPhase: Int = 0
|
||||||
|
|
||||||
public init(useSharedAnimationPhase: Bool = false) {
|
public init(colors: [UIColor]? = nil, useSharedAnimationPhase: Bool = false) {
|
||||||
self.useSharedAnimationPhase = useSharedAnimationPhase
|
self.useSharedAnimationPhase = useSharedAnimationPhase
|
||||||
self.contentView = UIImageView()
|
self.contentView = UIImageView()
|
||||||
|
let defaultColors: [UIColor] = [
|
||||||
|
UIColor(rgb: 0x7FA381),
|
||||||
|
UIColor(rgb: 0xFFF5C5),
|
||||||
|
UIColor(rgb: 0x336F55),
|
||||||
|
UIColor(rgb: 0xFBE37D)
|
||||||
|
]
|
||||||
|
self.colors = colors ?? defaultColors
|
||||||
|
|
||||||
super.init()
|
super.init()
|
||||||
|
|
||||||
@ -395,12 +396,25 @@ public final class GradientBackgroundNode: ASDisplayNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public func updateColors(colors: [UIColor]) {
|
public func updateColors(colors: [UIColor]) {
|
||||||
|
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.colors = colors
|
||||||
self.invalidated = true
|
self.invalidated = true
|
||||||
if let size = self.validLayout {
|
if let size = self.validLayout {
|
||||||
self.updateLayout(size: size, transition: .immediate)
|
self.updateLayout(size: size, transition: .immediate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func animateEvent(transition: ContainedViewLayoutTransition, extendAnimation: Bool = false) {
|
public func animateEvent(transition: ContainedViewLayoutTransition, extendAnimation: Bool = false) {
|
||||||
guard case let .animated(duration, _) = transition, duration > 0.001 else {
|
guard case let .animated(duration, _) = transition, duration > 0.001 else {
|
||||||
|
@ -434,8 +434,15 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
|||||||
self.botStart = botStart
|
self.botStart = botStart
|
||||||
self.peekData = peekData
|
self.peekData = peekData
|
||||||
|
|
||||||
self.chatBackgroundNode = WallpaperBackgroundNode(context: context, useSharedAnimationPhase: true)
|
var useSharedAnimationPhase = false
|
||||||
self.wallpaperReady.set(chatBackgroundNode.isReady)
|
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 locationBroadcastPanelSource: LocationBroadcastPanelSource
|
||||||
var groupCallPanelSource: GroupCallPanelSource
|
var groupCallPanelSource: GroupCallPanelSource
|
||||||
|
@ -391,15 +391,16 @@ public final class WallpaperBackgroundNode: ASDisplayNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if gradientColors.count >= 3 {
|
if gradientColors.count >= 3 {
|
||||||
|
let mappedColors = gradientColors.map { color -> UIColor in
|
||||||
|
return UIColor(rgb: color)
|
||||||
|
}
|
||||||
if self.gradientBackgroundNode == nil {
|
if self.gradientBackgroundNode == nil {
|
||||||
let gradientBackgroundNode = createGradientBackgroundNode(useSharedAnimationPhase: self.useSharedAnimationPhase)
|
let gradientBackgroundNode = createGradientBackgroundNode(colors: mappedColors, useSharedAnimationPhase: self.useSharedAnimationPhase)
|
||||||
self.gradientBackgroundNode = gradientBackgroundNode
|
self.gradientBackgroundNode = gradientBackgroundNode
|
||||||
self.insertSubnode(gradientBackgroundNode, aboveSubnode: self.contentNode)
|
self.insertSubnode(gradientBackgroundNode, aboveSubnode: self.contentNode)
|
||||||
gradientBackgroundNode.addSubnode(self.patternImageNode)
|
gradientBackgroundNode.addSubnode(self.patternImageNode)
|
||||||
}
|
}
|
||||||
self.gradientBackgroundNode?.updateColors(colors: gradientColors.map { color -> UIColor in
|
self.gradientBackgroundNode?.updateColors(colors: mappedColors)
|
||||||
return UIColor(rgb: color)
|
|
||||||
})
|
|
||||||
|
|
||||||
self.contentNode.backgroundColor = nil
|
self.contentNode.backgroundColor = nil
|
||||||
self.contentNode.contents = nil
|
self.contentNode.contents = nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user