From 4018360cab4089fadecc0ee1e20cdc341016a88b Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Wed, 22 Mar 2023 17:48:22 +0400 Subject: [PATCH] Various fixes --- submodules/AnimationUI/BUILD | 1 + .../AnimationUI/Sources/AnimationNode.swift | 15 +++++++- .../Sources/ViewControllerComponent.swift | 21 +++++++----- .../PremiumUI/Sources/PremiumGiftScreen.swift | 2 +- .../Sources/PeerInfo/PeerInfoHeaderNode.swift | 34 +++++++++++-------- 5 files changed, 49 insertions(+), 24 deletions(-) diff --git a/submodules/AnimationUI/BUILD b/submodules/AnimationUI/BUILD index c4701284a7..adf8470d17 100644 --- a/submodules/AnimationUI/BUILD +++ b/submodules/AnimationUI/BUILD @@ -13,6 +13,7 @@ swift_library( "//submodules/AsyncDisplayKit:AsyncDisplayKit", "//submodules/rlottie:RLottieBinding", "//submodules/lottie-ios:Lottie", + "//submodules/GZip:GZip", "//submodules/AppBundle:AppBundle", "//submodules/Display:Display", ], diff --git a/submodules/AnimationUI/Sources/AnimationNode.swift b/submodules/AnimationUI/Sources/AnimationNode.swift index e15a0cdc5a..c7f9391e20 100644 --- a/submodules/AnimationUI/Sources/AnimationNode.swift +++ b/submodules/AnimationUI/Sources/AnimationNode.swift @@ -2,6 +2,7 @@ import Foundation import UIKit import AsyncDisplayKit import Lottie +import GZip import AppBundle import Display @@ -32,7 +33,15 @@ public final class AnimationNode: ASDisplayNode { super.init() self.setViewBlock({ - if let animationName = animationName, let url = getAppBundle().url(forResource: animationName, withExtension: "json"), let animation = Animation.filepath(url.path) { + var animation: Animation? + if let animationName { + if let url = getAppBundle().url(forResource: animationName, withExtension: "json"), let maybeAnimation = Animation.filepath(url.path) { + animation = maybeAnimation + } else if let url = getAppBundle().url(forResource: animationName, withExtension: "tgs"), let data = try? Data(contentsOf: URL(fileURLWithPath: url.path)), let unpackedData = TGGUnzipData(data, 5 * 1024 * 1024) { + animation = try? Animation.from(data: unpackedData, strategy: .codable) + } + } + if let animation { let view = AnimationView(animation: animation, configuration: LottieConfiguration(renderingEngine: .mainThread, decodingStrategy: .codable)) view.animationSpeed = self.speed view.backgroundColor = .clear @@ -104,6 +113,10 @@ public final class AnimationNode: ASDisplayNode { self.animationView()?.currentProgress = 1.0 } + public func setProgress(_ progress: CGFloat) { + self.animationView()?.currentProgress = progress + } + public func setAnimation(name: String, colors: [String: UIColor]? = nil) { self.currentParams = (name, colors) if let url = getAppBundle().url(forResource: name, withExtension: "json"), let animation = Animation.filepath(url.path) { diff --git a/submodules/Components/ViewControllerComponent/Sources/ViewControllerComponent.swift b/submodules/Components/ViewControllerComponent/Sources/ViewControllerComponent.swift index ece9265938..0266f7142a 100644 --- a/submodules/Components/ViewControllerComponent/Sources/ViewControllerComponent.swift +++ b/submodules/Components/ViewControllerComponent/Sources/ViewControllerComponent.swift @@ -20,6 +20,11 @@ open class ViewControllerComponentContainer: ViewController { case `default` } + public enum PresentationMode { + case `default` + case modal + } + public final class Environment: Equatable { public let statusBarHeight: CGFloat public let navigationHeight: CGFloat @@ -139,11 +144,6 @@ open class ViewControllerComponentContainer: ViewController { func containerLayoutUpdated(layout: ContainerViewLayout, navigationHeight: CGFloat, transition: Transition) { self.currentLayout = (layout, navigationHeight) - var theme = self.theme ?? self.presentationData.theme - if theme.list.blocksBackgroundColor.rgb == theme.list.plainBackgroundColor.rgb { - theme = theme.withModalBlocksBackground() - } - let environment = ViewControllerComponentContainer.Environment( statusBarHeight: layout.statusBarHeight ?? 0.0, navigationHeight: navigationHeight, @@ -152,7 +152,7 @@ open class ViewControllerComponentContainer: ViewController { metrics: layout.metrics, deviceMetrics: layout.deviceMetrics, isVisible: self.currentIsVisible, - theme: theme, + theme: self.theme ?? self.presentationData.theme, strings: self.presentationData.strings, dateTimeFormat: self.presentationData.dateTimeFormat, controller: { [weak self] in @@ -203,7 +203,7 @@ open class ViewControllerComponentContainer: ViewController { private var presentationDataDisposable: Disposable? public private(set) var validLayout: ContainerViewLayout? - public init(context: AccountContext, component: C, navigationBarAppearance: NavigationBarAppearance, statusBarStyle: StatusBarStyle = .default, theme: PresentationTheme? = nil) where C.EnvironmentType == ViewControllerComponentContainer.Environment { + public init(context: AccountContext, component: C, navigationBarAppearance: NavigationBarAppearance, statusBarStyle: StatusBarStyle = .default, presentationMode: PresentationMode = .default, theme: PresentationTheme? = nil) where C.EnvironmentType == ViewControllerComponentContainer.Environment { self.context = context self.component = AnyComponent(component) self.theme = theme @@ -224,7 +224,12 @@ open class ViewControllerComponentContainer: ViewController { self.presentationDataDisposable = (self.context.sharedContext.presentationData |> deliverOnMainQueue).start(next: { [weak self] presentationData in if let strongSelf = self { - strongSelf.node.presentationData = presentationData + var theme = presentationData.theme + if case .modal = presentationMode, theme.list.blocksBackgroundColor.rgb == theme.list.plainBackgroundColor.rgb { + theme = theme.withModalBlocksBackground() + } + + strongSelf.node.presentationData = presentationData.withUpdated(theme: theme) switch statusBarStyle { case .none: diff --git a/submodules/PremiumUI/Sources/PremiumGiftScreen.swift b/submodules/PremiumUI/Sources/PremiumGiftScreen.swift index 777e0f9e2c..adf80c4f64 100644 --- a/submodules/PremiumUI/Sources/PremiumGiftScreen.swift +++ b/submodules/PremiumUI/Sources/PremiumGiftScreen.swift @@ -1032,7 +1032,7 @@ public final class PremiumGiftScreen: ViewControllerComponentContainer, Attachme completion: { duration in completionImpl?(duration) } - ), navigationBarAppearance: .transparent) + ), navigationBarAppearance: .transparent, presentationMode: .modal) let presentationData = context.sharedContext.currentPresentationData.with { $0 } diff --git a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoHeaderNode.swift b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoHeaderNode.swift index 00170656e8..aa21e6fffb 100644 --- a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoHeaderNode.swift +++ b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoHeaderNode.swift @@ -1044,7 +1044,7 @@ final class PeerInfoAvatarListNode: ASDisplayNode { self.bottomCoverNode = ASDisplayNode() self.bottomCoverNode.backgroundColor = .black - self.maskNode = DynamicIslandMaskNode(size: CGSize(width: 512.0, height: 512.0)) + self.maskNode = DynamicIslandMaskNode() self.pinchSourceNode = PinchSourceContainerNode() self.avatarContainerNode = PeerInfoAvatarTransformContainerNode(context: context) @@ -3678,29 +3678,35 @@ final class PeerInfoHeaderNode: ASDisplayNode { } } -private class DynamicIslandMaskNode: ManagedAnimationNode { - var frameIndex: Int = 0 +private class DynamicIslandMaskNode: ASDisplayNode { + private var animationNode: AnimationNode? var isForum = false { didSet { if self.isForum != oldValue { - self.update(frameIndex: self.frameIndex) + self.animationNode?.removeFromSupernode() + let animationNode = AnimationNode(animation: "ForumAvatarMask") + self.addSubnode(animationNode) + self.animationNode = animationNode } } } - func update(_ value: CGFloat) { - let lowerBound = 0 - let upperBound = 540 - let frameIndex = lowerBound + Int(value * CGFloat(upperBound - lowerBound)) - if frameIndex != self.frameIndex { - self.update(frameIndex: frameIndex) - } + override init() { + let animationNode = AnimationNode(animation: "UserAvatarMask") + self.animationNode = animationNode + + super.init() + + self.addSubnode(animationNode) } - func update(frameIndex: Int) { - self.frameIndex = frameIndex - self.trackTo(item: ManagedAnimationItem(source: .local(self.isForum ? "ForumAvatarMask" : "UserAvatarMask"), frames: .range(startFrame: frameIndex, endFrame: frameIndex), duration: 0.001)) + func update(_ value: CGFloat) { + self.animationNode?.setProgress(value) + } + + override func layout() { + self.animationNode?.frame = self.bounds } }