Compare commits

..

No commits in common. "b8764b5577870617e6753f34f41331d8f502c1ae" and "09ffa5f8e25af7f1b77c3bfaeefbb0d86157d7ec" have entirely different histories.

2 changed files with 108 additions and 166 deletions

View File

@ -101,10 +101,8 @@ class ShowTitle: NSObject, ObservableObject {
@Published var chapVisible = false
}
struct Pane: View {
@ObservedObject var paneConnector: PaneConnector
@ObservedObject var scrollDelegate: ScrollDelegate
@StateObject var showTitle = ShowTitle()
// @State var chapVisible = false
@ -204,11 +202,12 @@ struct Pane: View {
let reactive = self.refresh
}
scrollView.canCancelContentTouches = false
scrollView.delegate = scrollDelegate
// if self.paneConnector != nil {
// let reactive = self.paneConnector
// }
DispatchQueue.main.async {
if paneConnector.setScrollOffset != nil {
DispatchQueue.main.async {
if paneConnector.setScrollOffset != nil {
scrollView.contentOffset.y = scrollView.contentOffset.y + paneConnector.setScrollOffset!
paneConnector.setScrollOffset = nil

View File

@ -215,7 +215,6 @@ func makeVerseView(seg: SegDenorm) -> some View {
}
class PaneConnector: NSObject, ObservableObject {
var showOverlay: Bool = false
@Published var refresh: Bool = false
@Published var vertSep = CGFloat(20)
@ -226,27 +225,9 @@ class PaneConnector: NSObject, ObservableObject {
@Published var scrollOffset = CGFloat()
@Published var hasMoved = false
var setScrollOffset: CGFloat?
@Published var disableScroll = false
}
class ScrollDelegate: NSObject, ObservableObject, UIScrollViewDelegate {
@Published var isScrolling = false
func scrollViewWillBeginDragging(_: UIScrollView) {
print("pop started scroll")
isScrolling.toggle()
}
func scrollViewDidEndDragging(_: UIScrollView, willDecelerate _: Bool) {
print("pop ended scroll")
isScrolling.toggle()
}
}
struct ContentView: View {
// this is for the whole view swiping
@State var mainSwipe = CGSize.zero
@ -255,7 +236,6 @@ struct ContentView: View {
@State var selection = 0
@StateObject var paneConnector = PaneConnector()
@StateObject var scrollDelegate = ScrollDelegate()
@State var refresh: Bool = false
@ -268,8 +248,6 @@ struct ContentView: View {
@State var dragOffset = CGFloat(0)
@GestureState var dragGestureActive = CGSize.zero
enum SwipeStartState {
case center
case right
@ -293,13 +271,10 @@ struct ContentView: View {
init() {
UITableView.appearance().backgroundColor = UIColor(Color(red: 0.2, green: 0.2, blue: 0.2))
_selectedRibbon = Query(SelectedRibbonRequest())
}
var body: some View {
var fontSize = CGFloat(15)
var scale = 0.65
var height = CGFloat(50)
@ -352,7 +327,6 @@ struct ContentView: View {
// Top pane
Pane(paneConnector: paneConnector,
scrollDelegate: scrollDelegate,
selectedRibbon: selectedRibbon,
width: geometry.size.width - 15,
height: geometry.size.height + 20,
@ -366,7 +340,7 @@ struct ContentView: View {
// .onChanged { gesture in
// paneConnector.vertSep = paneConnector.vertSep - gesture.translation.height
// }
//
// )
// // Bottom pane
// ScrollViewReader { _ in
@ -398,14 +372,9 @@ struct ContentView: View {
.offset(x: 20, y: 0)
.offset(x: pulledOut.width)
.offset(x: mainSwipe.width)
.highPriorityGesture(
DragGesture(minimumDistance: 20)
.updating($dragGestureActive) { value, state, _ in
print("pop here")
state = value.translation
}
.gesture(
DragGesture()
.onChanged { value in
print("pop changed")
// Calculate the offset
let margin = CGFloat(30)
@ -423,29 +392,50 @@ struct ContentView: View {
print("start swipe meow: \(startSwipeState)")
}
if newOffset > 0 {
startSwipeDir = .right
} else {
startSwipeDir = .left
}
if newOffset > 0 {
startSwipeDir = .right
} else {
startSwipeDir = .left
}
// Apply resistance if out of bounds
let maxRight: CGFloat = 140
let finalRight: CGFloat = 110
let rightDiff = maxRight - finalRight
var maxOffsetLeft: CGFloat = -200
var maxOffsetRight: CGFloat = 110
var maxOffsetLeft: CGFloat = 200
if newOffset > maxRight , pulledOut.width == 0 {
// newOffset = maxRight + rubberBandEffect(newOffset)
newOffset = maxRight + rubberBandEffect(newOffset - maxRight)
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 if startSwipeDir == .right {
maxOffsetLeft = CGFloat(200)
maxOffsetRight = CGFloat(10)
}
}
if newOffset > rightDiff, pulledOut.width > 0 {
newOffset = rightDiff + rubberBandEffect(newOffset - rightDiff)
}
if newOffset + pulledOut.width < -maxOffsetLeft {
if startSwipeState == .right && startSwipeDir == .left {
newOffset = -maxOffsetLeft + rubberBandEffect(newOffset + maxOffsetLeft) - pulledOut.width
} else {
newOffset = -maxOffsetLeft + rubberBandEffect(newOffset + maxOffsetLeft)
}
if newOffset < maxOffsetLeft, pulledOut.width == 0 {
newOffset = maxOffsetLeft + rubberBandEffect(newOffset)
} else if newOffset + pulledOut.width > maxOffsetRight {
if startSwipeState == .left, startSwipeDir == .right {
newOffset = maxOffsetRight + rubberBandEffect(newOffset - maxOffsetRight) - pulledOut.width
} else {
newOffset = maxOffsetRight + rubberBandEffect(newOffset - maxOffsetRight)
}
}
self.mainSwipe.width = newOffset
@ -453,130 +443,83 @@ struct ContentView: View {
// dragOffset is what is used to make the text be readable
// 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 {
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
}
}
.onEnded { _ in
onDragEnded()
var finalSwipe = CGFloat(0)
let swipeLeftFinal = CGFloat(-200)
let swipeRightFinal = CGFloat(110)
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
if startSwipeDir == .left {
finalSwipe = .zero
} else {
finalSwipe = swipeRightFinal
}
} else if startSwipeState == .left {
if startSwipeDir == .left {
finalSwipe = swipeLeftFinal
setDragOffset = margin + swipeLeftFinal
} else {
finalSwipe = .zero
}
}
startSwipeState = nil
startSwipeDir = nil
print("foo")
// if mainSwipe.width < 0 && pulledOut.width > 0 {
// setPulledOutWith = CGFloat(0)
// } else if mainSwipe.width > 0 && pulledOut.width < 0 {
// setPulledOutWith = CGFloat(0)
// } else if (mainSwipe.width < 0 && pulledOut.width < 0) ||
// (mainSwipe.width < 0 && pulledOut.width == 0) {
// setPulledOutWith = pulledOutRight
// setDragOffset = margin + setPulledOutWith
// } else if abs(mainSwipe.width + pulledOut.width) > 30 {
// setPulledOutWith = pulledOutLeft
// }
withAnimation(.spring(response: 0.2)) {
pulledOut.width = finalSwipe
dragOffset = setDragOffset
mainSwipe = .zero
}
}
)
.onChange(of: scrollDelegate.isScrolling) { value in
print ("pop reset change")
// if scrollDelegate.isScrolling == true {
Task {
mainSwipe.width = 0
}
// }
}
)
}
}
.background(Color(red: 0.1, green: 0.1, blue: 0.1))
}
func onDragEnded() {
print("pop ended")
paneConnector.disableScroll = false
var finalSwipe = CGFloat(0)
let swipeLeftFinal = CGFloat(-200)
let swipeRightFinal = CGFloat(110)
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
if startSwipeDir == .left {
finalSwipe = .zero
} else {
finalSwipe = swipeRightFinal
}
} else if startSwipeState == .left {
if startSwipeDir == .left {
finalSwipe = swipeLeftFinal
setDragOffset = margin + swipeLeftFinal
} else {
finalSwipe = .zero
}
}
startSwipeState = nil
startSwipeDir = nil
print("foo")
// if mainSwipe.width < 0 && pulledOut.width > 0 {
// setPulledOutWith = CGFloat(0)
// } else if mainSwipe.width > 0 && pulledOut.width < 0 {
// setPulledOutWith = CGFloat(0)
// } else if (mainSwipe.width < 0 && pulledOut.width < 0) ||
// (mainSwipe.width < 0 && pulledOut.width == 0) {
// setPulledOutWith = pulledOutRight
// setDragOffset = margin + setPulledOutWith
// } else if abs(mainSwipe.width + pulledOut.width) > 30 {
// setPulledOutWith = pulledOutLeft
// }
withAnimation(.spring(response: 0.2)) {
pulledOut.width = finalSwipe
dragOffset = setDragOffset
mainSwipe = .zero
}
}
// let hackyPinch = MagnificationGesture(minimumScaleDelta: 0.0)
// .onChanged({ delta in
// onDragEnded()
// })
// .onEnded({ delta in
// onDragEnded()
// })
// let hackyRotation = RotationGesture(minimumAngleDelta: Angle(degrees: 0.0))
// .onChanged({ delta in
// onDragEnded()
// })
// .onEnded({ delta in
// onDragEnded()
// })
// let hackyPress = LongPressGesture(minimumDuration: 0.0, maximumDistance: 0.0)
// .onChanged({ _ in
// onDragEnded()
// })
// .onEnded({ delta in
// onDragEnded()
// })
func handleVisibilityChanged2(_: String, change _: VisibilityChange, tracker _: VisibilityTracker<String>) {}
func rubberBandEffect(_ offset: CGFloat) -> CGFloat {
let resistance: CGFloat = 0.05
return 6 * log(offset + 1)
// return resistance * pow(abs(offset), 1) * (offset < 0 ? -1 : 1)
}
private func dragCancelled() {
print("pop dragCancelled")
mainSwipe = .zero
let resistance: CGFloat = 0.55
return resistance * pow(abs(offset), 0.7) * (offset < 0 ? -1 : 1)
}
}