Skip to content

Commit

Permalink
Merge pull request #34 from payan-app/image-viewer
Browse files Browse the repository at this point in the history
fix: add minor fixes to image viewer
  • Loading branch information
juandahurt authored Sep 2, 2022
2 parents 729ac91 + 4b9e74e commit d1ad696
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ struct ImageViewerExample: View {

var body: some View {
VStack {
PuraceButtonView("Mostrar imagen") {
isVisible.toggle()
HStack {
Spacer()
PuraceButtonView("Mostrar imagen") {
isVisible.toggle()
}
Spacer()
}
Spacer()
}.imageViewer(
Expand Down
16 changes: 10 additions & 6 deletions Sources/Purace/Views/Complex/Image Viewer/PuraceImageViewer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public struct PuraceImageViewer: View {
@GestureState var scale: CGFloat = 1
@State var dragOffset: CGFloat = .zero
@State var backgroundOpacity = 1.0

@State var userHasDropped = true
private let numberOfImages: Int

private let maximumImageHeight = UIScreen.main.bounds.height * 0.65
Expand Down Expand Up @@ -61,7 +61,7 @@ public struct PuraceImageViewer: View {

indicator
}.frame(height: 60)
.opacity((abs(dragOffset) >= .zero && abs(dragOffset) <= 5) ? 1 : 0.0002)
.opacity((abs(dragOffset) >= .zero && abs(dragOffset) <= 5 && userHasDropped) ? 1 : 0.0002)
}
}

Expand Down Expand Up @@ -91,17 +91,21 @@ public struct PuraceImageViewer: View {
DragGesture()
.onChanged { value in
dragOffset = value.translation.height
let screenHeight = UIScreen.main.bounds.height
let progress = abs(dragOffset) / screenHeight / 2
withAnimation {
backgroundOpacity = 1 - progress
if abs(dragOffset) > 5 {
let screenHeight = UIScreen.main.bounds.height
let progress = abs(dragOffset) / screenHeight / 2
withAnimation {
backgroundOpacity = 1 - progress
userHasDropped = false
}
}
}
.onEnded { _ in
if abs(dragOffset) < 200 {
withAnimation {
dragOffset = 0
backgroundOpacity = 1
userHasDropped = true
}
} else {
withAnimation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ public struct PuraceImageViewerModifier: ViewModifier {
}

public func body(content: Content) -> some View {
ZStack {
content
if isVisible {
PuraceImageViewer(urls: urls, isVisible: $isVisible, index: selectedIndex)
}
}
content
.overlay(
Group {
if isVisible {
PuraceImageViewer(urls: urls, isVisible: $isVisible, index: selectedIndex)
}
}
)
}
}

Expand Down

0 comments on commit d1ad696

Please sign in to comment.