Compare commits

..

2 Commits

Author SHA1 Message Date
saint c04469ef19 swipe with drag offset works now 2024-06-09 10:32:59 -04:00
saint a8648b8508 swiping seems to work fine, need to fix dragoffset now 2024-06-09 10:25:08 -04:00
1 changed files with 22 additions and 26 deletions

View File

@ -372,6 +372,8 @@ struct ContentView: View {
.onChanged { value in
// Calculate the offset
let margin = CGFloat(30)
var newOffset = value.translation.width
if startSwipeState == nil {
if pulledOut.width == 0 {
@ -410,60 +412,56 @@ struct ContentView: View {
if startSwipeDir == .left {
maxOffsetLeft = .zero
maxOffsetRight = .zero
} else {
} else if startSwipeDir == .right {
maxOffsetLeft = CGFloat(200)
maxOffsetRight = .zero
maxOffsetRight = CGFloat(10)
}
}
if newOffset + pulledOut.width < -maxOffsetLeft {
if startSwipeState == .right && startSwipeDir == .left {
print("meow here")
newOffset = -maxOffsetLeft + rubberBandEffect(newOffset + maxOffsetLeft) - pulledOut.width
} else {
print("meow here")
newOffset = -maxOffsetLeft + rubberBandEffect(newOffset + maxOffsetLeft)
}
} else if newOffset + pulledOut.width > maxOffsetRight {
if startSwipeState == .left, startSwipeDir == .right {
newOffset = maxOffsetRight + rubberBandEffect(newOffset - maxOffsetRight) - pulledOut.width
} else {
newOffset = maxOffsetRight + rubberBandEffect(newOffset - maxOffsetRight)
}
// if newOffset.height < -maxOffset {
// newOffset.height = -maxOffset + rubberBandEffect(newOffset.height + maxOffset)
// } else if newOffset.height > maxOffset {
// newOffset.height = maxOffset + rubberBandEffect(newOffset.height - maxOffset)
// }
}
self.mainSwipe.width = newOffset
// dragOffset is what is used to make the text be readable
// with the right pane being visible
// if mainSwipe.width < -margin && pulledOut.width <= 0 {
// if mainSwipe.width < -margin && pulledOut.width <= 0 {
// dragOffset = margin + mainSwipe.width + pulledOut.width
// }
if mainSwipe.width < -margin && pulledOut.width <= 0 {
dragOffset = margin + mainSwipe.width + pulledOut.width
}
// if mainSwipe.width > 0 && pulledOut.width < 0 {
// dragOffset = margin + mainSwipe.width + pulledOut.width
// }
if mainSwipe.width > 0 && pulledOut.width < 0 {
dragOffset = margin + mainSwipe.width + pulledOut.width
}
}
.onEnded { _ in
var finalSwipe = CGFloat(0)
let swipeLeftFinal = CGFloat(-200)
let swipeRightFinal = CGFloat(110)
// let margin = CGFloat(30)
let margin = CGFloat(30)
var setDragOffset = CGFloat(0)
if startSwipeState == .center {
if startSwipeDir == .right {
finalSwipe = swipeRightFinal
} else {
finalSwipe = swipeLeftFinal
setDragOffset = margin + swipeLeftFinal
}
} else if startSwipeState == .right {
finalSwipe = .zero
@ -477,6 +475,7 @@ struct ContentView: View {
if startSwipeDir == .left {
finalSwipe = swipeLeftFinal
setDragOffset = margin + swipeLeftFinal
} else {
finalSwipe = .zero
}
@ -485,9 +484,6 @@ struct ContentView: View {
startSwipeState = nil
startSwipeDir = nil
// var setDragOffset = CGFloat(0)
// if mainSwipe.width < 0 && pulledOut.width > 0 {
// setPulledOutWith = CGFloat(0)
// } else if mainSwipe.width > 0 && pulledOut.width < 0 {
@ -503,7 +499,7 @@ struct ContentView: View {
withAnimation(.spring(response: 0.2)) {
pulledOut.width = finalSwipe
// dragOffset = setDragOffset
dragOffset = setDragOffset
mainSwipe = .zero
}
}