Compare commits
2 Commits
56b32c39ab
...
c04469ef19
Author | SHA1 | Date |
---|---|---|
|
c04469ef19 | |
|
a8648b8508 |
|
@ -372,6 +372,8 @@ 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 {
|
||||||
|
@ -410,60 +412,56 @@ struct ContentView: View {
|
||||||
if startSwipeDir == .left {
|
if startSwipeDir == .left {
|
||||||
maxOffsetLeft = .zero
|
maxOffsetLeft = .zero
|
||||||
maxOffsetRight = .zero
|
maxOffsetRight = .zero
|
||||||
} else {
|
} else if startSwipeDir == .right {
|
||||||
maxOffsetLeft = CGFloat(200)
|
maxOffsetLeft = CGFloat(200)
|
||||||
maxOffsetRight = .zero
|
maxOffsetRight = CGFloat(10)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
newOffset = maxOffsetRight + rubberBandEffect(newOffset - 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
|
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
|
||||||
|
@ -477,6 +475,7 @@ struct ContentView: View {
|
||||||
|
|
||||||
if startSwipeDir == .left {
|
if startSwipeDir == .left {
|
||||||
finalSwipe = swipeLeftFinal
|
finalSwipe = swipeLeftFinal
|
||||||
|
setDragOffset = margin + swipeLeftFinal
|
||||||
} else {
|
} else {
|
||||||
finalSwipe = .zero
|
finalSwipe = .zero
|
||||||
}
|
}
|
||||||
|
@ -485,9 +484,6 @@ 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 {
|
||||||
|
@ -503,8 +499,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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue