From 246b20d07998f7bbe60f8cf7f22944a57dc915bc Mon Sep 17 00:00:00 2001 From: infinitepower18 <44692189+infinitepower18@users.noreply.github.com> Date: Wed, 14 Aug 2024 22:24:08 +0100 Subject: [PATCH] Disable spring animation for scroll zoom due to performance issue --- Sources/CropImage/UnderlyingImageView.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Sources/CropImage/UnderlyingImageView.swift b/Sources/CropImage/UnderlyingImageView.swift index 2c87225..6d7ab11 100644 --- a/Sources/CropImage/UnderlyingImageView.swift +++ b/Sources/CropImage/UnderlyingImageView.swift @@ -25,6 +25,7 @@ struct UnderlyingImageView: View { @State private var tempOffset: CGSize = .zero @State private var tempScale: CGFloat = 1 @State private var tempRotation: Angle = .zero + @State private var scrolling: Bool = false #if os(macOS) @State private var isHovering: Bool = false #endif @@ -69,9 +70,15 @@ struct UnderlyingImageView: View { clampedOffset.height = clampedOffset.height.clamped(to: yOffsetBounds(at: clampedScale)) if clampedScale != scale || clampedOffset != offset { - withAnimation(.interactiveSpring()) { + if scrolling { scale = clampedScale offset = clampedOffset + scrolling = false + } else { + withAnimation(.interactiveSpring()) { + scale = clampedScale + offset = clampedOffset + } } } } @@ -88,6 +95,7 @@ struct UnderlyingImageView: View { #if os(macOS) NSEvent.addLocalMonitorForEvents(matching: .scrollWheel) {event in if isHovering { + scrolling = true scale = scale + event.scrollingDeltaY/1000 } return event