From a3c48406075db4cfcdc66d11465249605b5bc15f Mon Sep 17 00:00:00 2001 From: ericholguin Date: Sat, 14 Oct 2023 16:46:58 -0600 Subject: [PATCH] ui: dont display images when users have collapse image setting enabled --- damus/Views/NoteContentView.swift | 48 ++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/damus/Views/NoteContentView.swift b/damus/Views/NoteContentView.swift index 4842d2757a..3e3351661d 100644 --- a/damus/Views/NoteContentView.swift +++ b/damus/Views/NoteContentView.swift @@ -26,7 +26,7 @@ struct NoteContentView: View { let damus_state: DamusState let event: NostrEvent - @State var show_images: Bool + @State var blur_images: Bool let size: EventViewKind let preview_height: CGFloat? let options: EventViewOptions @@ -39,10 +39,10 @@ struct NoteContentView: View { return self.artifacts_model.state.artifacts ?? .separated(.just_content(event.get_content(damus_state.keypair))) } - init(damus_state: DamusState, event: NostrEvent, show_images: Bool, size: EventViewKind, options: EventViewOptions) { + init(damus_state: DamusState, event: NostrEvent, blur_images: Bool, size: EventViewKind, options: EventViewOptions) { self.damus_state = damus_state self.event = event - self.show_images = show_images + self.blur_images = blur_images self.size = size self.options = options self.preview_height = lookup_cached_preview_size(previews: damus_state.previews, evid: event.id) @@ -61,7 +61,7 @@ struct NoteContentView: View { } var preview: LinkViewRepresentable? { - guard show_images, + guard blur_images, case .loaded(let preview) = preview_model.state, case .value(let cached) = preview else { return nil @@ -92,7 +92,7 @@ struct NoteContentView: View { func previewView(links: [URL]) -> some View { Group { - if let preview = self.preview, show_images { + if let preview = self.preview, blur_images { if let preview_height { preview .frame(height: preview_height) @@ -133,17 +133,31 @@ struct NoteContentView: View { } } - if show_images && artifacts.media.count > 0 { - ImageCarousel(state: damus_state, evid: event.id, urls: artifacts.media) - } else if !show_images && artifacts.media.count > 0 { - ZStack { - ImageCarousel(state: damus_state, evid: event.id, urls: artifacts.media) - Blur() - .onTapGesture { - show_images = true + if damus_state.settings.collapse_images { + ForEach(artifacts.media.indices, id: \.self) { index in + switch artifacts.media[index] { + case .image(let url), .video(let url): + if with_padding { + truncatedText(content: url_str(url)) + .padding(.horizontal) + } else { + truncatedText(content: url_str(url)) } + } + } + } else { + if blur_images && artifacts.media.count > 0 { + ImageCarousel(state: damus_state, evid: event.id, urls: artifacts.media) + } else if !blur_images && artifacts.media.count > 0 { + ZStack { + ImageCarousel(state: damus_state, evid: event.id, urls: artifacts.media) + Blur() + .onTapGesture { + blur_images = true + } + } + //.cornerRadius(10) } - //.cornerRadius(10) } if artifacts.invoices.count > 0 { @@ -618,17 +632,17 @@ struct NoteContentView_Previews: PreviewProvider { Group { VStack { - NoteContentView(damus_state: state, event: test_note, show_images: true, size: .normal, options: []) + NoteContentView(damus_state: state, event: test_note, blur_images: true, size: .normal, options: []) } .previewDisplayName("Short note") VStack { - NoteContentView(damus_state: state, event: test_encoded_note_with_image!, show_images: true, size: .normal, options: []) + NoteContentView(damus_state: state, event: test_encoded_note_with_image!, blur_images: true, size: .normal, options: []) } .previewDisplayName("Note with image") VStack { - NoteContentView(damus_state: state2, event: test_longform_event.event, show_images: true, size: .normal, options: [.wide]) + NoteContentView(damus_state: state2, event: test_longform_event.event, blur_images: true, size: .normal, options: [.wide]) .border(Color.red) } .previewDisplayName("Long-form note")