diff --git a/submodules/GradientBackground/Sources/GradientBackground.swift b/submodules/GradientBackground/Sources/GradientBackground.swift index c2c1babfae..352d1aacf4 100644 --- a/submodules/GradientBackground/Sources/GradientBackground.swift +++ b/submodules/GradientBackground/Sources/GradientBackground.swift @@ -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) } diff --git a/submodules/GradientBackground/Sources/SoftwareGradientBackground.swift b/submodules/GradientBackground/Sources/SoftwareGradientBackground.swift index e927c5842f..81366c7efb 100644 --- a/submodules/GradientBackground/Sources/SoftwareGradientBackground.swift +++ b/submodules/GradientBackground/Sources/SoftwareGradientBackground.swift @@ -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) + } } } diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index 7ebf90553a..99993c70e5 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -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 diff --git a/submodules/WallpaperBackgroundNode/Sources/WallpaperBackgroundNode.swift b/submodules/WallpaperBackgroundNode/Sources/WallpaperBackgroundNode.swift index 7dd8c0270f..21a47e8a79 100644 --- a/submodules/WallpaperBackgroundNode/Sources/WallpaperBackgroundNode.swift +++ b/submodules/WallpaperBackgroundNode/Sources/WallpaperBackgroundNode.swift @@ -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