Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collapse Images #1607

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions damus/Models/UserSettingsStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ class UserSettingsStore: ObservableObject {
@Setting(key: "always_show_images", default_value: false)
var always_show_images: Bool

@Setting(key: "collapse_images", default_value: false)
var collapse_images: Bool

@Setting(key: "hide_nsfw_tagged_content", default_value: false)
var hide_nsfw_tagged_content: Bool

Expand Down
48 changes: 31 additions & 17 deletions damus/Views/NoteContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions damus/Views/Settings/AppearanceSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ struct AppearanceSettingsView: View {
Toggle(NSLocalizedString("Always show images", comment: "Setting to always show and never blur images"), isOn: $settings.always_show_images)
.toggleStyle(.switch)

Toggle(NSLocalizedString("Collapse images", comment: "Setting to only show image links"), isOn: $settings.collapse_images)
.toggleStyle(.switch)

Picker(NSLocalizedString("Image uploader", comment: "Prompt selection of user's image uploader"),
selection: $settings.default_media_uploader) {
ForEach(MediaUploader.allCases, id: \.self) { uploader in
Expand Down
Loading