okay now it seems to work with delay
parent
25d7d9b188
commit
3a456cb457
|
@ -62,7 +62,8 @@ public class VisibilityTracker<ID: Hashable>: ObservableObject {
|
|||
|
||||
visibleViews[id] = -1 * (bounds.origin.y - containerBounds.origin.y)
|
||||
// if (abs(visibleViews[id]! ) > 500 || visibleViews[id]! < 0) {
|
||||
if (((id.hashValue) != "1".hashValue && visibleViews[id]! < 0) ||
|
||||
// if (((id.hashValue) != "1".hashValue && visibleViews[id]! < 0) ||
|
||||
if (
|
||||
|
||||
bounds.width == 0 || bounds.height == 0
|
||||
|| bounds.origin.x == 0 || bounds.origin.y == 0
|
||||
|
@ -94,7 +95,8 @@ public class VisibilityTracker<ID: Hashable>: ObservableObject {
|
|||
}
|
||||
|
||||
func sortViews() {
|
||||
let sortedPairs = visibleViews.sorted(by: { Int($0.1) < Int($1.1) })
|
||||
var sortedPairs = visibleViews.sorted(by: { Int($0.1) < Int($1.1) })
|
||||
// let sortedPairs = visibleViews.sorted(by: { Int($0.1) < Int($1.1) })
|
||||
// let sortedPairs = visibleViews.sorted(by: { $0 < $1 })
|
||||
sortedViewIDs = sortedPairs.map { $0.0 }
|
||||
}
|
||||
|
|
Binary file not shown.
|
@ -7,17 +7,81 @@
|
|||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "1C2BE985-4558-4ECC-A9BA-0620C612A996"
|
||||
uuid = "15F59F9C-3FC1-4D0F-B85D-E6FBE78FA1B7"
|
||||
shouldBeEnabled = "Yes"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "gloss/ContentView.swift"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "121"
|
||||
endingLineNumber = "121"
|
||||
landmarkName = "SwitchButton"
|
||||
landmarkType = "14">
|
||||
startingLineNumber = "577"
|
||||
endingLineNumber = "577"
|
||||
landmarkName = "unknown"
|
||||
landmarkType = "0">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "CDC436E9-4048-417F-B565-1230E11797C1"
|
||||
shouldBeEnabled = "Yes"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "gloss/ContentView.swift"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "446"
|
||||
endingLineNumber = "446"
|
||||
landmarkName = "body"
|
||||
landmarkType = "24">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "EA8119C2-B8C5-4B88-AA9A-2C4C80482D9E"
|
||||
shouldBeEnabled = "Yes"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "gloss/ContentView.swift"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "451"
|
||||
endingLineNumber = "451"
|
||||
landmarkName = "body"
|
||||
landmarkType = "24">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "19620363-AF5F-4353-862D-4E40746274F5"
|
||||
shouldBeEnabled = "Yes"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "gloss/ContentView.swift"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "556"
|
||||
endingLineNumber = "556"
|
||||
landmarkName = "handleVisibilityChanged(_:change:tracker:)"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "A3202903-6BE5-4879-8970-4CE7B825E6DD"
|
||||
shouldBeEnabled = "Yes"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "gloss/ContentView.swift"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "558"
|
||||
endingLineNumber = "558"
|
||||
landmarkName = "handleVisibilityChanged(_:change:tracker:)"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
</Breakpoints>
|
||||
|
|
|
@ -413,94 +413,72 @@ struct ContentView: View {
|
|||
loading: true)
|
||||
|
||||
}
|
||||
.onChange(of: refresh) { target in
|
||||
//if let target = target {
|
||||
//gTracker!.visibleViews["123123"] = CGFloat(100)
|
||||
// Print("ON CHANGE", gTracker!.visibleViews)
|
||||
// Print("removing", gTracker!.visibleViews.removeAll())
|
||||
.onChange(of: refresh) { target in
|
||||
//if let target = target {
|
||||
//gTracker!.visibleViews["123123"] = CGFloat(100)
|
||||
// Print("ON CHANGE", gTracker!.visibleViews)
|
||||
// Print("removing", gTracker!.visibleViews.removeAll())
|
||||
|
||||
Print("first scroll to")
|
||||
Print(scrollId)
|
||||
proxy.scrollTo(scrollId! , anchor: .top)
|
||||
currentId = scrollId!
|
||||
Print("removing", gTracker!.visibleViews.removeAll())
|
||||
Task {
|
||||
DispatchQueue.main.async {
|
||||
Print("first scroll to")
|
||||
Print(scrollId)
|
||||
|
||||
Task {
|
||||
// try? await Task.sleep(nanoseconds: 1_000_000_000)
|
||||
proxy.scrollTo(scrollId! , anchor: .top)
|
||||
|
||||
DispatchQueue.main.async {
|
||||
// if (currentId != scrollId!) {
|
||||
if (true) {
|
||||
DispatchQueue.main.async {
|
||||
// proxy.scrollTo(String(Int(scrollId!)! + 1))
|
||||
|
||||
// currentId = scrollId!
|
||||
|
||||
Print("cat MEOW MEOW MEOW")
|
||||
var newJump = String(Int(scrollId!)! + 1)
|
||||
// if (currentId != scrollId!) {
|
||||
|
||||
Print("cat new jump", newJump)
|
||||
proxy.scrollTo(newJump, anchor: .top)
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
|
||||
|
||||
DispatchQueue.main.async {
|
||||
|
||||
|
||||
var newJump2 = String(Int(scrollId!)!)
|
||||
Print("cat correct jump2", newJump2)
|
||||
proxy.scrollTo(newJump2, anchor: .top)
|
||||
|
||||
DispatchQueue.main.async {
|
||||
|
||||
|
||||
Print(" scroll offset target", scrollOffset)
|
||||
Print(" current offset ", currentOffset)
|
||||
// setScrollOffset = CGFloat(Int(currentOffset!) * -1 + Int(scrollOffset!))
|
||||
// setScrollOffset = CGFloat(Int(scrollOffset!) - Int(currentOffset!))
|
||||
setScrollOffset = CGFloat(Int(scrollOffset!))
|
||||
Print("setting scroll offset", setScrollOffset)
|
||||
currentOffset = scrollOffset!
|
||||
refresh2.toggle()
|
||||
// currentId = scrollId!
|
||||
|
||||
DispatchQueue.main.async {
|
||||
currentId = scrollId!
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Print(" scroll offset target", scrollOffset)
|
||||
Print(" current offset ", currentOffset)
|
||||
// setScrollOffset = CGFloat(Int(currentOffset!) * -1 + Int(scrollOffset!))
|
||||
setScrollOffset = CGFloat(Int(scrollOffset!) - Int(currentOffset!))
|
||||
Print("setting scroll offset", setScrollOffset)
|
||||
currentOffset = scrollOffset!
|
||||
refresh2.toggle()
|
||||
// currentId = scrollId!
|
||||
|
||||
DispatchQueue.main.async {
|
||||
currentId = scrollId!
|
||||
}
|
||||
}
|
||||
}
|
||||
Print(" scroll id target", currentId)
|
||||
Print(" current id ", scrollId)
|
||||
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!))
|
||||
setScrollOffset = CGFloat(Int(scrollOffset!) - Int(curOffset!))
|
||||
// // setScrollOffset = CGFloat(Int(scrollOffset!))
|
||||
// Print("setting scroll offset", setScrollOffset)
|
||||
refresh2.toggle()
|
||||
// // currentId = scrollId!
|
||||
|
||||
// DispatchQueue.main.async {
|
||||
|
||||
// currentOffset = scrollOffset!
|
||||
// currentId = scrollId!
|
||||
// }
|
||||
}
|
||||
}
|
||||
.introspectScrollView { scrollView in
|
||||
Print("introspect")
|
||||
// scrollView.delegate = scrollDelegate
|
||||
//Print("Scroll delegate offset", scrollDelegate.scrollOffset)
|
||||
}
|
||||
}
|
||||
.introspectScrollView { scrollView in
|
||||
Print("introspect")
|
||||
// scrollView.delegate = scrollDelegate
|
||||
//Print("Scroll delegate offset", scrollDelegate.scrollOffset)
|
||||
|
||||
if (setScrollOffset != nil) {
|
||||
// Print("Setting scroll offset in introspect", setScrollOffset)
|
||||
scrollView.contentOffset.y = scrollView.contentOffset.y + setScrollOffset!
|
||||
DispatchQueue.main.async { setScrollOffset = nil }
|
||||
}
|
||||
if (setScrollOffset != nil) {
|
||||
// Print("Setting scroll offset in introspect", setScrollOffset)
|
||||
scrollView.contentOffset.y = scrollView.contentOffset.y + setScrollOffset!
|
||||
DispatchQueue.main.async { setScrollOffset = nil }
|
||||
}
|
||||
|
||||
// if (thisScrollView == nil) {
|
||||
// Print("init scroll")
|
||||
// thisScrollView = scrollView
|
||||
// scrollView.contentOffset.y = CGFloat(selectedRibbon[0].scrollOffset)
|
||||
// }
|
||||
Print("end instrospect")
|
||||
}
|
||||
// if (thisScrollView == nil) {
|
||||
// Print("init scroll")
|
||||
// thisScrollView = scrollView
|
||||
// scrollView.contentOffset.y = CGFloat(selectedRibbon[0].scrollOffset)
|
||||
// }
|
||||
Print("end instrospect")
|
||||
}
|
||||
.listStyle(PlainListStyle())
|
||||
}
|
||||
.background(Color(red: 0.2, green: 0.2, blue: 0.2))
|
||||
|
@ -549,7 +527,7 @@ struct ContentView: View {
|
|||
func handleVisibilityChanged(_ id: String, change: VisibilityChange, tracker: VisibilityTracker<String>) {
|
||||
|
||||
|
||||
var printRate: Int64 = 10
|
||||
// var printRate: Int64 = 10
|
||||
gTracker = tracker
|
||||
|
||||
// @Environment(\.appDatabase) var appDatabase
|
||||
|
@ -557,13 +535,13 @@ struct ContentView: View {
|
|||
// case .shown: print("\(id) shown")
|
||||
// case .hidden: print("\(id) hidden")
|
||||
// }
|
||||
if (printCount % printRate == 0) {
|
||||
print("VISIBILITY CHANGED STARTED")
|
||||
print(tracker.visibleViews)
|
||||
print(tracker.sortedViewIDs)
|
||||
print("VISIBILITY CHANGED ENDED")
|
||||
}
|
||||
printCount += 1
|
||||
// if (printCount % printRate == 0) {
|
||||
// print("VISIBILITY CHANGED STARTED")
|
||||
// print(tracker.visibleViews)
|
||||
// print(tracker.sortedViewIDs)
|
||||
// print("VISIBILITY CHANGED ENDED")
|
||||
// }
|
||||
// printCount += 1
|
||||
|
||||
// if (currentId != nil) {
|
||||
// currentOffset = tracker.visibleViews[currentId!]!
|
||||
|
@ -575,15 +553,22 @@ struct ContentView: View {
|
|||
return
|
||||
}
|
||||
|
||||
currentId = tracker.sortedViewIDs[0]
|
||||
if (currentId != nil) {
|
||||
if (printCount % printRate == 0) {
|
||||
print(printCount)
|
||||
print("cat current ID:", currentId)
|
||||
currentId = tracker.sortedViewIDs[tracker.sortedViewIDs.count - 1]
|
||||
currentOffset = tracker.visibleViews[currentId!]!
|
||||
if (Int(currentOffset!) < 0) {
|
||||
if (tracker.sortedViewIDs.count > 1) {
|
||||
currentId = tracker.sortedViewIDs[1]
|
||||
currentOffset = tracker.visibleViews[currentId!]!
|
||||
}
|
||||
print("got here")
|
||||
currentOffset = tracker.visibleViews[currentId!]!
|
||||
}
|
||||
// if (currentId != nil) {
|
||||
// // if (printCount % printRate == 0) {
|
||||
// // print(printCount)
|
||||
// // print("cat current ID:", currentId)
|
||||
// // }
|
||||
// // print("got here")
|
||||
// currentOffset = tracker.visibleViews[currentId!]!
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue