pfps: load profile pics in the background

So we don't get annoying popping artifacts when scrolling

Changelog-Fixed: Profile pics are now loaded in the background
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2022-08-06 13:34:04 -07:00
parent 97bca010f6
commit 03748a2b02
8 changed files with 133 additions and 75 deletions

View File

@@ -54,7 +54,6 @@ struct ProfilePicView: View {
}
func ProfilePic(_ url: URL) -> some View {
let pub = load_image(cache: image_cache, from: url)
return Group {
if let img = self.img {
img
@@ -67,9 +66,10 @@ struct ProfilePicView: View {
Placeholder
}
}
.onReceive(pub) { mimg in
if let img = mimg {
self.img = Image(uiImage: img)
.task {
let ui_img = await load_image(cache: image_cache, from: url)
if let ui_img = ui_img {
self.img = Image(uiImage: ui_img)
}
}
}
@@ -89,12 +89,17 @@ struct ProfilePicView: View {
MainContent
.onReceive(handle_notify(.profile_updated)) { notif in
let updated = notif.object as! ProfileUpdate
if updated.pubkey != pubkey {
guard updated.pubkey == self.pubkey else {
return
}
if updated.profile.picture != picture {
picture = updated.profile.picture
if let pic = updated.profile.picture {
if let url = URL(string: pic) {
if let ui_img = image_cache.lookup_sync(for: url) {
self.img = Image(uiImage: ui_img)
}
}
}
}
}