mirror of
https://github.com/laosb/CropImage.git
synced 2025-04-30 23:51:08 +00:00
Disable spring animation for scroll zoom due to performance issue
This commit is contained in:
parent
672ec51d3e
commit
246b20d079
1 changed files with 9 additions and 1 deletions
|
@ -25,6 +25,7 @@ struct UnderlyingImageView: View {
|
||||||
@State private var tempOffset: CGSize = .zero
|
@State private var tempOffset: CGSize = .zero
|
||||||
@State private var tempScale: CGFloat = 1
|
@State private var tempScale: CGFloat = 1
|
||||||
@State private var tempRotation: Angle = .zero
|
@State private var tempRotation: Angle = .zero
|
||||||
|
@State private var scrolling: Bool = false
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
@State private var isHovering: Bool = false
|
@State private var isHovering: Bool = false
|
||||||
#endif
|
#endif
|
||||||
|
@ -69,12 +70,18 @@ struct UnderlyingImageView: View {
|
||||||
clampedOffset.height = clampedOffset.height.clamped(to: yOffsetBounds(at: clampedScale))
|
clampedOffset.height = clampedOffset.height.clamped(to: yOffsetBounds(at: clampedScale))
|
||||||
|
|
||||||
if clampedScale != scale || clampedOffset != offset {
|
if clampedScale != scale || clampedOffset != offset {
|
||||||
|
if scrolling {
|
||||||
|
scale = clampedScale
|
||||||
|
offset = clampedOffset
|
||||||
|
scrolling = false
|
||||||
|
} else {
|
||||||
withAnimation(.interactiveSpring()) {
|
withAnimation(.interactiveSpring()) {
|
||||||
scale = clampedScale
|
scale = clampedScale
|
||||||
offset = clampedOffset
|
offset = clampedOffset
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func setInitialScale(basedOn viewSize: CGSize) {
|
func setInitialScale(basedOn viewSize: CGSize) {
|
||||||
guard viewSize != .zero else { return }
|
guard viewSize != .zero else { return }
|
||||||
|
@ -88,6 +95,7 @@ struct UnderlyingImageView: View {
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
NSEvent.addLocalMonitorForEvents(matching: .scrollWheel) {event in
|
NSEvent.addLocalMonitorForEvents(matching: .scrollWheel) {event in
|
||||||
if isHovering {
|
if isHovering {
|
||||||
|
scrolling = true
|
||||||
scale = scale + event.scrollingDeltaY/1000
|
scale = scale + event.scrollingDeltaY/1000
|
||||||
}
|
}
|
||||||
return event
|
return event
|
||||||
|
|
Loading…
Add table
Reference in a new issue