Compare commits

..

No commits in common. "c04469ef19936fd57f0b771856516d06ddd177d8" and "56b32c39abb243ae5b992aa44c7aae6c2bd21c5c" have entirely different histories.

1 changed files with 26 additions and 22 deletions

View File

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