Compare commits
No commits in common. "56b32c39abb243ae5b992aa44c7aae6c2bd21c5c" and "ed1377d9c5e3855f7494ad3bedcaf29af1676430" have entirely different histories.
56b32c39ab
...
ed1377d9c5
|
@ -243,21 +243,6 @@ struct ContentView: View {
|
||||||
|
|
||||||
@State var dragOffset = CGFloat(0)
|
@State var dragOffset = CGFloat(0)
|
||||||
|
|
||||||
enum SwipeStartState {
|
|
||||||
case center
|
|
||||||
case right
|
|
||||||
case left
|
|
||||||
}
|
|
||||||
|
|
||||||
enum SwipeStartDir {
|
|
||||||
case left
|
|
||||||
case right
|
|
||||||
}
|
|
||||||
|
|
||||||
// @State var curSwipeState: SwipeState = .start
|
|
||||||
@State var startSwipeState: SwipeStartState?
|
|
||||||
@State var startSwipeDir: SwipeStartDir?
|
|
||||||
|
|
||||||
@Environment(\.appDatabase) private var appDatabase
|
@Environment(\.appDatabase) private var appDatabase
|
||||||
|
|
||||||
@Query(RibbonRequest()) private var ribbons: [Ribbon]
|
@Query(RibbonRequest()) private var ribbons: [Ribbon]
|
||||||
|
@ -366,145 +351,77 @@ struct ContentView: View {
|
||||||
}
|
}
|
||||||
.offset(x: 20, y: 0)
|
.offset(x: 20, y: 0)
|
||||||
.offset(x: pulledOut.width)
|
.offset(x: pulledOut.width)
|
||||||
.offset(x: mainSwipe.width)
|
.offset(x: mainSwipe.width, y: mainSwipe.height)
|
||||||
.gesture(
|
.gesture(
|
||||||
DragGesture()
|
DragGesture()
|
||||||
.onChanged { value in
|
.onChanged { gesture in
|
||||||
// Calculate the offset
|
let margin = CGFloat(30)
|
||||||
|
let rightSwipeLimit = CGFloat(110)
|
||||||
|
let leftSwipeLimit = CGFloat(-200)
|
||||||
|
|
||||||
var newOffset = value.translation.width
|
print("mao mainSwipe :\(mainSwipe.width)")
|
||||||
if startSwipeState == nil {
|
print(pulledOut.width)
|
||||||
if pulledOut.width == 0 {
|
|
||||||
startSwipeState = .center
|
|
||||||
} else if pulledOut.width < 0 {
|
var swipeWidth = gesture.translation.width
|
||||||
startSwipeState = .left
|
var swipeActual = gesture.translation.width + pulledOut.width
|
||||||
} else {
|
|
||||||
startSwipeState = .right
|
// swiping right
|
||||||
|
if swipeWidth > 0 {
|
||||||
|
if swipeActual > rightSwipeLimit {
|
||||||
|
swipeWidth = rightSwipeLimit + pow(swipeActual - rightSwipeLimit, 0.8)
|
||||||
}
|
}
|
||||||
|
|
||||||
print("start swipe meow: \(startSwipeState)")
|
mainSwipe.width = swipeWidth - pulledOut.width
|
||||||
|
|
||||||
|
// swiping right
|
||||||
|
} else {
|
||||||
|
if swipeActual < leftSwipeLimit {
|
||||||
|
swipeWidth = leftSwipeLimit - pow(-swipeActual + leftSwipeLimit, 0.8)
|
||||||
|
}
|
||||||
|
|
||||||
|
mainSwipe.width = swipeWidth - pulledOut.width
|
||||||
}
|
}
|
||||||
|
|
||||||
if newOffset > 0 {
|
|
||||||
startSwipeDir = .right
|
|
||||||
} else {
|
|
||||||
startSwipeDir = .left
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Apply resistance if out of bounds
|
|
||||||
var maxOffsetRight: CGFloat = 110
|
|
||||||
var maxOffsetLeft: CGFloat = 200
|
|
||||||
|
|
||||||
|
|
||||||
if startSwipeState == .right {
|
|
||||||
if startSwipeDir == .right {
|
|
||||||
maxOffsetRight = .zero
|
|
||||||
maxOffsetLeft = .zero
|
|
||||||
} else if startSwipeDir == .left {
|
|
||||||
maxOffsetRight = CGFloat(110)
|
|
||||||
maxOffsetLeft = CGFloat(-30)
|
|
||||||
}
|
|
||||||
} else if startSwipeState == .left {
|
|
||||||
|
|
||||||
if startSwipeDir == .left {
|
|
||||||
maxOffsetLeft = .zero
|
|
||||||
maxOffsetRight = .zero
|
|
||||||
} else {
|
|
||||||
maxOffsetLeft = CGFloat(200)
|
|
||||||
maxOffsetRight = .zero
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
|
||||||
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
|
// 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 {
|
|
||||||
// dragOffset = margin + mainSwipe.width + pulledOut.width
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
.onEnded { _ in
|
|
||||||
var finalSwipe = CGFloat(0)
|
|
||||||
let swipeLeftFinal = CGFloat(-200)
|
|
||||||
let swipeRightFinal = CGFloat(110)
|
|
||||||
// let margin = CGFloat(30)
|
|
||||||
|
|
||||||
if startSwipeState == .center {
|
|
||||||
if startSwipeDir == .right {
|
|
||||||
finalSwipe = swipeRightFinal
|
|
||||||
} else {
|
|
||||||
finalSwipe = swipeLeftFinal
|
|
||||||
}
|
|
||||||
} else if startSwipeState == .right {
|
|
||||||
finalSwipe = .zero
|
|
||||||
|
|
||||||
if startSwipeDir == .left {
|
|
||||||
finalSwipe = .zero
|
|
||||||
} else {
|
|
||||||
finalSwipe = swipeRightFinal
|
|
||||||
}
|
|
||||||
} else if startSwipeState == .left {
|
|
||||||
|
|
||||||
if startSwipeDir == .left {
|
|
||||||
finalSwipe = swipeLeftFinal
|
|
||||||
} else {
|
|
||||||
finalSwipe = .zero
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
startSwipeState = nil
|
if mainSwipe.width > 0 && pulledOut.width < 0 {
|
||||||
startSwipeDir = nil
|
dragOffset = margin + mainSwipe.width + pulledOut.width
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.onEnded { _ in
|
||||||
|
let pulledOutRight = CGFloat(-200)
|
||||||
|
let pulledOutLeft = CGFloat(110)
|
||||||
|
let margin = CGFloat(30)
|
||||||
|
|
||||||
// var setDragOffset = CGFloat(0)
|
var setPulledOutWith = CGFloat(0)
|
||||||
|
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 {
|
||||||
// setPulledOutWith = CGFloat(0)
|
setPulledOutWith = CGFloat(0)
|
||||||
|
|
||||||
// } else if (mainSwipe.width < 0 && pulledOut.width < 0) ||
|
} else if (mainSwipe.width < 0 && pulledOut.width < 0) ||
|
||||||
// (mainSwipe.width < 0 && pulledOut.width == 0) {
|
(mainSwipe.width < 0 && pulledOut.width == 0) {
|
||||||
// setPulledOutWith = pulledOutRight
|
setPulledOutWith = pulledOutRight
|
||||||
// setDragOffset = margin + setPulledOutWith
|
setDragOffset = margin + setPulledOutWith
|
||||||
// } else if abs(mainSwipe.width + pulledOut.width) > 30 {
|
} else if abs(mainSwipe.width + pulledOut.width) > 30 {
|
||||||
// setPulledOutWith = pulledOutLeft
|
setPulledOutWith = pulledOutLeft
|
||||||
// }
|
}
|
||||||
|
|
||||||
withAnimation(.spring(response: 0.2)) {
|
withAnimation(.spring(response: 0.2)) {
|
||||||
pulledOut.width = finalSwipe
|
pulledOut.width = setPulledOutWith
|
||||||
// dragOffset = setDragOffset
|
dragOffset = setDragOffset
|
||||||
mainSwipe = .zero
|
mainSwipe = .zero
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -513,11 +430,6 @@ struct ContentView: View {
|
||||||
.background(Color(red: 0.1, green: 0.1, blue: 0.1))
|
.background(Color(red: 0.1, green: 0.1, blue: 0.1))
|
||||||
}
|
}
|
||||||
func handleVisibilityChanged2(_: String, change _: VisibilityChange, tracker _: VisibilityTracker<String>) {}
|
func handleVisibilityChanged2(_: String, change _: VisibilityChange, tracker _: VisibilityTracker<String>) {}
|
||||||
|
|
||||||
func rubberBandEffect(_ offset: CGFloat) -> CGFloat {
|
|
||||||
let resistance: CGFloat = 0.55
|
|
||||||
return resistance * pow(abs(offset), 0.7) * (offset < 0 ? -1 : 1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private let itemFormatter: DateFormatter = {
|
private let itemFormatter: DateFormatter = {
|
||||||
|
|
Loading…
Reference in New Issue