From 41e16a4d2a29339545dbefe4109dfc53b6384412 Mon Sep 17 00:00:00 2001 From: CMK Date: Wed, 7 Jul 2021 20:13:33 +0800 Subject: [PATCH] fix: timeline may offset after first launch issue --- .../HomeTimeline/HomeTimelineViewController.swift | 11 +++-------- .../Scene/HomeTimeline/HomeTimelineViewModel.swift | 4 +++- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/Mastodon/Scene/HomeTimeline/HomeTimelineViewController.swift b/Mastodon/Scene/HomeTimeline/HomeTimelineViewController.swift index fcd35cec..728c92c2 100644 --- a/Mastodon/Scene/HomeTimeline/HomeTimelineViewController.swift +++ b/Mastodon/Scene/HomeTimeline/HomeTimelineViewController.swift @@ -205,10 +205,6 @@ extension HomeTimelineViewController { // needs trigger manually after onboarding dismiss setNeedsStatusBarAppearanceUpdate() - - if (viewModel.fetchedResultsController.fetchedObjects ?? []).isEmpty { - viewModel.loadLatestStateMachine.enter(HomeTimelineViewModel.LoadLatestState.Loading.self) - } } override func viewDidAppear(_ animated: Bool) { @@ -216,11 +212,10 @@ extension HomeTimelineViewController { viewModel.viewDidAppear.send() - DispatchQueue.main.async { [weak self] in + DispatchQueue.main.asyncAfter(deadline: .now() + 2) { [weak self] in guard let self = self else { return } - if (self.viewModel.fetchedResultsController.fetchedObjects ?? []).count == 0 { - self.viewModel.loadLatestStateMachine.enter(HomeTimelineViewModel.LoadLatestState.Loading.self) - } + // always try to refresh timeline after appear + self.viewModel.homeTimelineNeedRefresh.send() } } diff --git a/Mastodon/Scene/HomeTimeline/HomeTimelineViewModel.swift b/Mastodon/Scene/HomeTimeline/HomeTimelineViewModel.swift index d22c52be..9d8f6f70 100644 --- a/Mastodon/Scene/HomeTimeline/HomeTimelineViewModel.swift +++ b/Mastodon/Scene/HomeTimeline/HomeTimelineViewModel.swift @@ -135,8 +135,10 @@ final class HomeTimelineViewModel: NSObject { self?.loadLatestStateMachine.enter(LoadLatestState.Loading.self) } .store(in: &disposeBag) - + + // refresh after publish post homeTimelineNavigationBarTitleViewModel.isPublished + .delay(for: 2, scheduler: DispatchQueue.main) .sink { [weak self] isPublished in guard let self = self else { return } self.homeTimelineNeedRefresh.send()