From 7827c03a859a1341105ffe435d658f921f1bf18d Mon Sep 17 00:00:00 2001 From: Juan David Hurtado Date: Mon, 29 Aug 2022 14:04:58 -0500 Subject: [PATCH 1/3] fix: image viewer removal transition fixed --- .../Examples/Complex/ImageViewerExample.swift | 8 ++++++-- .../Image Viewer/PuraceImageViewerModifier.swift | 14 ++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/PuraceDemo/PuraceDemo/Examples/Complex/ImageViewerExample.swift b/PuraceDemo/PuraceDemo/Examples/Complex/ImageViewerExample.swift index 65d9b82..284d854 100644 --- a/PuraceDemo/PuraceDemo/Examples/Complex/ImageViewerExample.swift +++ b/PuraceDemo/PuraceDemo/Examples/Complex/ImageViewerExample.swift @@ -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( diff --git a/Sources/Purace/Views/Complex/Image Viewer/PuraceImageViewerModifier.swift b/Sources/Purace/Views/Complex/Image Viewer/PuraceImageViewerModifier.swift index 257d8c3..f1d0da6 100644 --- a/Sources/Purace/Views/Complex/Image Viewer/PuraceImageViewerModifier.swift +++ b/Sources/Purace/Views/Complex/Image Viewer/PuraceImageViewerModifier.swift @@ -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) + } + } + ) } } From d8b5b4495f9b3784ff806dead1e2e9d9af5f640d Mon Sep 17 00:00:00 2001 From: Juan David Hurtado Date: Mon, 29 Aug 2022 14:30:42 -0500 Subject: [PATCH 2/3] fix: improve image viewer top bar behaviour --- .../Views/Complex/Image Viewer/PuraceImageViewer.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sources/Purace/Views/Complex/Image Viewer/PuraceImageViewer.swift b/Sources/Purace/Views/Complex/Image Viewer/PuraceImageViewer.swift index 6d2838a..7d13513 100644 --- a/Sources/Purace/Views/Complex/Image Viewer/PuraceImageViewer.swift +++ b/Sources/Purace/Views/Complex/Image Viewer/PuraceImageViewer.swift @@ -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 @@ -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) } } @@ -96,12 +96,14 @@ public struct PuraceImageViewer: View { withAnimation { backgroundOpacity = 1 - progress } + userHasDropped = false } .onEnded { _ in if abs(dragOffset) < 200 { withAnimation { dragOffset = 0 backgroundOpacity = 1 + userHasDropped = true } } else { withAnimation { From 4b9e74e19ab313ee947a8ac8cc227712ebc5af1e Mon Sep 17 00:00:00 2001 From: Juan David Hurtado Date: Fri, 2 Sep 2022 16:35:28 -0500 Subject: [PATCH 3/3] fix: top bar opacity behaviour fixed --- .../Complex/Image Viewer/PuraceImageViewer.swift | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Sources/Purace/Views/Complex/Image Viewer/PuraceImageViewer.swift b/Sources/Purace/Views/Complex/Image Viewer/PuraceImageViewer.swift index 7d13513..65de36b 100644 --- a/Sources/Purace/Views/Complex/Image Viewer/PuraceImageViewer.swift +++ b/Sources/Purace/Views/Complex/Image Viewer/PuraceImageViewer.swift @@ -91,12 +91,14 @@ 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 + } } - userHasDropped = false } .onEnded { _ in if abs(dragOffset) < 200 {