From 762a1ed6a53e860eadf6d8f83e29b8afd30f8db0 Mon Sep 17 00:00:00 2001 From: Ali <> Date: Mon, 26 Dec 2022 21:59:16 +0400 Subject: [PATCH] Storage usage: add optimistic loading delay --- .../Sources/StorageUsageScreen.swift | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StorageUsageScreen.swift b/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StorageUsageScreen.swift index 4645266da0..d4f0f9f1d4 100644 --- a/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StorageUsageScreen.swift +++ b/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StorageUsageScreen.swift @@ -113,15 +113,18 @@ final class StorageUsageScreenComponent: Component { let context: AccountContext let makeStorageUsageExceptionsScreen: (CacheStorageSettings.PeerStorageCategory) -> ViewController? let peer: EnginePeer? + let ready: Promise init( context: AccountContext, makeStorageUsageExceptionsScreen: @escaping (CacheStorageSettings.PeerStorageCategory) -> ViewController?, - peer: EnginePeer? + peer: EnginePeer?, + ready: Promise ) { self.context = context self.makeStorageUsageExceptionsScreen = makeStorageUsageExceptionsScreen self.peer = peer + self.ready = ready } static func ==(lhs: StorageUsageScreenComponent, rhs: StorageUsageScreenComponent) -> Bool { @@ -562,9 +565,13 @@ final class StorageUsageScreenComponent: Component { } else { if let loadingView = self.loadingView { self.loadingView = nil - loadingView.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false, completion: { [weak loadingView] _ in - loadingView?.removeFromSuperview() - }) + if environment.isVisible { + loadingView.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false, completion: { [weak loadingView] _ in + loadingView?.removeFromSuperview() + }) + } else { + loadingView.removeFromSuperview() + } } } @@ -651,7 +658,12 @@ final class StorageUsageScreenComponent: Component { if let animationHint { if case .firstStatsUpdate = animationHint.value { - let alphaTransition: Transition = .easeInOut(duration: 0.25) + let alphaTransition: Transition + if environment.isVisible { + alphaTransition = .easeInOut(duration: 0.25) + } else { + alphaTransition = .immediate + } alphaTransition.setAlpha(view: self.scrollView, alpha: self.currentStats != nil ? 1.0 : 0.0) alphaTransition.setAlpha(view: self.headerOffsetContainer, alpha: self.currentStats != nil ? 1.0 : 0.0) } else if case .clearedItems = animationHint.value { @@ -1786,6 +1798,7 @@ final class StorageUsageScreenComponent: Component { if firstTime { self.peerItems = StoragePeerListPanelComponent.Items(items: peerItems) self.state?.updated(transition: Transition(animation: .none).withUserData(AnimationHint(value: .firstStatsUpdate))) + self.component?.ready.set(.single(true)) } class RenderResult { @@ -2356,16 +2369,24 @@ final class StorageUsageScreenComponent: Component { public final class StorageUsageScreen: ViewControllerComponentContainer { private let context: AccountContext + private let readyValue = Promise() + override public var ready: Promise { + return self.readyValue + } + fileprivate var childCompleted: ((@escaping () -> Void) -> Void)? public init(context: AccountContext, makeStorageUsageExceptionsScreen: @escaping (CacheStorageSettings.PeerStorageCategory) -> ViewController?, peer: EnginePeer? = nil) { self.context = context - super.init(context: context, component: StorageUsageScreenComponent(context: context, makeStorageUsageExceptionsScreen: makeStorageUsageExceptionsScreen, peer: peer), navigationBarAppearance: .transparent) + let componentReady = Promise() + super.init(context: context, component: StorageUsageScreenComponent(context: context, makeStorageUsageExceptionsScreen: makeStorageUsageExceptionsScreen, peer: peer, ready: componentReady), navigationBarAppearance: .transparent) if peer != nil { self.navigationPresentation = .modal } + + self.readyValue.set(componentReady.get() |> timeout(0.3, queue: .mainQueue(), alternate: .single(true))) } required public init(coder aDecoder: NSCoder) {