swiping a bit better

master
Saint 2024-06-24 00:53:15 -04:00
parent 3af58e417f
commit b8764b5577
1 changed files with 11 additions and 27 deletions

View File

@ -399,7 +399,7 @@ struct ContentView: View {
.offset(x: pulledOut.width) .offset(x: pulledOut.width)
.offset(x: mainSwipe.width) .offset(x: mainSwipe.width)
.highPriorityGesture( .highPriorityGesture(
DragGesture(minimumDistance: 30) DragGesture(minimumDistance: 20)
.updating($dragGestureActive) { value, state, _ in .updating($dragGestureActive) { value, state, _ in
print("pop here") print("pop here")
state = value.translation state = value.translation
@ -430,35 +430,18 @@ struct ContentView: View {
} }
// Apply resistance if out of bounds // Apply resistance if out of bounds
var maxOffsetRight: CGFloat = 150 let maxRight: CGFloat = 140
let finalRight: CGFloat = 110
let rightDiff = maxRight - finalRight
var maxOffsetLeft: CGFloat = -200 var maxOffsetLeft: CGFloat = -200
// if startSwipeState == .right { if newOffset > maxRight , pulledOut.width == 0 {
// if startSwipeDir == .right { // newOffset = maxRight + rubberBandEffect(newOffset)
// maxOffsetRight = .zero newOffset = maxRight + rubberBandEffect(newOffset - maxRight)
// maxOffsetLeft = .zero
// } else if startSwipeDir == .left {
// maxOffsetRight = CGFloat(110)
// maxOffsetLeft = CGFloat(-30)
// }
// } else if startSwipeState == .left {
// if startSwipeDir == .left {
// maxOffsetLeft = .zero
// maxOffsetRight = .zero
// } else if startSwipeDir == .right {
// maxOffsetLeft = CGFloat(200)
// maxOffsetRight = CGFloat(10)
// }
// }
if newOffset > maxOffsetRight, pulledOut.width == 0 {
// newOffset = maxOffsetRight + rubberBandEffect(newOffset)
newOffset = maxOffsetRight + rubberBandEffect(newOffset - maxOffsetRight)
} }
if newOffset > 0, pulledOut.width > 0 { if newOffset > rightDiff, pulledOut.width > 0 {
newOffset = rubberBandEffect(newOffset) newOffset = rightDiff + rubberBandEffect(newOffset - rightDiff)
} }
if newOffset < maxOffsetLeft, pulledOut.width == 0 { if newOffset < maxOffsetLeft, pulledOut.width == 0 {
@ -584,9 +567,10 @@ struct ContentView: View {
func handleVisibilityChanged2(_: String, change _: VisibilityChange, tracker _: VisibilityTracker<String>) {} func handleVisibilityChanged2(_: String, change _: VisibilityChange, tracker _: VisibilityTracker<String>) {}
func rubberBandEffect(_ offset: CGFloat) -> CGFloat { func rubberBandEffect(_ offset: CGFloat) -> CGFloat {
let resistance: CGFloat = 0.05 let resistance: CGFloat = 0.05
return 4 * log(offset + 1) return 6 * log(offset + 1)
// return resistance * pow(abs(offset), 1) * (offset < 0 ? -1 : 1) // return resistance * pow(abs(offset), 1) * (offset < 0 ? -1 : 1)
} }