Skip to content

[trello.com/c/sG80IZan] fix reading while TransactionDetails on screen #841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Adamant/Modules/Chat/View/ChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Adamant/Modules/Chat/View/ChatViewControllerState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ struct ChatViewControllerState {
var isAppActive = true
var isScrollingToBottom = false
var shouldScrollToNewMessagesOrSavedPosition = true
var presentedControllerIDs: Set<String> = []

//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
}
}
16 changes: 16 additions & 0 deletions Adamant/Modules/ChatsList/ComplexTransferViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -93,6 +94,7 @@ final class ComplexTransferViewController: UIViewController {
}

deinit {
self.postLifecycleNotification(isPresented: false)
NotificationCenter.default.removeObserver(self)
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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"
12 changes: 12 additions & 0 deletions Adamant/Modules/Wallets/TransactionDetailsViewControllerBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ class TransactionDetailsViewControllerBase: FormViewController {
self.languageService = languageService

super.init(style: .grouped)
postLifecycleNotification(isPresented: true)
}

required init?(coder aDecoder: NSCoder) {
Expand Down Expand Up @@ -834,6 +835,7 @@ class TransactionDetailsViewControllerBase: FormViewController {
}

deinit {
postLifecycleNotification(isPresented: false)
refreshTask?.cancel()
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -1105,3 +1115,5 @@ class TransactionDetailsViewControllerBase: FormViewController {
)
}
}

fileprivate let controllerIdKey: String = "transactionDetailsController"