Skip to content

Commit

Permalink
Fix unexpected zoom when toggling toolbar overlay
Browse files Browse the repository at this point in the history
The media viewer needs to be able to respond to double-taps, to zoom
in/out of the media, and single taps, to hide/show the overlay.

We track the tap position so that we know where the user wants to zoom
into. However, we currently do not reset this tap position after
double-tapping to zoom out of a view.

For example, consider the following scenario:

* Double-tap. We zoom in, and tapLocation is set to zero
* Double-tap again. We zoom out, but tapLocation is not reset
* Single-tap. We fall into the "Scale in to a specific point" branch
* This causes an unexpected zoom-in followed by zoom-out

To fix this, we make sure to always reset the tapPosition to zero after
each zoom action has taken place.
  • Loading branch information
matthewrfennell authored and FriedrichAltheide committed Sep 22, 2024
1 parent c3a6d53 commit 6992277
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Monal/Classes/ZoomableContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,12 @@ struct ZoomableContainer<Content: View>: View {
uiView.setZoomScale(currentScale, animated: true)
} else if tapLocation != .zero { // Scale in to a specific point
uiView.zoom(to: zoomRect(for: uiView, scale: uiView.maximumZoomScale, center: tapLocation), animated: true)
// Reset the location to prevent scaling to it in case of a negative scale (manual pinch)
// Use the main thread to prevent unexpected behavior
DispatchQueue.main.async { tapLocation = .zero }
}

// Reset the location to prevent scaling to it in case of a negative scale (manual pinch)
// Use the main thread to prevent unexpected behavior
DispatchQueue.main.async { tapLocation = .zero }

assert(context.coordinator.hostingController.view.superview == uiView)
}

Expand Down

0 comments on commit 6992277

Please sign in to comment.