swipe with drag offset works now

fix_swipe
saint 2024-06-09 10:32:59 -04:00
parent a8648b8508
commit c04469ef19
1 changed files with 15 additions and 12 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 {
@ -438,25 +440,28 @@ struct ContentView: View {
// 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
@ -470,6 +475,7 @@ struct ContentView: View {
if startSwipeDir == .left {
finalSwipe = swipeLeftFinal
setDragOffset = margin + swipeLeftFinal
} else {
finalSwipe = .zero
}
@ -478,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 {
@ -496,8 +499,8 @@ struct ContentView: View {
withAnimation(.spring(response: 0.2)) {
pulledOut.width = finalSwipe
// dragOffset = setDragOffset
mainSwipe = .zero
dragOffset = setDragOffset
mainSwipe = .zero
}
}
)