Fix stautses on My Profile not appearing until scroll

This commit is contained in:
Shadowfacts 2020-10-25 11:19:37 -04:00
parent 5d9f4b8ea8
commit 80b3585b71
Signed by untrusted user: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 16 additions and 2 deletions

View File

@ -38,6 +38,8 @@ class ProfileViewController: UIPageViewController {
private var headerView: ProfileHeaderView! private var headerView: ProfileHeaderView!
private var hasAppeared = false
init(accountID: String?, mastodonController: MastodonController) { init(accountID: String?, mastodonController: MastodonController) {
self.accountID = accountID self.accountID = accountID
self.mastodonController = mastodonController self.mastodonController = mastodonController
@ -95,6 +97,12 @@ class ProfileViewController: UIPageViewController {
loadAccount() loadAccount()
} }
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
hasAppeared = true
}
private func loadAccount() { private func loadAccount() {
guard let accountID = accountID else { return } guard let accountID = accountID else { return }
if mastodonController.persistentContainer.account(for: accountID) != nil { if mastodonController.persistentContainer.account(for: accountID) != nil {
@ -122,10 +130,16 @@ class ProfileViewController: UIPageViewController {
// Optionally invoke updateUI on headerView because viewDidLoad may not have been called yet // Optionally invoke updateUI on headerView because viewDidLoad may not have been called yet
headerView?.updateUI(for: accountID) headerView?.updateUI(for: accountID)
navigationItem.title = account.displayNameWithoutCustomEmoji navigationItem.title = account.displayNameWithoutCustomEmoji
// Only call updateUI on the individual page controllers if the account is loaded after the profile VC has appeared on screen.
// Otherwise, fi the page view controllers do something with the table view before they appear, the table view doesn't load
// its cells until the user begins to scroll.
if hasAppeared {
pageControllers.forEach { pageControllers.forEach {
$0.updateUI(account: account) $0.updateUI(account: account)
} }
} }
}
private func selectPage(at index: Int, animated: Bool, completion: ((Bool) -> Void)? = nil) { private func selectPage(at index: Int, animated: Bool, completion: ((Bool) -> Void)? = nil) {
let direction: UIPageViewController.NavigationDirection = currentIndex == nil || index - currentIndex > 0 ? .forward : .reverse let direction: UIPageViewController.NavigationDirection = currentIndex == nil || index - currentIndex > 0 ? .forward : .reverse