From 6992277b84541b7f3276e1eb932d29c9c08723a9 Mon Sep 17 00:00:00 2001 From: Matthew Fennell Date: Sat, 21 Sep 2024 23:36:50 +0100 Subject: [PATCH] Fix unexpected zoom when toggling toolbar overlay 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. --- Monal/Classes/ZoomableContainer.swift | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Monal/Classes/ZoomableContainer.swift b/Monal/Classes/ZoomableContainer.swift index 64d9e40e2f..4559414234 100644 --- a/Monal/Classes/ZoomableContainer.swift +++ b/Monal/Classes/ZoomableContainer.swift @@ -87,11 +87,12 @@ struct ZoomableContainer: 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) }