okay now it seems to work with delay

undo
Saint 2023-06-02 17:25:20 -04:00
parent 25d7d9b188
commit 3a456cb457
4 changed files with 150 additions and 99 deletions

View File

@ -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 }
}

View File

@ -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>

View File

@ -419,66 +419,44 @@ struct ContentView: View {
// Print("ON CHANGE", gTracker!.visibleViews)
// Print("removing", gTracker!.visibleViews.removeAll())
Task {
DispatchQueue.main.async {
Print("first scroll to")
Print(scrollId)
proxy.scrollTo(scrollId! , anchor: .top)
currentId = scrollId!
Print("removing", gTracker!.visibleViews.removeAll())
Task {
// try? await Task.sleep(nanoseconds: 1_000_000_000)
// proxy.scrollTo(String(Int(scrollId!)! + 1))
// currentId = scrollId!
DispatchQueue.main.async {
// if (currentId != scrollId!) {
if (true) {
DispatchQueue.main.async {
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
Print(" scroll id target", currentId)
Print(" current id ", scrollId)
if (currentId! != scrollId!) {
Print("NO MATCH")
}
Print("cat MEOW MEOW MEOW")
var newJump = String(Int(scrollId!)! + 1)
Print("cat new jump", newJump)
proxy.scrollTo(newJump, anchor: .top)
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!
// 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!
// // 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 {
DispatchQueue.main.async {
currentId = scrollId!
}
// currentOffset = scrollOffset!
// currentId = scrollId!
// }
}
}
}
@ -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,16 +553,23 @@ struct ContentView: View {
return
}
currentId = tracker.sortedViewIDs[0]
if (currentId != nil) {
if (printCount % printRate == 0) {
print(printCount)
print("cat current ID:", currentId)
}
print("got here")
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!]!
}
}
// if (currentId != nil) {
// // if (printCount % printRate == 0) {
// // print(printCount)
// // print("cat current ID:", currentId)
// // }
// // print("got here")
// currentOffset = tracker.visibleViews[currentId!]!
// }
}
}
private let itemFormatter: DateFormatter = {