fix: wizard display before sign-in at the first time install issue

This commit is contained in:
CMK 2021-11-04 19:22:51 +08:00
parent 868e86e077
commit 29e3d10e97
2 changed files with 22 additions and 16 deletions

View File

@ -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)

View File

@ -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<Section, Item>?
var secondaryDiffableDataSource: UICollectionViewDiffableDataSource<Section, Item>?
private(set) var isReadyForWizardAvatarButton = false
@Published private(set) var isReadyForWizardAvatarButton = false
let activeMastodonAuthenticationObjectID = CurrentValueSubject<NSManagedObjectID?, Never>(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