From 29e3d10e9737f4b34691ba9eeb4b15c79af84dc2 Mon Sep 17 00:00:00 2001 From: CMK Date: Thu, 4 Nov 2021 19:22:51 +0800 Subject: [PATCH] fix: wizard display before sign-in at the first time install issue --- .../Root/MainTab/MainTabBarController.swift | 14 ++++++----- .../Scene/Root/Sidebar/SidebarViewModel.swift | 24 +++++++++++-------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/Mastodon/Scene/Root/MainTab/MainTabBarController.swift b/Mastodon/Scene/Root/MainTab/MainTabBarController.swift index 8688a8fab..4b803bc49 100644 --- a/Mastodon/Scene/Root/MainTab/MainTabBarController.swift +++ b/Mastodon/Scene/Root/MainTab/MainTabBarController.swift @@ -252,6 +252,14 @@ extension MainTabBarController { tabBarLongPressGestureRecognizer.addTarget(self, action: #selector(MainTabBarController.tabBarLongPressGestureRecognizerHandler(_:))) tabBar.addGestureRecognizer(tabBarLongPressGestureRecognizer) + context.authenticationService.activeMastodonAuthenticationBox + .receive(on: DispatchQueue.main) + .sink { [weak self] authenticationBox in + guard let self = self else { return } + self.isReadyForWizardAvatarButton = authenticationBox != nil + } + .store(in: &disposeBag) + currentTab .receive(on: DispatchQueue.main) .sink { [weak self] tab in @@ -267,12 +275,6 @@ extension MainTabBarController { #endif } - override func viewDidAppear(_ animated: Bool) { - super.viewDidAppear(animated) - - isReadyForWizardAvatarButton = true - } - override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { super.traitCollectionDidChange(previousTraitCollection) diff --git a/Mastodon/Scene/Root/Sidebar/SidebarViewModel.swift b/Mastodon/Scene/Root/Sidebar/SidebarViewModel.swift index 1f982429e..5ababf161 100644 --- a/Mastodon/Scene/Root/Sidebar/SidebarViewModel.swift +++ b/Mastodon/Scene/Root/Sidebar/SidebarViewModel.swift @@ -18,32 +18,36 @@ final class SidebarViewModel { // input let context: AppContext - let searchHistoryFetchedResultController: SearchHistoryFetchedResultController - + @Published private var isSidebarDataSourceReady = false + @Published private var isAvatarButtonDataReady = false + // output var diffableDataSource: UICollectionViewDiffableDataSource? var secondaryDiffableDataSource: UICollectionViewDiffableDataSource? - private(set) var isReadyForWizardAvatarButton = false + @Published private(set) var isReadyForWizardAvatarButton = false let activeMastodonAuthenticationObjectID = CurrentValueSubject(nil) init(context: AppContext) { self.context = context - self.searchHistoryFetchedResultController = SearchHistoryFetchedResultController(managedObjectContext: context.managedObjectContext) + + Publishers.CombineLatest( + $isSidebarDataSourceReady, + $isAvatarButtonDataReady + ) + .map { $0 && $1 } + .assign(to: &$isReadyForWizardAvatarButton) context.authenticationService.activeMastodonAuthentication .sink { [weak self] authentication in guard let self = self else { return } - // bind search history - self.searchHistoryFetchedResultController.domain.value = authentication?.domain - self.searchHistoryFetchedResultController.userID.value = authentication?.userID // bind objectID self.activeMastodonAuthenticationObjectID.value = authentication?.objectID + + self.isAvatarButtonDataReady = authentication != nil } .store(in: &disposeBag) - - try? searchHistoryFetchedResultController.fetchedResultsController.performFetch() } } @@ -175,7 +179,7 @@ extension SidebarViewModel { // otherwise the UI layout will infinity loop _diffableDataSource.apply(sectionSnapshot, to: .main, animatingDifferences: true) { [weak self] in guard let self = self else { return } - self.isReadyForWizardAvatarButton = true + self.isSidebarDataSourceReady = true } // secondary