Skip to content

Commit

Permalink
add docs, simplify code per PR suggestions
Browse files Browse the repository at this point in the history
# Conflicts:
#	Nos/Views/Components/Images/ImageViewer.swift
#	Nos/Views/LinkPreview.swift
  • Loading branch information
joshuatbrown committed Aug 16, 2024
1 parent 7c80f1a commit 3095f38
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 48 deletions.
37 changes: 24 additions & 13 deletions Nos/Views/Components/Images/ImageViewer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,25 @@ struct ImageViewer: View {
/// The URL of the image to display.
let url: URL

@Environment(\.dismiss) var dismiss
@Environment(\.dismiss) private var dismiss

/// The current zoom scale of the image.
@State private var scale: CGFloat = 1.0

/// The offset of the image. This is updated when the user has zoomed and is panning up, down, left, and right.
@State private var offset: CGSize = .zero

/// The previous offset of the image.
/// - SeeAlso: `offset`
@State private var zoomScale: CGFloat = 1.0

/// The size of the image. Will be set to a non-zero value when the image has loaded.
@State private var imageSize: CGSize = .zero

/// The maximum zoom scale for the image.
private let maxZoomScale: CGFloat = 10.0

/// The minimum zoom scale for the image.
private let minZoomScale: CGFloat = 1.0

var body: some View {
Expand All @@ -26,18 +40,15 @@ struct ImageViewer: View {
ZStack(alignment: .topLeading) {
Color.clear

Button(
action: {
dismiss()
},
label: {
Image(systemName: "xmark")
.symbolVariant(.fill.circle)
.symbolRenderingMode(.palette)
.foregroundStyle(Color.buttonCloseForeground, Color.buttonCloseBackground)
.font(.title)
}
)
Button {
dismiss()
} label: {
Image(systemName: "xmark")
.symbolVariant(.fill.circle)
.symbolRenderingMode(.palette)
.foregroundStyle(Color.buttonCloseForeground, Color.buttonCloseBackground)
.font(.title)
}
.padding()
}
}
Expand Down
62 changes: 27 additions & 35 deletions Nos/Views/LinkPreview.swift
Original file line number Diff line number Diff line change
@@ -1,36 +1,31 @@
import Dependencies
import SwiftUI
import LinkPresentation
import SDWebImageSwiftUI

struct ImageLinkButton: View {
let url: URL

@State private var isViewerPresented: Bool = false
@State private var isViewerPresented = false

var body: some View {
Button(
action: {
isViewerPresented = true
},
label: {
let image = WebImage(url: url)
.resizable()
.indicator(.activity)
Button {
isViewerPresented = true
} label: {
let image = WebImage(url: url)
.resizable()
.indicator(.activity)

ZStack {
image
.blur(radius: 10)
.clipped()
ZStack {
image
.blur(radius: 10)
.clipped()

image
.aspectRatio(contentMode: .fit)
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
.cornerRadius(8)
image
.aspectRatio(contentMode: .fit)
.frame(maxWidth: .infinity, maxHeight: .infinity)
}

)
.cornerRadius(8)
}
.sheet(isPresented: $isViewerPresented) {
ImageViewer(url: url)
}
Expand All @@ -40,22 +35,19 @@ struct ImageLinkButton: View {
struct HeroImageButton: View {
let url: URL

@State private var isViewerPresented: Bool = false
@State private var isViewerPresented = false

var body: some View {
Button(
action: {
isViewerPresented = true
},
label: {
WebImage(url: url)
.resizable()
.indicator(.activity)
.aspectRatio(contentMode: .fill)
.clipped()
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
)
Button {
isViewerPresented = true
} label: {
WebImage(url: url)
.resizable()
.indicator(.activity)
.aspectRatio(contentMode: .fill)
.clipped()
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
.sheet(isPresented: $isViewerPresented) {
ImageViewer(url: url)
}
Expand Down

0 comments on commit 3095f38

Please sign in to comment.