Only refresh or alert if visible

This commit is contained in:
Justin Mazzocchi 2021-03-05 21:48:11 -08:00
parent 94d0b2338f
commit 11f5a3a914
No known key found for this signature in database
GPG key ID: E223E6937AAFB01C
2 changed files with 12 additions and 2 deletions

View file

@ -5,6 +5,8 @@ import UIKit
import ViewModels import ViewModels
extension UIViewController { extension UIViewController {
var isVisible: Bool { isViewLoaded && view.window != nil && presentedViewController == nil }
func present(alertItem: AlertItem) { func present(alertItem: AlertItem) {
let alertController = UIAlertController( let alertController = UIAlertController(
title: nil, title: nil,

View file

@ -422,7 +422,11 @@ private extension TableViewController {
viewModel.alertItems viewModel.alertItems
.compactMap { $0 } .compactMap { $0 }
.sink { [weak self] in self?.present(alertItem: $0) } .sink { [weak self] in
guard let self = self, self.isVisible else { return }
self.present(alertItem: $0)
}
.store(in: &cancellables) .store(in: &cancellables)
tableView.publisher(for: \.contentOffset) tableView.publisher(for: \.contentOffset)
@ -444,7 +448,11 @@ private extension TableViewController {
NotificationCenter.default.publisher(for: UIScene.willEnterForegroundNotification) NotificationCenter.default.publisher(for: UIScene.willEnterForegroundNotification)
.merge(with: NotificationCenter.default.publisher(for: NewStatusViewController.newStatusPostedNotification)) .merge(with: NotificationCenter.default.publisher(for: NewStatusViewController.newStatusPostedNotification))
.sink { [weak self] _ in self?.refreshIfAble() } .sink { [weak self] _ in
guard let self = self, self.isVisible else { return }
self.refreshIfAble()
}
.store(in: &cancellables) .store(in: &cancellables)
NotificationCenter.default.publisher(for: LoadMoreView.accessibilityCustomAction) NotificationCenter.default.publisher(for: LoadMoreView.accessibilityCustomAction)