mirror of
https://github.com/mastodon/mastodon-ios.git
synced 2024-12-12 16:46:32 +01:00
fix: tab bar avatar button not update issue. resolve #383
This commit is contained in:
parent
b2b81e27e8
commit
d90b61e732
@ -106,6 +106,10 @@ class MainTabBarController: UITabBarController {
|
||||
var _viewControllers: [UIViewController] = []
|
||||
|
||||
private(set) var isReadyForWizardAvatarButton = false
|
||||
|
||||
// output
|
||||
var avatarURLObserver: AnyCancellable?
|
||||
@Published var avatarURL: URL?
|
||||
|
||||
init(context: AppContext, coordinator: SceneCoordinator) {
|
||||
self.context = context
|
||||
@ -226,17 +230,34 @@ extension MainTabBarController {
|
||||
.store(in: &disposeBag)
|
||||
|
||||
layoutAvatarButton()
|
||||
|
||||
$avatarURL
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { [weak self] avatarURL in
|
||||
guard let self = self else { return }
|
||||
self.avatarButton.avatarImageView.setImage(
|
||||
url: avatarURL,
|
||||
placeholder: .placeholder(color: .systemFill),
|
||||
scaleToSize: MainTabBarController.avatarButtonSize
|
||||
)
|
||||
}
|
||||
.store(in: &disposeBag)
|
||||
context.authenticationService.activeMastodonAuthentication
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { [weak self] activeMastodonAuthentication in
|
||||
guard let self = self else { return }
|
||||
|
||||
let avatarImageURL = activeMastodonAuthentication?.user.avatarImageURL()
|
||||
self.avatarButton.avatarImageView.setImage(
|
||||
url: avatarImageURL,
|
||||
placeholder: .placeholder(color: .systemFill),
|
||||
scaleToSize: MainTabBarController.avatarButtonSize
|
||||
)
|
||||
if let user = activeMastodonAuthentication?.user {
|
||||
self.avatarURLObserver = user.publisher(for: \.avatar)
|
||||
.sink { [weak self, weak user] _ in
|
||||
guard let self = self else { return }
|
||||
guard let user = user else { return }
|
||||
guard user.managedObjectContext != nil else { return }
|
||||
self.avatarURL = user.avatarImageURL()
|
||||
}
|
||||
} else {
|
||||
self.avatarURLObserver = nil
|
||||
}
|
||||
|
||||
// a11y
|
||||
let _profileTabItem = self.tabBar.items?.first { item in item.tag == Tab.me.tag }
|
||||
|
Loading…
Reference in New Issue
Block a user