undo
saint 2024-05-23 10:46:13 -04:00
parent 1275ad4f96
commit 3746682941
2 changed files with 109 additions and 92 deletions

View File

@ -76,14 +76,16 @@ struct SegRow: View {
} }
// struct Fenestra: View { // struct Pane: View {
// @State var paneConnector = PaneConnector()
// @State var segs: [SegDenorm] // @State var segs: [SegDenorm]
// @State var selectedRibbon: [Ribbon] // @State var selectedRibbon: [Ribbon]
// @State var dragOffset = CGFloat() // @State var dragOffset = CGFloat()
// @State var refresh: Bool = false // @State var refresh: Bool = false
// @State var refresh2: Bool = false
// // var handleVisibilityChanged: (String, VisibilityChange, VisibilityTracker<String>) -> Void // // var handleVisibilityChanged: (String, VisibilityChange, VisibilityTracker<String>) -> Void
@ -104,7 +106,6 @@ struct SegRow: View {
// } // }
// .onAppear { // .onAppear {
// Print("APPEAR")
// goToRibbon(selectedRibbon: selectedRibbon[0], // goToRibbon(selectedRibbon: selectedRibbon[0],
// destRibbon: selectedRibbon[0], // destRibbon: selectedRibbon[0],
// scrollId: $scrollId, // scrollId: $scrollId,
@ -112,32 +113,42 @@ struct SegRow: View {
// refresh: $refresh, // refresh: $refresh,
// showOverlay: $showOverlay, // showOverlay: $showOverlay,
// appDatabase: appDatabase, // appDatabase: appDatabase,
// paneConnector: $paneConnector,
// loading: true) // loading: true)
// } // }
// .onChange(of: refresh) { _ in // .onChange(of: paneConnector.refresh) { _ in
// Task { // Task {
// DispatchQueue.main.async { // DispatchQueue.main.async {
// Print("scroll Id target: \(scrollId)") // let gTracker = paneConnector.visibilityTracker!
// proxy.scrollTo(scrollId!, anchor: .top)
// Print("scroll Id target: \(paneConnector.scrollId)")
// proxy.scrollTo(paneConnector.scrollId, anchor: .top)
// DispatchQueue.main.asyncAfter(deadline: .now() + 1) { // DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
// Print(" scroll id target", scrollId) // Print(" scroll id target", paneConnector.scrollId)
// Print(" current id ", currentId) // Print(" current id ", paneConnector.currentId)
// Print(gTracker!.sortedViewIDs) // Print(gTracker.sortedViewIDs)
// if currentId! != scrollId! { // if paneConnector.currentId != paneConnector.scrollId {
// Print("NO MATCH") // Print("NO MATCH")
// } // }
// Print(" current offset ", gTracker!.visibleViews[scrollId!]) // Print(" current offset ", gTracker.visibleViews[paneConnector.scrollId])
// var curOffset = gTracker!.visibleViews[scrollId!] // var curOffset = gTracker.visibleViews[paneConnector.scrollId]
// Print(" stats", gTracker!.visibleViews) // Print(" stats", gTracker.visibleViews)
// if curOffset != nil { // if curOffset != nil {
// setScrollOffset = CGFloat(Int(scrollOffset!) - Int(curOffset!)) // paneConnector.setScrollOffset = CGFloat(Int(paneConnector.scrollOffset) - Int(curOffset!))
// // setScrollOffset = CGFloat(Int(paneConnector.scrollOffset) - Int(curOffset!))
// // setScrollOffset = CGFloat(Int(paneConnector.scrollOffset) - Int(curOffset!))
// Print("applying scroll offset \(setScrollOffset)") // Print("applying scroll offset \(setScrollOffset)")
// refresh2.toggle() // Print("applying scroll offset \(paneConnector.setScrollOffset)")
// // paneConnector = paneConnector.copy() as! PaneConnector
// self.refresh.toggle()
// } else { // } else {
// var adjust = (Int(scrollId!)! - Int(currentId!)!) * 200 // var adjust = (Int(paneConnector.scrollId)! - Int(paneConnector.currentId)!) * 200
// Print("adjusting \(adjust)") // Print("adjusting \(adjust)")
// setScrollOffset = CGFloat(adjust) // setScrollOffset = CGFloat(adjust)
// refresh.toggle() // refresh.toggle()
// } // }
@ -145,62 +156,44 @@ struct SegRow: View {
// } // }
// } // }
// } // }
// .introspect(.scrollView, on: .iOS(.v13, .v14, .v15, .v16, .v17)) { scrollView in Print("introspect") // .introspect(.scrollView, on: .iOS(.v13, .v14, .v15, .v16, .v17)) { scrollView in
// if setScrollOffset != nil { // Print("introspect")
// // Weird hack for reactivity
// if self.refresh {
// let reactive = self.refresh
// }
// // if self.paneConnector != nil {
// // let reactive = self.paneConnector
// // }
// if paneConnector.setScrollOffset != nil {
// DispatchQueue.main.async { // DispatchQueue.main.async {
// scrollView.contentOffset.y = scrollView.contentOffset.y + setScrollOffset! // scrollView.contentOffset.y = scrollView.contentOffset.y + paneConnector.setScrollOffset!
// setScrollOffset = nil // paneConnector.setScrollOffset = nil
// withAnimation {
// showOverlay = false // withAnimation(.easeIn(duration: 0.2)) {
// paneConnector.showOverlay = false
// self.refresh.toggle()
// } // }
// } // }
// } // }
// Print("end introspect")
// } // }
// .listStyle(PlainListStyle()) // .listStyle(PlainListStyle())
// } // }
// .zIndex(1) // .zIndex(1)
// .background(Color(red: 0.2, green: 0.2, blue: 0.2)) // .background(Color(red: 0.2, green: 0.2, blue: 0.2))
// .frame(width: geometry.size.width - 50, height: geometry.size.height / 2 - vertSep) // .frame(width: geometry.size.width - 50, height: geometry.size.height / 2 - vertSep)
// .offset(x: 30, y: 0)
// .offset(x: pulledOut.width)
// .offset(x: viewState.width, y: viewState.height)
// .gesture(
// DragGesture()
// .onChanged { gesture in
// if endedDrag {
// endedDrag = false
// scrollOffset = readOffset.y - 20
// }
// Print(viewState.width)
// if abs(gesture.translation.width) > 20 {
// viewState.width = gesture.translation.width
// if gesture.translation.width < -50, pulledOut.width == CGFloat(0) {
// dragOffset = gesture.translation.width + 50
// }
// }
// }
// .onEnded { _ in
// endedDrag = true
// var pulledOutWidth = CGFloat(0)
// if viewState.width < 0 {
// pulledOutWidth = CGFloat(0)
// } else if abs(viewState.width + pulledOut.width) > 30 {
// pulledOutWidth = CGFloat(200)
// }
// withAnimation(.spring(response: 0.2)) {
// pulledOut.width = pulledOutWidth
// viewState = .zero
// dragOffset = .zero
// }
// }
// )
// } // }
// func handleVisibilityChanged(_: String, change _: VisibilityChange, tracker: VisibilityTracker<String>) { // func handleVisibilityChanged(_: String, change _: VisibilityChange, tracker: VisibilityTracker<String>) {
// // var printRate: Int64 = 10 // // var printRate: Int64 = 10
// gTracker = tracker // // gTracker = tracker
// self.paneConnector.visibilityTracker = tracker
// let visibleViews2 = Array(tracker.visibleViews.keys) // let visibleViews2 = Array(tracker.visibleViews.keys)
// if visibleViews2.count == 0 { // if visibleViews2.count == 0 {
@ -210,7 +203,11 @@ struct SegRow: View {
// // currentId = tracker.sortedViewIDs[tracker.sortedViewIDs.count - 1] // // currentId = tracker.sortedViewIDs[tracker.sortedViewIDs.count - 1]
// currentId = tracker.sortedViewIDs[0] // currentId = tracker.sortedViewIDs[0]
// currentOffset = tracker.visibleViews[currentId!]! // currentOffset = tracker.visibleViews[currentId!]!
// self.paneConnector.currentId = tracker.sortedViewIDs[0]
// self.paneConnector.currentOffset = tracker.visibleViews[currentId!]!
// } // }
// } // }

View File

@ -41,10 +41,6 @@ public extension UserDefaults {
func goToRibbon(selectedRibbon: Ribbon, func goToRibbon(selectedRibbon: Ribbon,
destRibbon: Ribbon, destRibbon: Ribbon,
scrollId: Binding<String?>,
scrollOffset: Binding<CGFloat?>,
refresh: Binding<Bool>,
showOverlay: Binding<Bool>,
appDatabase: AppDatabase, appDatabase: AppDatabase,
paneConnector: Binding<PaneConnector>, paneConnector: Binding<PaneConnector>,
loading: Bool) loading: Bool)
@ -59,7 +55,6 @@ func goToRibbon(selectedRibbon: Ribbon,
print("switching ribbons") print("switching ribbons")
paneConnector.wrappedValue.showOverlay = true paneConnector.wrappedValue.showOverlay = true
showOverlay.wrappedValue = true
if loading { if loading {
paneConnector.wrappedValue.currentId = destRibbon.scrollId paneConnector.wrappedValue.currentId = destRibbon.scrollId
@ -102,10 +97,6 @@ extension View {
struct RibbonCrown: View { struct RibbonCrown: View {
var ribbon: Ribbon var ribbon: Ribbon
@Binding var scrollId: String?
@Binding var scrollOffset: CGFloat?
@Binding var showOverlay: Bool
@Binding var refresh: Bool
@Binding var paneConnector: PaneConnector @Binding var paneConnector: PaneConnector
var draggedRibbon: Ribbon? var draggedRibbon: Ribbon?
var isDragging: Bool var isDragging: Bool
@ -147,10 +138,6 @@ struct RibbonCrown: View {
Task { Task {
goToRibbon(selectedRibbon: sr[0], goToRibbon(selectedRibbon: sr[0],
destRibbon: ribbon, destRibbon: ribbon,
scrollId: $scrollId,
scrollOffset: $scrollOffset,
refresh: $refresh,
showOverlay: $showOverlay,
appDatabase: appDatabase, appDatabase: appDatabase,
paneConnector: $paneConnector, paneConnector: $paneConnector,
loading: false) loading: false)
@ -184,7 +171,7 @@ func makeVerseView(seg: SegDenorm) -> some View {
return retView return retView
} }
class PaneConnector: NSObject { class PaneConnector: NSObject, NSCopying {
// var scrollId: String // var scrollId: String
// var scrollOffset: CGFloat // var scrollOffset: CGFloat
// var setScrollOffset: CGFloat // var setScrollOffset: CGFloat
@ -196,7 +183,42 @@ class PaneConnector: NSObject {
var scrollId = "" var scrollId = ""
var scrollOffset = CGFloat() var scrollOffset = CGFloat()
var setScrollOffset: CGFloat? var setScrollOffset: CGFloat?
required override init() {}
// convenience init(showOverlay _: Bool, refresh _: Bool, currentId _: String,
// currentOffset _: CGFloat, visibilityTracker _: VisibilityTracker<String>?, scrollId _: String,
// scrollOffset _: CGFloat, setScrollOffset _: CGFloat) {
// self.init()
// self.showOverlay = showOverlay
// self.refresh = refresh
// self.currentId = currentId
// self.currentOffset = currentOffset
// self.visibilityTracker = visibilityTracker
// self.scrollId = scrollId
// self.scrollOffset = scrollOffset
// self.setScrollOffset = setScrollOffset
// }
// func copy(with _: NSZone? = nil) -> Any {
// let item = PaneConnector(
// return item
// }
func copy(with _: NSZone? = nil) -> Any {
let item = type(of: self).init()
item.showOverlay = showOverlay
item.refresh = refresh
item.currentId = currentId
item.currentOffset = currentOffset
item.visibilityTracker = visibilityTracker
item.scrollId = scrollId
item.setScrollOffset = setScrollOffset
return item
} }
}
struct ContentView: View { struct ContentView: View {
// this is for the whole view swiping // this is for the whole view swiping
@ -206,29 +228,28 @@ struct ContentView: View {
@State var paneConnector = PaneConnector() @State var paneConnector = PaneConnector()
// scroll location of the main Pane // scroll location of the main Pane
@State var scrollId: String? // @State var scrollId: String?
@State var scrollOffset: CGFloat? // @State var scrollOffset: CGFloat?
@State var setScrollOffset: CGFloat? // @State var setScrollOffset: CGFloat?
@State var foocat = "meow" // @State var showOverlay: Bool = false
@State var showOverlay: Bool = false
@State var refresh: Bool = false @State var refresh: Bool = false
@State var refresh3: Bool = false
@State var vertSep = CGFloat(20) @State var vertSep = CGFloat(20)
@State var endedDrag = true @State var endedDrag = true
@State var readOffset = CGPoint() @State var readOffset = CGPoint()
@State var dragOffset = CGFloat() @State var dragOffset = CGFloat()
@State var refresh2: Bool = false
@State var draggedRibbon: Ribbon? @State var draggedRibbon: Ribbon?
@State var isDragging = false @State var isDragging = false
@Environment(\.appDatabase) private var appDatabase @Environment(\.appDatabase) private var appDatabase
@Query(SegDenormRequest(book: "bible.mark")) private var segs: [SegDenorm] @Query(SegDenormRequest(book: "bible.mark")) private var segs: [SegDenorm]
@Query(RibbonRequest()) private var ribbons: [Ribbon] @Query(RibbonRequest()) private var ribbons: [Ribbon]
@Query<SelectedRibbonRequest> var selectedRibbon: [Ribbon] @Query<SelectedRibbonRequest> var selectedRibbon: [Ribbon]
@ -251,10 +272,6 @@ struct ContentView: View {
VStack { VStack {
ForEach(ribbons) { ribbon in ForEach(ribbons) { ribbon in
RibbonCrown(ribbon: ribbon, RibbonCrown(ribbon: ribbon,
scrollId: $scrollId,
scrollOffset: $scrollOffset,
showOverlay: $showOverlay,
refresh: $refresh,
paneConnector: $paneConnector, paneConnector: $paneConnector,
draggedRibbon: draggedRibbon, draggedRibbon: draggedRibbon,
isDragging: isDragging) isDragging: isDragging)
@ -281,6 +298,7 @@ struct ContentView: View {
.frame(alignment: .topLeading) .frame(alignment: .topLeading)
VStack { VStack {
// Top pane
ScrollViewReader { proxy in ScrollViewReader { proxy in
VisibilityTrackingScrollView(action: handleVisibilityChanged) { VisibilityTrackingScrollView(action: handleVisibilityChanged) {
LazyVStack { LazyVStack {
@ -299,10 +317,6 @@ struct ContentView: View {
.onAppear { .onAppear {
goToRibbon(selectedRibbon: selectedRibbon[0], goToRibbon(selectedRibbon: selectedRibbon[0],
destRibbon: selectedRibbon[0], destRibbon: selectedRibbon[0],
scrollId: $scrollId,
scrollOffset: $scrollOffset,
refresh: $refresh,
showOverlay: $showOverlay,
appDatabase: appDatabase, appDatabase: appDatabase,
paneConnector: $paneConnector, paneConnector: $paneConnector,
loading: true) loading: true)
@ -331,15 +345,15 @@ struct ContentView: View {
paneConnector.setScrollOffset = CGFloat(Int(paneConnector.scrollOffset) - Int(curOffset!)) paneConnector.setScrollOffset = CGFloat(Int(paneConnector.scrollOffset) - Int(curOffset!))
// setScrollOffset = CGFloat(Int(paneConnector.scrollOffset) - Int(curOffset!)) // setScrollOffset = CGFloat(Int(paneConnector.scrollOffset) - Int(curOffset!))
// setScrollOffset = CGFloat(Int(paneConnector.scrollOffset) - Int(curOffset!)) // setScrollOffset = CGFloat(Int(paneConnector.scrollOffset) - Int(curOffset!))
Print("applying scroll offset \(setScrollOffset)")
Print("applying scroll offset \(paneConnector.setScrollOffset)") Print("applying scroll offset \(paneConnector.setScrollOffset)")
Print("applying scroll offset2 \(foocat)")
// paneConnector = paneConnector.copy() as! PaneConnector
self.refresh.toggle() self.refresh.toggle()
} else { } else {
var adjust = (Int(paneConnector.scrollId)! - Int(paneConnector.currentId)!) * 200 var adjust = (Int(paneConnector.scrollId)! - Int(paneConnector.currentId)!) * 200
Print("adjusting \(adjust)") Print("adjusting \(adjust)")
setScrollOffset = CGFloat(adjust) paneConnector.setScrollOffset = CGFloat(adjust)
refresh.toggle() refresh.toggle()
} }
} }
@ -354,6 +368,10 @@ struct ContentView: View {
let reactive = self.refresh let reactive = self.refresh
} }
// if self.paneConnector != nil {
// let reactive = self.paneConnector
// }
if paneConnector.setScrollOffset != nil { if paneConnector.setScrollOffset != nil {
DispatchQueue.main.async { DispatchQueue.main.async {
scrollView.contentOffset.y = scrollView.contentOffset.y + paneConnector.setScrollOffset! scrollView.contentOffset.y = scrollView.contentOffset.y + paneConnector.setScrollOffset!
@ -374,6 +392,8 @@ struct ContentView: View {
.background(Color(red: 0.2, green: 0.2, blue: 0.2)) .background(Color(red: 0.2, green: 0.2, blue: 0.2))
.frame(width: geometry.size.width - 50, height: geometry.size.height / 2 - vertSep) .frame(width: geometry.size.width - 50, height: geometry.size.height / 2 - vertSep)
//////
Text("separator").foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00))) Text("separator").foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00)))
.gesture( .gesture(
DragGesture() DragGesture()
@ -598,8 +618,8 @@ struct ContentView_Previews: PreviewProvider {
} }
} }
//@discardableResult
extension View { extension View {
@discardableResult
func Print(_ vars: Any...) -> some View { func Print(_ vars: Any...) -> some View {
for v in vars { for v in vars {
print(v) print(v)