From 3a44e0428cf4d8947b6ef2faf31d530180725110 Mon Sep 17 00:00:00 2001 From: Vladimir Klevtsov Date: Tue, 29 Apr 2025 21:29:57 +0200 Subject: [PATCH 1/2] [trello.com/c/sG80IZan] fix reading while TransactionDetails on screen --- .../Modules/Chat/View/ChatViewController.swift | 16 ++++++++++++++++ .../Chat/View/ChatViewControllerState.swift | 7 ++++++- .../ComplexTransferViewController.swift | 16 ++++++++++++++++ .../TransactionDetailsViewControllerBase.swift | 12 ++++++++++++ 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/Adamant/Modules/Chat/View/ChatViewController.swift b/Adamant/Modules/Chat/View/ChatViewController.swift index 7e2387809..b476e1a6f 100644 --- a/Adamant/Modules/Chat/View/ChatViewController.swift +++ b/Adamant/Modules/Chat/View/ChatViewController.swift @@ -320,6 +320,22 @@ extension ChatViewController { self?.state.isAppActive = false } .store(in: &subscriptions) + + NotificationCenter.default + .publisher(for: .controllerPresentedLifecycleNotification) + .sink { [weak self] notification in + guard let self, + let id = notification.userInfo?["id"] as? String, + let isPresented = notification.userInfo?["isPresented"] as? Bool else { return } + + if isPresented { + self.state.presentedControllerIDs.insert(id) + } else { + self.state.presentedControllerIDs.remove(id) + updateUnreadMessages() + } + } + .store(in: &subscriptions) viewModel.didTapAdmNodesList .sink { [weak self] in diff --git a/Adamant/Modules/Chat/View/ChatViewControllerState.swift b/Adamant/Modules/Chat/View/ChatViewControllerState.swift index ad8324c6d..d078cf875 100644 --- a/Adamant/Modules/Chat/View/ChatViewControllerState.swift +++ b/Adamant/Modules/Chat/View/ChatViewControllerState.swift @@ -20,12 +20,17 @@ struct ChatViewControllerState { var isAppActive = true var isScrollingToBottom = false var shouldScrollToNewMessagesOrSavedPosition = true + var presentedControllerIDs: Set = [] { + didSet { + print("can read:", presentedControllerIDs.isEmpty) + } + } //calculation for animation, might use for something else in the future var isAnimationAllowed: Bool { isMessagesLoaded && !isAutoScrolling && !isScrollingToBottom } var canReadChat: Bool { - !isAutoScrolling && isViewAppeared && (!isMacOS || isAppActive) + !isAutoScrolling && isViewAppeared && (!isMacOS || isAppActive) && presentedControllerIDs.isEmpty } } diff --git a/Adamant/Modules/ChatsList/ComplexTransferViewController.swift b/Adamant/Modules/ChatsList/ComplexTransferViewController.swift index fb9e1a125..aa4b7facb 100644 --- a/Adamant/Modules/ChatsList/ComplexTransferViewController.swift +++ b/Adamant/Modules/ChatsList/ComplexTransferViewController.swift @@ -57,6 +57,7 @@ final class ComplexTransferViewController: UIViewController { self.nodesStorage = nodesStorage super.init(nibName: nil, bundle: nil) + self.postLifecycleNotification(isPresented: true) } required init?(coder: NSCoder) { @@ -93,6 +94,7 @@ final class ComplexTransferViewController: UIViewController { } deinit { + self.postLifecycleNotification(isPresented: false) NotificationCenter.default.removeObserver(self) } @@ -113,6 +115,14 @@ final class ComplexTransferViewController: UIViewController { @objc func cancel() { transferDelegate?.complexTransferViewController(self, didFinishWithTransfer: nil, detailsViewController: nil) } + + private func postLifecycleNotification(isPresented: Bool) { + NotificationCenter.default.post( + name: .controllerPresentedLifecycleNotification, + object: nil, + userInfo: ["id": controllerIdKey, "isPresented": isPresented] + ) + } } extension ComplexTransferViewController: PagingViewControllerDataSource { @@ -266,3 +276,9 @@ extension ComplexTransferViewController { super.pressesBegan(presses, with: event) } } + +extension Notification.Name { + static let controllerPresentedLifecycleNotification = Notification.Name("controllerPresentedLifecycleNotification") +} + +fileprivate let controllerIdKey: String = "complexTransferViewController" diff --git a/Adamant/Modules/Wallets/TransactionDetailsViewControllerBase.swift b/Adamant/Modules/Wallets/TransactionDetailsViewControllerBase.swift index 63ffccf0f..5e3780515 100644 --- a/Adamant/Modules/Wallets/TransactionDetailsViewControllerBase.swift +++ b/Adamant/Modules/Wallets/TransactionDetailsViewControllerBase.swift @@ -269,6 +269,7 @@ class TransactionDetailsViewControllerBase: FormViewController { self.languageService = languageService super.init(style: .grouped) + postLifecycleNotification(isPresented: true) } required init?(coder aDecoder: NSCoder) { @@ -834,6 +835,7 @@ class TransactionDetailsViewControllerBase: FormViewController { } deinit { + postLifecycleNotification(isPresented: false) refreshTask?.cancel() } @@ -955,6 +957,14 @@ class TransactionDetailsViewControllerBase: FormViewController { row.value = getFeeValue() row.updateCell() } + + private func postLifecycleNotification(isPresented: Bool) { + NotificationCenter.default.post( + name: .controllerPresentedLifecycleNotification, + object: nil, + userInfo: ["id": controllerIdKey, "isPresented": isPresented] + ) + } func getFeeValue() -> String { guard let value = transaction?.feeValue else { @@ -1105,3 +1115,5 @@ class TransactionDetailsViewControllerBase: FormViewController { ) } } + +fileprivate let controllerIdKey: String = "transactionDetailsController" From b20af37e354ac74875783c9d03fa98ef3593979b Mon Sep 17 00:00:00 2001 From: Vladimir Klevtsov Date: Wed, 30 Apr 2025 16:11:46 +0200 Subject: [PATCH 2/2] [trello.com/c/sG80IZan] delete print --- Adamant/Modules/Chat/View/ChatViewControllerState.swift | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Adamant/Modules/Chat/View/ChatViewControllerState.swift b/Adamant/Modules/Chat/View/ChatViewControllerState.swift index d078cf875..7763e37f5 100644 --- a/Adamant/Modules/Chat/View/ChatViewControllerState.swift +++ b/Adamant/Modules/Chat/View/ChatViewControllerState.swift @@ -20,11 +20,7 @@ struct ChatViewControllerState { var isAppActive = true var isScrollingToBottom = false var shouldScrollToNewMessagesOrSavedPosition = true - var presentedControllerIDs: Set = [] { - didSet { - print("can read:", presentedControllerIDs.isEmpty) - } - } + var presentedControllerIDs: Set = [] //calculation for animation, might use for something else in the future var isAnimationAllowed: Bool {