damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 357e8adf86199bd909c1e0d0e35568d1492e47c4
parent 084c86eb0e826266d34f1f3e84a2816db0ee4008
Author: William Casarin <jb55@jb55.com>
Date:   Sat, 22 Apr 2023 12:08:24 -0700

Refactor disable_animation setting

Pass it down from the top instead of using a function which goes around
our settings store

Diffstat:
Mdamus/Components/ImageCarousel.swift | 11+++++++----
Mdamus/Components/UserView.swift | 2+-
Mdamus/ContentView.swift | 2+-
Mdamus/Util/Extensions/KFOptionSetter+.swift | 4++--
Mdamus/Views/BannerImageView.swift | 14+++++++++-----
Mdamus/Views/ChatView.swift | 6+++++-
Mdamus/Views/DMChatView.swift | 2+-
Mdamus/Views/Events/EventProfile.swift | 6+++++-
Mdamus/Views/Images/ImageContainerView.swift | 7++++---
Mdamus/Views/Images/ImageView.swift | 6++++--
Mdamus/Views/Images/ProfilePicImageView.swift | 13++++++++-----
Mdamus/Views/NoteContentView.swift | 4++--
Mdamus/Views/Notifications/ProfilePicturesView.swift | 2+-
Mdamus/Views/ParticipantsView.swift | 2+-
Mdamus/Views/PostView.swift | 2+-
Mdamus/Views/Profile/EditMetadataView.swift | 2+-
Mdamus/Views/Profile/MaybeAnonPfpView.swift | 2+-
Mdamus/Views/Profile/ProfilePicView.swift | 20++++++++++++++------
Mdamus/Views/Profile/ProfileView.swift | 7++++---
Mdamus/Views/QRCodeView.swift | 2+-
Mdamus/Views/SideMenuView.swift | 2+-
21 files changed, 74 insertions(+), 44 deletions(-)

diff --git a/damus/Components/ImageCarousel.swift b/damus/Components/ImageCarousel.swift @@ -46,19 +46,22 @@ struct ImageCarousel: View { let evid: String let previews: PreviewCache + let disable_animation: Bool + @State private var open_sheet: Bool = false @State private var current_url: URL? = nil @State private var image_fill: ImageFill? = nil @State private var fillHeight: CGFloat = 350 @State private var maxHeight: CGFloat = UIScreen.main.bounds.height * 0.85 - init(previews: PreviewCache, evid: String, urls: [URL]) { + init(previews: PreviewCache, evid: String, urls: [URL], disable_animation: Bool) { _open_sheet = State(initialValue: false) _current_url = State(initialValue: nil) _image_fill = State(initialValue: previews.lookup_image_meta(evid)) self.urls = urls self.evid = evid self.previews = previews + self.disable_animation = disable_animation } var filling: Bool { @@ -79,7 +82,7 @@ struct ImageCarousel: View { KFAnimatedImage(url) .callbackQueue(.dispatch(.global(qos:.background))) .backgroundDecode(true) - .imageContext(.note) + .imageContext(.note, disable_animation: disable_animation) .cancelOnDisappear(true) .configure { view in view.framePreloadCount = 3 @@ -98,7 +101,7 @@ struct ImageCarousel: View { } } .fullScreenCover(isPresented: $open_sheet) { - ImageView(urls: urls) + ImageView(urls: urls, disable_animation: disable_animation) } .frame(height: height) .onTapGesture { @@ -169,7 +172,7 @@ public struct ImageFill { struct ImageCarousel_Previews: PreviewProvider { static var previews: some View { - ImageCarousel(previews: test_damus_state().previews, evid: "evid", urls: [URL(string: "https://jb55.com/red-me.jpg")!,URL(string: "https://jb55.com/red-me.jpg")!]) + ImageCarousel(previews: test_damus_state().previews, evid: "evid", urls: [URL(string: "https://jb55.com/red-me.jpg")!,URL(string: "https://jb55.com/red-me.jpg")!], disable_animation: false) } } diff --git a/damus/Components/UserView.swift b/damus/Components/UserView.swift @@ -37,7 +37,7 @@ struct UserView: View { VStack { HStack { - ProfilePicView(pubkey: pubkey, size: PFP_SIZE, highlight: .none, profiles: damus_state.profiles) + ProfilePicView(pubkey: pubkey, size: PFP_SIZE, highlight: .none, profiles: damus_state.profiles, disable_animation: damus_state.settings.disable_animation) VStack(alignment: .leading) { let profile = damus_state.profiles.lookup(id: pubkey) diff --git a/damus/ContentView.swift b/damus/ContentView.swift @@ -261,7 +261,7 @@ struct ContentView: View { Button { isSideBarOpened.toggle() } label: { - ProfilePicView(pubkey: damus_state!.pubkey, size: 32, highlight: .none, profiles: damus_state!.profiles) + ProfilePicView(pubkey: damus_state!.pubkey, size: 32, highlight: .none, profiles: damus_state!.profiles, disable_animation: damus_state!.settings.disable_animation) .opacity(isSideBarOpened ? 0 : 1) .animation(isSideBarOpened ? .none : .default, value: isSideBarOpened) } diff --git a/damus/Util/Extensions/KFOptionSetter+.swift b/damus/Util/Extensions/KFOptionSetter+.swift @@ -10,7 +10,7 @@ import Kingfisher extension KFOptionSetter { - func imageContext(_ imageContext: ImageContext) -> Self { + func imageContext(_ imageContext: ImageContext, disable_animation: Bool) -> Self { options.callbackQueue = .dispatch(.global(qos: .background)) options.processingQueue = .dispatch(.global(qos: .background)) options.downloader = CustomImageDownloader.shared @@ -26,7 +26,7 @@ extension KFOptionSetter { options.backgroundDecode = true options.cacheOriginalImage = true options.scaleFactor = UIScreen.main.scale - options.onlyLoadFirstFrame = should_disable_image_animation() + options.onlyLoadFirstFrame = disable_animation return self } diff --git a/damus/Views/BannerImageView.swift b/damus/Views/BannerImageView.swift @@ -9,7 +9,7 @@ import SwiftUI import Kingfisher struct InnerBannerImageView: View { - + let disable_animation: Bool let url: URL? let defaultImage = UIImage(named: "profile-banner") ?? UIImage() @@ -19,7 +19,7 @@ struct InnerBannerImageView: View { if (url != nil) { KFAnimatedImage(url) - .imageContext(.banner) + .imageContext(.banner, disable_animation: disable_animation) .configure { view in view.framePreloadCount = 3 } @@ -35,19 +35,21 @@ struct InnerBannerImageView: View { } struct BannerImageView: View { + let disable_animation: Bool let pubkey: String let profiles: Profiles @State var banner: String? - init (pubkey: String, profiles: Profiles, banner: String? = nil) { + init (pubkey: String, profiles: Profiles, disable_animation: Bool, banner: String? = nil) { self.pubkey = pubkey self.profiles = profiles self._banner = State(initialValue: banner) + self.disable_animation = disable_animation } var body: some View { - InnerBannerImageView(url: get_banner_url(banner: banner, pubkey: pubkey, profiles: profiles)) + InnerBannerImageView(disable_animation: disable_animation, url: get_banner_url(banner: banner, pubkey: pubkey, profiles: profiles)) .onReceive(handle_notify(.profile_updated)) { notif in let updated = notif.object as! ProfileUpdate @@ -76,7 +78,9 @@ struct BannerImageView_Previews: PreviewProvider { static var previews: some View { BannerImageView( pubkey: pubkey, - profiles: make_preview_profiles(pubkey)) + profiles: make_preview_profiles(pubkey), + disable_animation: false + ) } } diff --git a/damus/Views/ChatView.swift b/damus/Views/ChatView.swift @@ -71,11 +71,15 @@ struct ChatView: View { @Environment(\.colorScheme) var colorScheme + var disable_animation: Bool { + self.damus_state.settings.disable_animation + } + var body: some View { HStack { VStack { if is_active || just_started { - ProfilePicView(pubkey: event.pubkey, size: 32, highlight: is_active ? .main : .none, profiles: damus_state.profiles) + ProfilePicView(pubkey: event.pubkey, size: 32, highlight: is_active ? .main : .none, profiles: damus_state.profiles, disable_animation: disable_animation) } Spacer() diff --git a/damus/Views/DMChatView.swift b/damus/Views/DMChatView.swift @@ -43,7 +43,7 @@ struct DMChatView: View { let profile_page = ProfileView(damus_state: damus_state, pubkey: pubkey) return NavigationLink(destination: profile_page) { HStack { - ProfilePicView(pubkey: pubkey, size: 24, highlight: .none, profiles: damus_state.profiles) + ProfilePicView(pubkey: pubkey, size: 24, highlight: .none, profiles: damus_state.profiles, disable_animation: damus_state.settings.disable_animation) ProfileName(pubkey: pubkey, profile: profile, damus: damus_state, show_friend_confirmed: true) } diff --git a/damus/Views/Events/EventProfile.swift b/damus/Views/Events/EventProfile.swift @@ -28,11 +28,15 @@ struct EventProfile: View { eventview_pfp_size(size) } + var disable_animation: Bool { + damus_state.settings.disable_animation + } + var body: some View { HStack(alignment: .center) { VStack { NavigationLink(destination: ProfileView(damus_state: damus_state, pubkey: pubkey)) { - ProfilePicView(pubkey: pubkey, size: pfp_size, highlight: .none, profiles: damus_state.profiles) + ProfilePicView(pubkey: pubkey, size: pfp_size, highlight: .none, profiles: damus_state.profiles, disable_animation: disable_animation) } } diff --git a/damus/Views/Images/ImageContainerView.swift b/damus/Views/Images/ImageContainerView.swift @@ -11,12 +11,13 @@ import Kingfisher // lots of overlap between this and ImageContainerView struct ImageContainerView: View { - let url: URL? @State private var image: UIImage? @State private var showShareSheet = false + let disable_animation: Bool + private struct ImageHandler: ImageModifier { @Binding var handler: UIImage? @@ -29,7 +30,7 @@ struct ImageContainerView: View { var body: some View { KFAnimatedImage(url) - .imageContext(.note) + .imageContext(.note, disable_animation: disable_animation) .configure { view in view.framePreloadCount = 3 } @@ -46,6 +47,6 @@ let test_image_url = URL(string: "https://jb55.com/red-me.jpg")! struct ImageContainerView_Previews: PreviewProvider { static var previews: some View { - ImageContainerView(url: test_image_url) + ImageContainerView(url: test_image_url, disable_animation: false) } } diff --git a/damus/Views/Images/ImageView.swift b/damus/Views/Images/ImageView.swift @@ -16,6 +16,8 @@ struct ImageView: View { @State private var selectedIndex = 0 @State var showMenu = true + let disable_animation: Bool + var tabViewIndicator: some View { HStack(spacing: 10) { ForEach(urls.indices, id: \.self) { index in @@ -37,7 +39,7 @@ struct ImageView: View { TabView(selection: $selectedIndex) { ForEach(urls.indices, id: \.self) { index in ZoomableScrollView { - ImageContainerView(url: urls[index]) + ImageContainerView(url: urls[index], disable_animation: disable_animation) .aspectRatio(contentMode: .fit) .padding(.top, Theme.safeAreaInsets?.top) .padding(.bottom, Theme.safeAreaInsets?.bottom) @@ -77,6 +79,6 @@ struct ImageView: View { struct ImageView_Previews: PreviewProvider { static var previews: some View { - ImageView(urls: [URL(string: "https://jb55.com/red-me.jpg")]) + ImageView(urls: [URL(string: "https://jb55.com/red-me.jpg")], disable_animation: false) } } diff --git a/damus/Views/Images/ProfilePicImageView.swift b/damus/Views/Images/ProfilePicImageView.swift @@ -8,12 +8,13 @@ import SwiftUI import Kingfisher struct ProfileImageContainerView: View { - let url: URL? @State private var image: UIImage? @State private var showShareSheet = false + let disable_animation: Bool + private struct ImageHandler: ImageModifier { @Binding var handler: UIImage? @@ -26,7 +27,7 @@ struct ProfileImageContainerView: View { var body: some View { KFAnimatedImage(url) - .imageContext(.pfp) + .imageContext(.pfp, disable_animation: disable_animation) .configure { view in view.framePreloadCount = 3 } @@ -61,9 +62,9 @@ struct NavDismissBarView: View { } struct ProfilePicImageView: View { - let pubkey: String let profiles: Profiles + let disable_animation: Bool @Environment(\.presentationMode) var presentationMode @@ -73,7 +74,7 @@ struct ProfilePicImageView: View { .ignoresSafeArea() ZoomableScrollView { - ProfileImageContainerView(url: get_profile_url(picture: nil, pubkey: pubkey, profiles: profiles)) + ProfileImageContainerView(url: get_profile_url(picture: nil, pubkey: pubkey, profiles: profiles), disable_animation: disable_animation) .aspectRatio(contentMode: .fit) .padding(.top, Theme.safeAreaInsets?.top) .padding(.bottom, Theme.safeAreaInsets?.bottom) @@ -94,6 +95,8 @@ struct ProfileZoomView_Previews: PreviewProvider { static var previews: some View { ProfilePicImageView( pubkey: pubkey, - profiles: make_preview_profiles(pubkey)) + profiles: make_preview_profiles(pubkey), + disable_animation: false + ) } } diff --git a/damus/Views/NoteContentView.swift b/damus/Views/NoteContentView.swift @@ -123,10 +123,10 @@ struct NoteContentView: View { } if show_images && artifacts.images.count > 0 { - ImageCarousel(previews: damus_state.previews, evid: event.id, urls: artifacts.images) + ImageCarousel(previews: damus_state.previews, evid: event.id, urls: artifacts.images, disable_animation: damus_state.settings.disable_animation) } else if !show_images && artifacts.images.count > 0 { ZStack { - ImageCarousel(previews: damus_state.previews, evid: event.id, urls: artifacts.images) + ImageCarousel(previews: damus_state.previews, evid: event.id, urls: artifacts.images, disable_animation: damus_state.settings.disable_animation) Blur() .disabled(true) } diff --git a/damus/Views/Notifications/ProfilePicturesView.swift b/damus/Views/Notifications/ProfilePicturesView.swift @@ -20,7 +20,7 @@ struct ProfilePicturesView: View { } HStack { ForEach(events.prefix(8)) { ev in - ProfilePicView(pubkey: ev.pubkey, size: 32.0, highlight: .none, profiles: state.profiles) + ProfilePicView(pubkey: ev.pubkey, size: 32.0, highlight: .none, profiles: state.profiles, disable_animation: state.settings.disable_animation) .onTapGesture { nav_target = ev.pubkey navigating = true diff --git a/damus/Views/ParticipantsView.swift b/damus/Views/ParticipantsView.swift @@ -51,7 +51,7 @@ struct ParticipantsView: View { ForEach(originalReferences.pRefs) { participant in let pubkey = participant.id HStack { - ProfilePicView(pubkey: pubkey, size: PFP_SIZE, highlight: .none, profiles: damus_state.profiles) + ProfilePicView(pubkey: pubkey, size: PFP_SIZE, highlight: .none, profiles: damus_state.profiles, disable_animation: damus_state.settings.disable_animation) VStack(alignment: .leading) { let profile = damus_state.profiles.lookup(id: pubkey) diff --git a/damus/Views/PostView.swift b/damus/Views/PostView.swift @@ -281,7 +281,7 @@ struct PostView: View { func Editor(deviceSize: GeometryProxy) -> some View { VStack(alignment: .leading, spacing: 0) { HStack(alignment: .top) { - ProfilePicView(pubkey: damus_state.pubkey, size: PFP_SIZE, highlight: .none, profiles: damus_state.profiles) + ProfilePicView(pubkey: damus_state.pubkey, size: PFP_SIZE, highlight: .none, profiles: damus_state.profiles, disable_animation: damus_state.settings.disable_animation) TextEntry } diff --git a/damus/Views/Profile/EditMetadataView.swift b/damus/Views/Profile/EditMetadataView.swift @@ -125,7 +125,7 @@ struct EditMetadataView: View { var TopSection: some View { ZStack(alignment: .top) { GeometryReader { geo in - BannerImageView(pubkey: damus_state.pubkey, profiles: damus_state.profiles) + BannerImageView(pubkey: damus_state.pubkey, profiles: damus_state.profiles, disable_animation: damus_state.settings.disable_animation) .aspectRatio(contentMode: .fill) .frame(width: geo.size.width, height: BANNER_HEIGHT) .clipped() diff --git a/damus/Views/Profile/MaybeAnonPfpView.swift b/damus/Views/Profile/MaybeAnonPfpView.swift @@ -35,7 +35,7 @@ struct MaybeAnonPfpView: View { .frame(width: size, height: size) } else { NavigationLink(destination: ProfileView(damus_state: state, pubkey: pubkey)) { - ProfilePicView(pubkey: pubkey, size: size, highlight: .none, profiles: state.profiles) + ProfilePicView(pubkey: pubkey, size: size, highlight: .none, profiles: state.profiles, disable_animation: state.settings.disable_animation) } } } diff --git a/damus/Views/Profile/ProfilePicView.swift b/damus/Views/Profile/ProfilePicView.swift @@ -53,13 +53,17 @@ struct EditProfilePictureView: View { .overlay(Circle().stroke(highlight_color(highlight), lineWidth: pfp_line_width(highlight))) .padding(2) } + + var disable_animation: Bool { + damus_state?.settings.disable_animation ?? false + } var body: some View { ZStack { Color(uiColor: .systemBackground) KFAnimatedImage(get_profile_url()) - .imageContext(.pfp) + .imageContext(.pfp, disable_animation: disable_animation) .cancelOnDisappear(true) .configure { view in view.framePreloadCount = 3 @@ -87,12 +91,12 @@ struct EditProfilePictureView: View { } struct InnerProfilePicView: View { - let url: URL? let fallbackUrl: URL? let pubkey: String let size: CGFloat let highlight: Highlight + let disable_animation: Bool var PlaceholderColor: Color { return id_to_color(pubkey) @@ -111,7 +115,7 @@ struct InnerProfilePicView: View { Color(uiColor: .systemBackground) KFAnimatedImage(url) - .imageContext(.pfp) + .imageContext(.pfp, disable_animation: disable_animation) .onFailure(fallbackUrl: fallbackUrl, cacheKey: url?.absoluteString) .cancelOnDisappear(true) .configure { view in @@ -133,19 +137,21 @@ struct ProfilePicView: View { let size: CGFloat let highlight: Highlight let profiles: Profiles + let disable_animation: Bool @State var picture: String? - init (pubkey: String, size: CGFloat, highlight: Highlight, profiles: Profiles, picture: String? = nil) { + init (pubkey: String, size: CGFloat, highlight: Highlight, profiles: Profiles, disable_animation: Bool, picture: String? = nil) { self.pubkey = pubkey self.profiles = profiles self.size = size self.highlight = highlight self._picture = State(initialValue: picture) + self.disable_animation = disable_animation } var body: some View { - InnerProfilePicView(url: get_profile_url(picture: picture, pubkey: pubkey, profiles: profiles), fallbackUrl: URL(string: robohash(pubkey)), pubkey: pubkey, size: size, highlight: highlight) + InnerProfilePicView(url: get_profile_url(picture: picture, pubkey: pubkey, profiles: profiles), fallbackUrl: URL(string: robohash(pubkey)), pubkey: pubkey, size: size, highlight: highlight, disable_animation: disable_animation) .onReceive(handle_notify(.profile_updated)) { notif in let updated = notif.object as! ProfileUpdate @@ -185,7 +191,9 @@ struct ProfilePicView_Previews: PreviewProvider { pubkey: pubkey, size: 100, highlight: .none, - profiles: make_preview_profiles(pubkey)) + profiles: make_preview_profiles(pubkey), + disable_animation: false + ) } } diff --git a/damus/Views/Profile/ProfileView.swift b/damus/Views/Profile/ProfileView.swift @@ -165,7 +165,7 @@ struct ProfileView: View { return AnyView( VStack(spacing: 0) { ZStack { - BannerImageView(pubkey: profile.pubkey, profiles: damus_state.profiles) + BannerImageView(pubkey: profile.pubkey, profiles: damus_state.profiles, disable_animation: damus_state.settings.disable_animation) .aspectRatio(contentMode: .fill) .frame(width: proxy.size.width, height: minY > 0 ? bannerHeight + minY : bannerHeight) .clipped() @@ -332,7 +332,7 @@ struct ProfileView: View { func nameSection(profile_data: Profile?) -> some View { return Group { HStack(alignment: .center) { - ProfilePicView(pubkey: profile.pubkey, size: pfp_size, highlight: .custom(imageBorderColor(), 4.0), profiles: damus_state.profiles) + ProfilePicView(pubkey: profile.pubkey, size: pfp_size, highlight: .custom(imageBorderColor(), 4.0), profiles: damus_state.profiles, disable_animation: damus_state.settings.disable_animation) .padding(.top, -(pfp_size / 2.0)) .offset(y: pfpOffset()) .scaleEffect(pfpScale()) @@ -340,7 +340,8 @@ struct ProfileView: View { is_zoomed.toggle() } .fullScreenCover(isPresented: $is_zoomed) { - ProfilePicImageView(pubkey: profile.pubkey, profiles: damus_state.profiles) } + ProfilePicImageView(pubkey: profile.pubkey, profiles: damus_state.profiles, disable_animation: damus_state.settings.disable_animation) + } Spacer() diff --git a/damus/Views/QRCodeView.swift b/damus/Views/QRCodeView.swift @@ -44,7 +44,7 @@ struct QRCodeView: View { let profile = damus_state.profiles.lookup(id: pubkey) if (damus_state.profiles.lookup(id: pubkey)?.picture) != nil { - ProfilePicView(pubkey: pubkey, size: 90.0, highlight: .custom(DamusColors.white, 4.0), profiles: damus_state.profiles) + ProfilePicView(pubkey: pubkey, size: 90.0, highlight: .custom(DamusColors.white, 4.0), profiles: damus_state.profiles, disable_animation: damus_state.settings.disable_animation) .padding(.top, 50) } else { Image(systemName: "person.fill") diff --git a/damus/Views/SideMenuView.swift b/damus/Views/SideMenuView.swift @@ -58,7 +58,7 @@ struct SideMenuView: View { NavigationLink(destination: ProfileView(damus_state: damus_state, profile: profile_model, followers: followers)) { HStack { - ProfilePicView(pubkey: damus_state.pubkey, size: 60, highlight: .none, profiles: damus_state.profiles) + ProfilePicView(pubkey: damus_state.pubkey, size: 60, highlight: .none, profiles: damus_state.profiles, disable_animation: damus_state.settings.disable_animation) VStack(alignment: .leading) { if let display_name = profile?.display_name {