undo
saint 2024-05-23 10:51:50 -04:00
parent 3746682941
commit 4615dbd433
2 changed files with 125 additions and 131 deletions

View File

@ -76,138 +76,138 @@ struct SegRow: View {
} }
// struct Pane: View { struct Pane: View {
// @State var paneConnector = PaneConnector() @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 vertSep = CGFloat(20)
// // var handleVisibilityChanged: (String, VisibilityChange, VisibilityTracker<String>) -> Void @Environment(\.appDatabase) private var appDatabase
// var body: some View { // var handleVisibilityChanged: (String, VisibilityChange, VisibilityTracker<String>) -> Void
// ScrollViewReader { proxy in
// VisibilityTrackingScrollView(action: handleVisibilityChanged) { var body: some View {
// LazyVStack { GeometryReader { geometry in
// ForEach(segs) { seg in ScrollViewReader { proxy in
// SegRow(seg: seg, VisibilityTrackingScrollView(action: handleVisibilityChanged) {
// ribbonId: selectedRibbon[0].id!) LazyVStack {
// .id("\(seg.id)") ForEach(segs) { seg in
// .offset(x: -dragOffset) SegRow(seg: seg,
// .padding(EdgeInsets(top: 10, leading: 20, bottom: 40, trailing: 20)) ribbonId: selectedRibbon[0].id!)
// .trackVisibility(id: "\(seg.id)") .id("\(seg.id)")
// } .offset(x: -dragOffset)
// } .padding(EdgeInsets(top: 10, leading: 20, bottom: 40, trailing: 20))
// .background(Color(red: 0.18, green: 0.18, blue: 0.18)) .trackVisibility(id: "\(seg.id)")
}
}
.background(Color(red: 0.18, green: 0.18, blue: 0.18))
}
.onAppear {
goToRibbon(selectedRibbon: selectedRibbon[0],
destRibbon: selectedRibbon[0],
appDatabase: appDatabase,
paneConnector: $paneConnector,
loading: true)
}
.onChange(of: paneConnector.refresh) { _ in
Task {
DispatchQueue.main.async {
let gTracker = paneConnector.visibilityTracker!
Print("scroll Id target: \(paneConnector.scrollId)")
proxy.scrollTo(paneConnector.scrollId, anchor: .top)
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
Print(" scroll id target", paneConnector.scrollId)
Print(" current id ", paneConnector.currentId)
Print(gTracker.sortedViewIDs)
if paneConnector.currentId != paneConnector.scrollId {
Print("NO MATCH")
}
Print(" current offset ", gTracker.visibleViews[paneConnector.scrollId])
var curOffset = gTracker.visibleViews[paneConnector.scrollId]
Print(" stats", gTracker.visibleViews)
if curOffset != nil {
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 \(paneConnector.setScrollOffset)")
// paneConnector = paneConnector.copy() as! PaneConnector
self.refresh.toggle()
} else {
var adjust = (Int(paneConnector.scrollId)! - Int(paneConnector.currentId)!) * 200
Print("adjusting \(adjust)")
paneConnector.setScrollOffset = CGFloat(adjust)
refresh.toggle()
}
}
}
}
}
.introspect(.scrollView, on: .iOS(.v13, .v14, .v15, .v16, .v17)) { scrollView in
Print("introspect")
// Weird hack for reactivity
if self.refresh {
let reactive = self.refresh
}
// if self.paneConnector != nil {
// let reactive = self.paneConnector
// } // }
// .onAppear { if paneConnector.setScrollOffset != nil {
// goToRibbon(selectedRibbon: selectedRibbon[0], DispatchQueue.main.async {
// destRibbon: selectedRibbon[0], scrollView.contentOffset.y = scrollView.contentOffset.y + paneConnector.setScrollOffset!
// scrollId: $scrollId, paneConnector.setScrollOffset = nil
// scrollOffset: $scrollOffset,
// refresh: $refresh,
// showOverlay: $showOverlay,
// appDatabase: appDatabase,
// paneConnector: $paneConnector,
// loading: true)
// }
// .onChange(of: paneConnector.refresh) { _ in
// Task { withAnimation(.easeIn(duration: 0.2)) {
// DispatchQueue.main.async { paneConnector.showOverlay = false
// let gTracker = paneConnector.visibilityTracker! self.refresh.toggle()
}
}
}
// Print("scroll Id target: \(paneConnector.scrollId)") Print("end introspect")
// proxy.scrollTo(paneConnector.scrollId, anchor: .top) }
.listStyle(PlainListStyle())
}
.zIndex(1)
.background(Color(red: 0.2, green: 0.2, blue: 0.2))
.frame(width: geometry.size.width - 50, height: geometry.size.height / 2 - vertSep)
}
}
// DispatchQueue.main.asyncAfter(deadline: .now() + 1) { func handleVisibilityChanged(_: String, change _: VisibilityChange, tracker: VisibilityTracker<String>) {
// Print(" scroll id target", paneConnector.scrollId) // var printRate: Int64 = 10
// Print(" current id ", paneConnector.currentId) // gTracker = tracker
// Print(gTracker.sortedViewIDs) self.paneConnector.visibilityTracker = tracker
// if paneConnector.currentId != paneConnector.scrollId {
// Print("NO MATCH")
// }
// Print(" current offset ", gTracker.visibleViews[paneConnector.scrollId])
// var curOffset = gTracker.visibleViews[paneConnector.scrollId]
// Print(" stats", gTracker.visibleViews)
// if curOffset != nil {
// 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 \(paneConnector.setScrollOffset)")
// // paneConnector = paneConnector.copy() as! PaneConnector
// self.refresh.toggle()
// } else {
// var adjust = (Int(paneConnector.scrollId)! - Int(paneConnector.currentId)!) * 200
// Print("adjusting \(adjust)")
// setScrollOffset = CGFloat(adjust)
// refresh.toggle()
// }
// }
// }
// }
// }
// .introspect(.scrollView, on: .iOS(.v13, .v14, .v15, .v16, .v17)) { scrollView in
// 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 {
// scrollView.contentOffset.y = scrollView.contentOffset.y + paneConnector.setScrollOffset!
// paneConnector.setScrollOffset = nil
// withAnimation(.easeIn(duration: 0.2)) {
// paneConnector.showOverlay = false
// self.refresh.toggle()
// }
// }
// }
// Print("end introspect")
// }
// .listStyle(PlainListStyle())
// }
// .zIndex(1)
// .background(Color(red: 0.2, green: 0.2, blue: 0.2))
// .frame(width: geometry.size.width - 50, height: geometry.size.height / 2 - vertSep)
// }
// func handleVisibilityChanged(_: String, change _: VisibilityChange, tracker: VisibilityTracker<String>) {
// // var printRate: Int64 = 10
// // 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 {
// return return
// } }
// // 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.currentId = tracker.sortedViewIDs[0]
// self.paneConnector.currentOffset = tracker.visibleViews[currentId!]! self.paneConnector.currentOffset = tracker.visibleViews[currentId!]!
// } }
// } }

View File

@ -227,12 +227,6 @@ struct ContentView: View {
@State var paneConnector = PaneConnector() @State var paneConnector = PaneConnector()
// scroll location of the main Pane
// @State var scrollId: String?
// @State var scrollOffset: CGFloat?
// @State var setScrollOffset: CGFloat?
// @State var showOverlay: Bool = false
@State var refresh: Bool = false @State var refresh: Bool = false
@State var vertSep = CGFloat(20) @State var vertSep = CGFloat(20)