From c04a5800f80108b0e2a507fa6be3031376f46f9b Mon Sep 17 00:00:00 2001 From: Eric Andrews Date: Mon, 16 Dec 2024 18:46:24 -0500 Subject: [PATCH] streamline opacity --- Mlem/App/Views/Pages/ImageViewer.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Mlem/App/Views/Pages/ImageViewer.swift b/Mlem/App/Views/Pages/ImageViewer.swift index aadcfba55..24b81d7c4 100644 --- a/Mlem/App/Views/Pages/ImageViewer.swift +++ b/Mlem/App/Views/Pages/ImageViewer.swift @@ -34,7 +34,7 @@ struct ImageViewer: View { DynamicMediaView(url: url, cornerRadius: 0, playImmediately: true) } .offset(y: offset) - .background(Color.black.opacity(1.0 - (abs(offset) / screenHeight))) + .background(.black) .opacity(opacity) .overlay(alignment: .topTrailing) { if offset == 0 { @@ -52,19 +52,18 @@ struct ImageViewer: View { .padding(Constants.main.standardSpacing) } } - .onAppear { - updateOpacity(1.0) - } .simultaneousGesture(DragGesture(minimumDistance: 0.0) - .onChanged { value in + .updating($dragState) { value, state, _ in + state = true if !isZoomed, !isDismissing { offset = value.translation.height + opacity = 1.0 - (abs(value.translation.height) / screenHeight) } } - .updating($dragState) { _, state, _ in - state = true - } ) + .onAppear { + updateOpacity(1.0) + } .onChange(of: dragState) { if !dragState { if abs(offset) > 100 { @@ -104,6 +103,7 @@ struct ImageViewer: View { private func updateDragDistance(_ newDistance: CGFloat, callback: (() -> Void)? = nil) { withAnimation(.easeOut(duration: duration)) { offset = newDistance + opacity = 1.0 - (abs(newDistance) / screenHeight) } if let callback { DispatchQueue.main.asyncAfter(deadline: .now() + duration) {