More refactor, stil builds
parent
a9b85c90d1
commit
cce075abaa
|
@ -16,7 +16,7 @@ let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "network
|
|||
var currentId: String?
|
||||
var currentOffset: CGFloat?
|
||||
|
||||
var gTracker: VisibilityTracker<String>?
|
||||
//var gTracker: VisibilityTracker<String>?
|
||||
var printCount: Int64 = 0
|
||||
|
||||
var disableDrop = false
|
||||
|
@ -46,35 +46,28 @@ func goToRibbon(selectedRibbon: Ribbon,
|
|||
refresh: Binding<Bool>,
|
||||
showOverlay: Binding<Bool>,
|
||||
appDatabase: AppDatabase,
|
||||
paneConnector: Binding<PaneConnector?>,
|
||||
paneConnector: Binding<PaneConnector>,
|
||||
loading: Bool)
|
||||
{
|
||||
Task {
|
||||
// print("SELECTED RIBBON", selectedRibbon)
|
||||
var scrollOffsetToSave = currentOffset
|
||||
var scrollIdToSave = currentId
|
||||
var scrollOffsetToSave = paneConnector.wrappedValue.currentOffset
|
||||
var scrollIdToSave = paneConnector.wrappedValue.currentId
|
||||
|
||||
var updatedRibbon = selectedRibbon
|
||||
|
||||
if selectedRibbon.id != destRibbon.id! || loading {
|
||||
print("switching ribbons")
|
||||
|
||||
// withAnimation(.spring(response: 0.05)) {
|
||||
// showOverlay.wrappedValue = true
|
||||
showOverlay.wrappedValue = true
|
||||
// }
|
||||
|
||||
if loading {
|
||||
currentId = destRibbon.scrollId
|
||||
// currentOffset = CGFloat(destRibbon.scrollOffset)
|
||||
paneConnector.wrappedValue.currentId = destRibbon.scrollId
|
||||
}
|
||||
|
||||
scrollId.wrappedValue = destRibbon.scrollId
|
||||
// print("setting scroll offset")
|
||||
scrollOffset.wrappedValue = CGFloat(destRibbon.scrollOffset)
|
||||
// print(scrollOffset.wrappedValue)
|
||||
// print("end setting scroll offset")
|
||||
refresh.wrappedValue.toggle()
|
||||
// refresh.wrappedValue.toggle()
|
||||
paneConnector.wrappedValue.refresh.toggle()
|
||||
|
||||
var updateSelectRibbon = SelectedRibbon(id: Int64(1), ribbonId: destRibbon.id!)
|
||||
// print("Saving selected ribbon")
|
||||
|
@ -88,21 +81,16 @@ func goToRibbon(selectedRibbon: Ribbon,
|
|||
|
||||
if !loading {
|
||||
print("not loading")
|
||||
updatedRibbon.scrollOffset = Int(floor(scrollOffsetToSave!))
|
||||
updatedRibbon.scrollId = scrollIdToSave!
|
||||
updatedRibbon.scrollOffset = Int(floor(scrollOffsetToSave))
|
||||
// updatedRibbon.scrollId = scrollIdToSave!
|
||||
updatedRibbon.scrollId = scrollIdToSave
|
||||
|
||||
_ = try await appDatabase.saveRibbon(&updatedRibbon)
|
||||
// print("saved updatedRibbon", updatedRibbon)
|
||||
|
||||
// print("UPDATED")
|
||||
// scrollOffsetToSave = userDefaults.object(forKey: "currentOffset") as? CGFloat
|
||||
// scrollIdToSave = userDefaults.object(forKey: "currentId") as? String
|
||||
} else {
|
||||
print("loading")
|
||||
}
|
||||
|
||||
// print("scrollOffsetToSave: ", scrollOffsetToSave)
|
||||
// print("scrollIdToSave: ", scrollIdToSave)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -120,7 +108,7 @@ struct RibbonCrown: View {
|
|||
@Binding var scrollOffset: CGFloat?
|
||||
@Binding var showOverlay: Bool
|
||||
@Binding var refresh: Bool
|
||||
@Binding var paneConnector: PaneConnector?
|
||||
@Binding var paneConnector: PaneConnector
|
||||
var draggedRibbon: Ribbon?
|
||||
var isDragging: Bool
|
||||
|
||||
|
@ -198,12 +186,18 @@ func makeVerseView(seg: SegDenorm) -> some View {
|
|||
return retView
|
||||
}
|
||||
|
||||
class PaneConnector : NSObject {
|
||||
var scrollId: String
|
||||
var scrollOffset: CGFloat
|
||||
var setScrollOffset: CGFloat
|
||||
class PaneConnector: NSObject {
|
||||
// var scrollId: String
|
||||
// var scrollOffset: CGFloat
|
||||
// var setScrollOffset: CGFloat
|
||||
var showOverlay: Bool = false
|
||||
var refresh: Bool = false
|
||||
var currentId = ""
|
||||
var currentOffset = CGFloat()
|
||||
var visibilityTracker: VisibilityTracker<String>?
|
||||
var scrollId = ""
|
||||
var scrollOffset = CGFloat()
|
||||
var setScrollOffset: CGFloat?
|
||||
}
|
||||
|
||||
struct ContentView: View {
|
||||
|
@ -211,10 +205,9 @@ struct ContentView: View {
|
|||
@State var viewState = CGSize.zero
|
||||
@State var pulledOut = CGSize.zero
|
||||
|
||||
@State var paneConnector = PaneConnector()
|
||||
|
||||
@State var paneConnector: PaneConnector?
|
||||
|
||||
// scroll location of the main fenestra
|
||||
// scroll location of the main Pane
|
||||
@State var scrollId: String?
|
||||
@State var scrollOffset: CGFloat?
|
||||
@State var setScrollOffset: CGFloat?
|
||||
|
@ -290,16 +283,12 @@ struct ContentView: View {
|
|||
VStack {
|
||||
ScrollViewReader { proxy in
|
||||
VisibilityTrackingScrollView(action: handleVisibilityChanged) {
|
||||
// ScrollView {
|
||||
|
||||
LazyVStack {
|
||||
ForEach(segs) { seg in
|
||||
SegRow(seg: seg,
|
||||
ribbonId: selectedRibbon[0].id!)
|
||||
.id("\(seg.id)")
|
||||
.offset(x: -dragOffset)
|
||||
// .offset(x: pulledOut.width)
|
||||
|
||||
.padding(EdgeInsets(top: 10, leading: 20, bottom: 40, trailing: 20))
|
||||
.trackVisibility(id: "\(seg.id)")
|
||||
}
|
||||
|
@ -308,12 +297,6 @@ struct ContentView: View {
|
|||
}
|
||||
|
||||
.onAppear {
|
||||
Print("APPEAR")
|
||||
// Print(selectedRibbon[0])
|
||||
// scrollId = "3"
|
||||
// scrollOffset = 103
|
||||
// refresh.toggle()
|
||||
|
||||
goToRibbon(selectedRibbon: selectedRibbon[0],
|
||||
destRibbon: selectedRibbon[0],
|
||||
scrollId: $scrollId,
|
||||
|
@ -324,38 +307,29 @@ struct ContentView: View {
|
|||
paneConnector: $paneConnector,
|
||||
loading: true)
|
||||
}
|
||||
.onChange(of: refresh) { _ in
|
||||
// if let target = target {
|
||||
// gTracker!.visibleViews["123123"] = CGFloat(100)
|
||||
// Print("ON CHANGE", gTracker!.visibleViews)
|
||||
// Print("removing", gTracker!.visibleViews.removeAll())
|
||||
.onChange(of: paneConnector.refresh) { _ in
|
||||
|
||||
Task {
|
||||
DispatchQueue.main.async {
|
||||
let gTracker = paneConnector.visibilityTracker!
|
||||
|
||||
Print("scroll Id target: \(scrollId)")
|
||||
proxy.scrollTo(scrollId!, anchor: .top)
|
||||
// proxy.scrollTo(String(Int(scrollId!)! + 1))
|
||||
// currentId = scrollId!
|
||||
// if (currentId != scrollId!) {
|
||||
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
|
||||
Print(" scroll id target", scrollId)
|
||||
Print(" current id ", currentId)
|
||||
Print(gTracker!.sortedViewIDs)
|
||||
Print(gTracker.sortedViewIDs)
|
||||
if currentId! != scrollId! {
|
||||
Print("NO MATCH")
|
||||
}
|
||||
|
||||
// Print(" scroll offset target", scrollOffset)
|
||||
Print(" current offset ", gTracker!.visibleViews[scrollId!])
|
||||
var curOffset = gTracker!.visibleViews[scrollId!]
|
||||
Print(" stats", gTracker!.visibleViews)
|
||||
// // setScrollOffset = CGFloat(Int(currentOffset!) * -1 + Int(scrollOffset!))
|
||||
Print(" current offset ", gTracker.visibleViews[scrollId!])
|
||||
var curOffset = gTracker.visibleViews[scrollId!]
|
||||
Print(" stats", gTracker.visibleViews)
|
||||
if curOffset != nil {
|
||||
setScrollOffset = CGFloat(Int(scrollOffset!) - Int(curOffset!))
|
||||
Print("applying scroll offset \(setScrollOffset)")
|
||||
// // setScrollOffset = CGFloat(Int(scrollOffset!))
|
||||
// Print("setting scroll offset", setScrollOffset)
|
||||
refresh2.toggle()
|
||||
} else {
|
||||
var adjust = (Int(scrollId!)! - Int(currentId!)!) * 200
|
||||
|
@ -364,13 +338,6 @@ struct ContentView: View {
|
|||
setScrollOffset = CGFloat(adjust)
|
||||
refresh.toggle()
|
||||
}
|
||||
// // currentId = scrollId!
|
||||
|
||||
// DispatchQueue.main.async {
|
||||
|
||||
// currentOffset = scrollOffset!
|
||||
// currentId = scrollId!
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -506,7 +473,9 @@ struct ContentView: View {
|
|||
|
||||
func handleVisibilityChanged(_: String, change _: VisibilityChange, tracker: VisibilityTracker<String>) {
|
||||
// var printRate: Int64 = 10
|
||||
gTracker = tracker
|
||||
// gTracker = tracker
|
||||
self.paneConnector.visibilityTracker = tracker
|
||||
|
||||
|
||||
let visibleViews2 = Array(tracker.visibleViews.keys)
|
||||
if visibleViews2.count == 0 {
|
||||
|
@ -516,6 +485,9 @@ struct ContentView: View {
|
|||
// currentId = tracker.sortedViewIDs[tracker.sortedViewIDs.count - 1]
|
||||
currentId = tracker.sortedViewIDs[0]
|
||||
currentOffset = tracker.visibleViews[currentId!]!
|
||||
|
||||
self.paneConnector.currentId = tracker.sortedViewIDs[0]
|
||||
self.paneConnector.currentOffset = tracker.visibleViews[currentId!]!
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue