diff --git a/gloss/ContentView.swift b/gloss/ContentView.swift index fcb6e16..51fe3b9 100644 --- a/gloss/ContentView.swift +++ b/gloss/ContentView.swift @@ -376,6 +376,7 @@ struct ContentView: View { .gesture( DragGesture() .onChanged { gesture in + let margin = CGFloat(50) print("mao viewState :\(viewState.width)") print(pulledOut.width) @@ -385,16 +386,20 @@ struct ContentView: View { // if gesture.translation.width < -50, pulledOut.width == CGFloat(0) { // } } - if viewState.width < -50 { - dragOffset = CGFloat(50) + viewState.width + pulledOut.width + if viewState.width < -50 && pulledOut.width <= 0 { + dragOffset = margin + viewState.width + pulledOut.width } - if viewState.width > 0 { - dragOffset = CGFloat(50) + viewState.width + pulledOut.width + if viewState.width > 0 && pulledOut.width != 0 { + dragOffset = margin + viewState.width + pulledOut.width } } .onEnded { _ in + let pulledOutRight = CGFloat(-300) + let pulledOutLeft = CGFloat(200) + let margin = CGFloat(50) + var setPulledOutWith = CGFloat(0) var setDragOffset = CGFloat(0) if viewState.width < 0 && pulledOut.width > 0 { @@ -402,18 +407,19 @@ struct ContentView: View { } else if viewState.width > 0 && pulledOut.width < 0 { setPulledOutWith = CGFloat(0) } else if viewState.width < 0 && pulledOut.width == 0 { - setPulledOutWith = CGFloat(-300) + setPulledOutWith = pulledOutRight + setDragOffset = margin + setPulledOutWith } else if abs(viewState.width + pulledOut.width) > 30 { - setPulledOutWith = CGFloat(200) + setPulledOutWith = pulledOutLeft } - if setPulledOutWith < 0 { - setDragOffset = CGFloat(50) + setPulledOutWith - } else if setPulledOutWith > 0 { - setDragOffset = setPulledOutWith - } else { - setDragOffset = .zero - } + // if setPulledOutWith < 0 { + // setDragOffset = CGFloat(50) + setPulledOutWith + // } else if setPulledOutWith > 0 { + // setDragOffset = setPulledOutWith + // } else { + // setDragOffset = .zero + // } print("mao setPulledOutWith \(setPulledOutWith)") withAnimation(.spring(response: 0.2)) {