Skip to content

Commit

Permalink
streamline opacity
Browse files Browse the repository at this point in the history
  • Loading branch information
EricBAndrews committed Dec 16, 2024
1 parent 67384e5 commit c04a580
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions Mlem/App/Views/Pages/ImageViewer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit c04a580

Please sign in to comment.