From ce6d55042dc2e9e25b28a9700132192e38a07866 Mon Sep 17 00:00:00 2001 From: Justin Mazzocchi <2831158+jzzocc@users.noreply.github.com> Date: Sun, 27 Nov 2022 22:59:52 -0800 Subject: [PATCH] Debounce refresh when resuming from background --- View Controllers/MainNavigationViewController.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/View Controllers/MainNavigationViewController.swift b/View Controllers/MainNavigationViewController.swift index c636d7fd..9b6c4a3b 100644 --- a/View Controllers/MainNavigationViewController.swift +++ b/View Controllers/MainNavigationViewController.swift @@ -55,6 +55,7 @@ final class MainNavigationViewController: UITabBarController { .store(in: &cancellables) NotificationCenter.default.publisher(for: UIScene.willEnterForegroundNotification) + .debounce(for: .seconds(Self.refreshFromBackgroundDebounceInterval), scheduler: DispatchQueue.main) .sink { [weak self] _ in self?.viewModel.refreshIdentity() } .store(in: &cancellables) } @@ -106,6 +107,7 @@ extension MainNavigationViewController: NavigationHandling { private extension MainNavigationViewController { static let secondaryNavigationViewTag = UUID().hashValue static let newStatusViewTag = UUID().hashValue + static let refreshFromBackgroundDebounceInterval: TimeInterval = 30 func setupViewControllers(pending: Bool) { var controllers: [UIViewController] = [