From 2fa059477c18b815a28f5d0e887bb309e48cd9a7 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Fri, 25 Oct 2024 03:04:39 +0400 Subject: [PATCH] Various fixes --- .../Sources/StarsStatisticsScreen.swift | 26 +++++++- .../StarsTransactionsListPanelComponent.swift | 13 +++- ...sTransactionsPanelContainerComponent.swift | 7 +++ .../Sources/StarsTransactionsScreen.swift | 60 +++++++++++++++---- .../Sources/StorageUsageScreen.swift | 22 +++++++ 5 files changed, 113 insertions(+), 15 deletions(-) diff --git a/submodules/TelegramUI/Components/Stars/StarsTransactionsScreen/Sources/StarsStatisticsScreen.swift b/submodules/TelegramUI/Components/Stars/StarsTransactionsScreen/Sources/StarsStatisticsScreen.swift index ee82996b1c..fe094d65b1 100644 --- a/submodules/TelegramUI/Components/Stars/StarsTransactionsScreen/Sources/StarsStatisticsScreen.swift +++ b/submodules/TelegramUI/Components/Stars/StarsTransactionsScreen/Sources/StarsStatisticsScreen.swift @@ -181,8 +181,8 @@ final class StarsStatisticsScreenComponent: Component { super.init(frame: frame) - self.scrollView.delaysContentTouches = true - self.scrollView.canCancelContentTouches = true + self.scrollView.delaysContentTouches = false +// self.scrollView.canCancelContentTouches = true self.scrollView.clipsToBounds = false if #available(iOSApplicationExtension 11.0, iOS 11.0, *) { self.scrollView.contentInsetAdjustmentBehavior = .never @@ -217,6 +217,28 @@ final class StarsStatisticsScreenComponent: Component { self.stateDisposable?.dispose() } + override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? { + guard let result = super.hitTest(point, with: event) else { + return nil + } + var currentParent: UIView? = result + while true { + if currentParent == nil || currentParent === self { + break + } + if let scrollView = currentParent as? UIScrollView { + if scrollView === self.scrollView { + break + } + if scrollView.isDecelerating && scrollView.contentOffset.y < -scrollView.contentInset.top { + return self.scrollView + } + } + currentParent = currentParent?.superview + } + return result + } + func scrollToTop() { self.scrollView.setContentOffset(CGPoint(x: 0.0, y: -self.scrollView.contentInset.top), animated: true) } diff --git a/submodules/TelegramUI/Components/Stars/StarsTransactionsScreen/Sources/StarsTransactionsListPanelComponent.swift b/submodules/TelegramUI/Components/Stars/StarsTransactionsScreen/Sources/StarsTransactionsListPanelComponent.swift index 23aa277d0f..713d2533f1 100644 --- a/submodules/TelegramUI/Components/Stars/StarsTransactionsScreen/Sources/StarsTransactionsListPanelComponent.swift +++ b/submodules/TelegramUI/Components/Stars/StarsTransactionsScreen/Sources/StarsTransactionsListPanelComponent.swift @@ -136,8 +136,8 @@ final class StarsTransactionsListPanelComponent: Component { super.init(frame: frame) - self.scrollView.delaysContentTouches = true - self.scrollView.canCancelContentTouches = true + self.scrollView.delaysContentTouches = false +// self.scrollView.canCancelContentTouches = true self.scrollView.clipsToBounds = false if #available(iOSApplicationExtension 11.0, iOS 11.0, *) { self.scrollView.contentInsetAdjustmentBehavior = .never @@ -164,6 +164,15 @@ final class StarsTransactionsListPanelComponent: Component { self.itemsDisposable?.dispose() } + func scrollToTop() -> Bool { + if self.scrollView.contentOffset.y > 0.0 { + self.scrollView.setContentOffset(CGPoint(), animated: true) + return true + } else { + return false + } + } + func scrollViewDidScroll(_ scrollView: UIScrollView) { if !self.ignoreScrolling { self.updateScrolling(transition: .immediate) diff --git a/submodules/TelegramUI/Components/Stars/StarsTransactionsScreen/Sources/StarsTransactionsPanelContainerComponent.swift b/submodules/TelegramUI/Components/Stars/StarsTransactionsScreen/Sources/StarsTransactionsPanelContainerComponent.swift index c35e7e9619..89f1e91ccb 100644 --- a/submodules/TelegramUI/Components/Stars/StarsTransactionsScreen/Sources/StarsTransactionsPanelContainerComponent.swift +++ b/submodules/TelegramUI/Components/Stars/StarsTransactionsScreen/Sources/StarsTransactionsPanelContainerComponent.swift @@ -610,6 +610,13 @@ final class StarsTransactionsPanelContainerComponent: Component { } } + func scrollToTop() -> Bool { + if let currentPanelView = self.currentPanelView as? StarsTransactionsListPanelComponent.View { + return currentPanelView.scrollToTop() + } + return false + } + func update(component: StarsTransactionsPanelContainerComponent, availableSize: CGSize, state: EmptyComponentState, environment: Environment, transition: ComponentTransition) -> CGSize { let environment = environment[StarsTransactionsPanelContainerEnvironment.self].value diff --git a/submodules/TelegramUI/Components/Stars/StarsTransactionsScreen/Sources/StarsTransactionsScreen.swift b/submodules/TelegramUI/Components/Stars/StarsTransactionsScreen/Sources/StarsTransactionsScreen.swift index 870009686b..276716b6cb 100644 --- a/submodules/TelegramUI/Components/Stars/StarsTransactionsScreen/Sources/StarsTransactionsScreen.swift +++ b/submodules/TelegramUI/Components/Stars/StarsTransactionsScreen/Sources/StarsTransactionsScreen.swift @@ -152,8 +152,8 @@ final class StarsTransactionsScreenComponent: Component { super.init(frame: frame) - self.scrollView.delaysContentTouches = true - self.scrollView.canCancelContentTouches = true + self.scrollView.delaysContentTouches = false +// self.scrollView.canCancelContentTouches = true self.scrollView.clipsToBounds = false if #available(iOSApplicationExtension 11.0, iOS 11.0, *) { self.scrollView.contentInsetAdjustmentBehavior = .never @@ -185,21 +185,44 @@ final class StarsTransactionsScreenComponent: Component { self.stateDisposable?.dispose() } + override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? { + guard let result = super.hitTest(point, with: event) else { + return nil + } + var currentParent: UIView? = result + while true { + if currentParent == nil || currentParent === self { + break + } + if let scrollView = currentParent as? UIScrollView { + if scrollView === self.scrollView { + break + } + if scrollView.isDecelerating && scrollView.contentOffset.y < -scrollView.contentInset.top { + return self.scrollView + } + } + currentParent = currentParent?.superview + } + return result + } + func scrollViewWillBeginDragging(_ scrollView: UIScrollView) { self.enableVelocityTracking = true } func scrollViewDidScroll(_ scrollView: UIScrollView) { - if !self.ignoreScrolling { - if self.enableVelocityTracking { - self.previousVelocityM1 = self.previousVelocity - if let value = (scrollView.value(forKey: (["_", "verticalVelocity"] as [String]).joined()) as? NSNumber)?.doubleValue { - self.previousVelocity = CGFloat(value) - } - } - - self.updateScrolling(transition: .immediate) + guard !self.ignoreScrolling else { + return } + if self.enableVelocityTracking { + self.previousVelocityM1 = self.previousVelocity + if let value = (scrollView.value(forKey: (["_", "verticalVelocity"] as [String]).joined()) as? NSNumber)?.doubleValue { + self.previousVelocity = CGFloat(value) + } + } + + self.updateScrolling(transition: .immediate) } func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) { @@ -229,6 +252,12 @@ final class StarsTransactionsScreenComponent: Component { self.previousVelocityM1 = 0.0 } } + + func scrollToTop() { + if let panelContainerView = self.panelContainer.view as? StarsTransactionsPanelContainerComponent.View, !panelContainerView.scrollToTop() { + self.scrollView.setContentOffset(.zero, animated: true) + } + } private func updateScrolling(transition: ComponentTransition) { let scrollBounds = self.scrollView.bounds @@ -1124,6 +1153,15 @@ public final class StarsTransactionsScreen: ViewControllerComponentContainer { self.starsContext.load(force: false) self.subscriptionsContext.loadMore() + + self.scrollToTop = { [weak self] in + guard let self else { + return + } + if let componentView = self.node.hostView.componentView as? StarsTransactionsScreenComponent.View { + componentView.scrollToTop() + } + } } required public init(coder aDecoder: NSCoder) { diff --git a/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StorageUsageScreen.swift b/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StorageUsageScreen.swift index 45352322e2..53130d45e0 100644 --- a/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StorageUsageScreen.swift +++ b/submodules/TelegramUI/Components/StorageUsageScreen/Sources/StorageUsageScreen.swift @@ -865,6 +865,28 @@ final class StorageUsageScreenComponent: Component { self.keepScreenActiveDisposable?.dispose() } + override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? { + guard let result = super.hitTest(point, with: event) else { + return nil + } + var currentParent: UIView? = result + while true { + if currentParent == nil || currentParent === self { + break + } + if let scrollView = currentParent as? UIScrollView { + if scrollView === self.scrollView { + break + } + if scrollView.isDecelerating && scrollView.contentOffset.y < -scrollView.contentInset.top { + return self.scrollView + } + } + currentParent = currentParent?.superview + } + return result + } + func scrollViewWillBeginDragging(_ scrollView: UIScrollView) { self.enableVelocityTracking = true }