mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-22 08:10:59 +00:00
Only refresh or alert if visible
This commit is contained in:
parent
94d0b2338f
commit
11f5a3a914
2 changed files with 12 additions and 2 deletions
|
@ -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,
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue