Skip to content

Commit 87a7a1d

Browse files
authored
Merge pull request #26 from Isvvc/master
Fix laggy dragging
2 parents ff4a269 + 53dfdd2 commit 87a7a1d

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

Sources/ImageViewer/ImageViewer.swift

+6-2
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,16 @@ public struct ImageViewer: View {
8484
}
8585
.onEnded { value in
8686
if((abs(self.dragOffset.height) + abs(self.dragOffset.width) > 570) || ((abs(self.dragOffsetPredicted.height)) / (abs(self.dragOffset.height)) > 3) || ((abs(self.dragOffsetPredicted.width)) / (abs(self.dragOffset.width))) > 3) {
87+
withAnimation(.spring()) {
88+
self.dragOffset = self.dragOffsetPredicted
89+
}
8790
self.viewerShown = false
8891

8992
return
9093
}
91-
self.dragOffset = .zero
94+
withAnimation(.interactiveSpring()) {
95+
self.dragOffset = .zero
96+
}
9297
}
9398
)
9499

@@ -273,7 +278,6 @@ struct PinchToZoom: ViewModifier {
273278
content
274279
.scaleEffect(scale, anchor: anchor)
275280
.offset(offset)
276-
.animation(isPinching ? .none : .spring())
277281
.overlay(PinchZoom(scale: $scale, anchor: $anchor, offset: $offset, isPinching: $isPinching))
278282
}
279283
}

Sources/ImageViewerRemote/ImageViewerRemote.swift

+12-3
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,15 @@ public struct ImageViewerRemote: View {
7676
}
7777
.onEnded { value in
7878
if((abs(self.dragOffset.height) + abs(self.dragOffset.width) > 570) || ((abs(self.dragOffsetPredicted.height)) / (abs(self.dragOffset.height)) > 3) || ((abs(self.dragOffsetPredicted.width)) / (abs(self.dragOffset.width))) > 3) {
79+
withAnimation(.spring()) {
80+
self.dragOffset = self.dragOffsetPredicted
81+
}
7982
self.viewerShown = false
8083
return
8184
}
82-
self.dragOffset = .zero
85+
withAnimation(.interactiveSpring()) {
86+
self.dragOffset = .zero
87+
}
8388
}
8489
)
8590
})
@@ -99,10 +104,15 @@ public struct ImageViewerRemote: View {
99104
}
100105
.onEnded { value in
101106
if((abs(self.dragOffset.height) + abs(self.dragOffset.width) > 570) || ((abs(self.dragOffsetPredicted.height)) / (abs(self.dragOffset.height)) > 3) || ((abs(self.dragOffsetPredicted.width)) / (abs(self.dragOffset.width))) > 3) {
107+
withAnimation(.spring()) {
108+
self.dragOffset = self.dragOffsetPredicted
109+
}
102110
self.viewerShown = false
103111
return
104112
}
105-
self.dragOffset = .zero
113+
withAnimation(.interactiveSpring()) {
114+
self.dragOffset = .zero
115+
}
106116
}
107117
)
108118
}
@@ -291,7 +301,6 @@ struct PinchToZoom: ViewModifier {
291301
content
292302
.scaleEffect(scale, anchor: anchor)
293303
.offset(offset)
294-
.animation(isPinching ? .none : .spring())
295304
.overlay(PinchZoom(scale: $scale, anchor: $anchor, offset: $offset, isPinching: $isPinching))
296305
}
297306
}

0 commit comments

Comments
 (0)