Skip to content
Open
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
5 changes: 4 additions & 1 deletion Sources/Zoomable/ZoomableImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public struct ZoomableImageView<Content>: View where Content: View {
private var min: CGFloat = 1.0
private var max: CGFloat = 3.0
private var showsIndicators: Bool = false
@Binding var scale: CGFloat
@ViewBuilder private var overlay: () -> Content

@State private var imageSize: CGSize = .zero
Expand All @@ -48,17 +49,19 @@ public struct ZoomableImageView<Content>: View where Content: View {
min: CGFloat = 1.0,
max: CGFloat = 3.0,
showsIndicators: Bool = false,
scale: Binding<CGFloat>,
@ViewBuilder overlay: @escaping () -> Content) {
self.url = url
self.min = min
self.max = max
self.showsIndicators = showsIndicators
self._scale = scale
self.overlay = overlay
}

public var body: some View {
GeometryReader { proxy in
ZoomableView(size: imageSize, min: self.min, max: self.max, showsIndicators: self.showsIndicators) {
ZoomableView(size: imageSize, min: self.min, max: self.max, showsIndicators: self.showsIndicators, scale: self.scale) {
WebImage(url: url)
.resizable()
.onSuccess(perform: { image, _, _ in
Expand Down
6 changes: 4 additions & 2 deletions Sources/Zoomable/ZoomableModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public struct ZoomableModifier: ViewModifier {
private var showsIndicators: Bool = false

@GestureState private var zoomState = ZoomState.inactive
@State private var currentScale: CGFloat = 1.0
@Binding var currentScale: CGFloat

/**
Initializes an `ZoomableModifier`
Expand All @@ -58,11 +58,13 @@ public struct ZoomableModifier: ViewModifier {
public init(contentSize: CGSize,
min: CGFloat = 1.0,
max: CGFloat = 3.0,
showsIndicators: Bool = false) {
showsIndicators: Bool = false,
scale: Binding<CGFloat> ) {
self.contentSize = contentSize
self.min = min
self.max = max
self.showsIndicators = showsIndicators
self._currentScale = scale
}

var scale: CGFloat {
Expand Down
5 changes: 4 additions & 1 deletion Sources/Zoomable/ZoomableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public struct ZoomableView<Content>: View where Content: View {
private var min: CGFloat = 1.0
private var max: CGFloat = 3.0
private var showsIndicators: Bool = false
@Binding var scale: CGFloat
@ViewBuilder private var content: () -> Content

/**
Expand All @@ -45,18 +46,20 @@ public struct ZoomableView<Content>: View where Content: View {
min: CGFloat = 1.0,
max: CGFloat = 3.0,
showsIndicators: Bool = false,
scale: Binding<CGFloat>,
@ViewBuilder content: @escaping () -> Content) {
self.size = size
self.min = min
self.max = max
self.showsIndicators = showsIndicators
self._scale = scale
self.content = content
}

public var body: some View {
content()
.frame(width: size.width, height: size.height, alignment: .center)
.contentShape(Rectangle())
.modifier(ZoomableModifier(contentSize: self.size, min: min, max: max, showsIndicators: showsIndicators))
.modifier(ZoomableModifier(contentSize: self.size, min: min, max: max, showsIndicators: showsIndicators, scale: $scale))
}
}