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