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)
|
visibleViews[id] = -1 * (bounds.origin.y - containerBounds.origin.y)
|
||||||
// if (abs(visibleViews[id]! ) > 500 || visibleViews[id]! < 0) {
|
// 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.width == 0 || bounds.height == 0
|
||||||
|| bounds.origin.x == 0 || bounds.origin.y == 0
|
|| bounds.origin.x == 0 || bounds.origin.y == 0
|
||||||
|
@ -94,7 +95,8 @@ public class VisibilityTracker<ID: Hashable>: ObservableObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
func sortViews() {
|
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 })
|
// let sortedPairs = visibleViews.sorted(by: { $0 < $1 })
|
||||||
sortedViewIDs = sortedPairs.map { $0.0 }
|
sortedViewIDs = sortedPairs.map { $0.0 }
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
|
@ -7,17 +7,81 @@
|
||||||
<BreakpointProxy
|
<BreakpointProxy
|
||||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||||
<BreakpointContent
|
<BreakpointContent
|
||||||
uuid = "1C2BE985-4558-4ECC-A9BA-0620C612A996"
|
uuid = "15F59F9C-3FC1-4D0F-B85D-E6FBE78FA1B7"
|
||||||
shouldBeEnabled = "Yes"
|
shouldBeEnabled = "Yes"
|
||||||
ignoreCount = "0"
|
ignoreCount = "0"
|
||||||
continueAfterRunningActions = "No"
|
continueAfterRunningActions = "No"
|
||||||
filePath = "gloss/ContentView.swift"
|
filePath = "gloss/ContentView.swift"
|
||||||
startingColumnNumber = "9223372036854775807"
|
startingColumnNumber = "9223372036854775807"
|
||||||
endingColumnNumber = "9223372036854775807"
|
endingColumnNumber = "9223372036854775807"
|
||||||
startingLineNumber = "121"
|
startingLineNumber = "577"
|
||||||
endingLineNumber = "121"
|
endingLineNumber = "577"
|
||||||
landmarkName = "SwitchButton"
|
landmarkName = "unknown"
|
||||||
landmarkType = "14">
|
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>
|
</BreakpointContent>
|
||||||
</BreakpointProxy>
|
</BreakpointProxy>
|
||||||
</Breakpoints>
|
</Breakpoints>
|
||||||
|
|
|
@ -413,94 +413,72 @@ struct ContentView: View {
|
||||||
loading: true)
|
loading: true)
|
||||||
|
|
||||||
}
|
}
|
||||||
.onChange(of: refresh) { target in
|
.onChange(of: refresh) { target in
|
||||||
//if let target = target {
|
//if let target = target {
|
||||||
//gTracker!.visibleViews["123123"] = CGFloat(100)
|
//gTracker!.visibleViews["123123"] = CGFloat(100)
|
||||||
// Print("ON CHANGE", gTracker!.visibleViews)
|
// Print("ON CHANGE", gTracker!.visibleViews)
|
||||||
// Print("removing", gTracker!.visibleViews.removeAll())
|
// Print("removing", gTracker!.visibleViews.removeAll())
|
||||||
|
|
||||||
Print("first scroll to")
|
Task {
|
||||||
Print(scrollId)
|
DispatchQueue.main.async {
|
||||||
proxy.scrollTo(scrollId! , anchor: .top)
|
Print("first scroll to")
|
||||||
currentId = scrollId!
|
Print(scrollId)
|
||||||
Print("removing", gTracker!.visibleViews.removeAll())
|
|
||||||
|
|
||||||
Task {
|
proxy.scrollTo(scrollId! , anchor: .top)
|
||||||
// try? await Task.sleep(nanoseconds: 1_000_000_000)
|
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
// proxy.scrollTo(String(Int(scrollId!)! + 1))
|
||||||
// if (currentId != scrollId!) {
|
|
||||||
if (true) {
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
|
|
||||||
|
// currentId = scrollId!
|
||||||
|
|
||||||
Print("cat MEOW MEOW MEOW")
|
// if (currentId != scrollId!) {
|
||||||
var newJump = String(Int(scrollId!)! + 1)
|
|
||||||
|
|
||||||
Print("cat new jump", newJump)
|
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
|
||||||
proxy.scrollTo(newJump, anchor: .top)
|
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
Print(" scroll id target", currentId)
|
||||||
|
Print(" current id ", scrollId)
|
||||||
|
if (currentId! != scrollId!) {
|
||||||
var newJump2 = String(Int(scrollId!)!)
|
Print("NO MATCH")
|
||||||
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 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
|
.introspectScrollView { scrollView in
|
||||||
//Print("Scroll delegate offset", scrollDelegate.scrollOffset)
|
Print("introspect")
|
||||||
|
// scrollView.delegate = scrollDelegate
|
||||||
|
//Print("Scroll delegate offset", scrollDelegate.scrollOffset)
|
||||||
|
|
||||||
if (setScrollOffset != nil) {
|
if (setScrollOffset != nil) {
|
||||||
// Print("Setting scroll offset in introspect", setScrollOffset)
|
// Print("Setting scroll offset in introspect", setScrollOffset)
|
||||||
scrollView.contentOffset.y = scrollView.contentOffset.y + setScrollOffset!
|
scrollView.contentOffset.y = scrollView.contentOffset.y + setScrollOffset!
|
||||||
DispatchQueue.main.async { setScrollOffset = nil }
|
DispatchQueue.main.async { setScrollOffset = nil }
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (thisScrollView == nil) {
|
// if (thisScrollView == nil) {
|
||||||
// Print("init scroll")
|
// Print("init scroll")
|
||||||
// thisScrollView = scrollView
|
// thisScrollView = scrollView
|
||||||
// scrollView.contentOffset.y = CGFloat(selectedRibbon[0].scrollOffset)
|
// scrollView.contentOffset.y = CGFloat(selectedRibbon[0].scrollOffset)
|
||||||
// }
|
// }
|
||||||
Print("end instrospect")
|
Print("end instrospect")
|
||||||
}
|
}
|
||||||
.listStyle(PlainListStyle())
|
.listStyle(PlainListStyle())
|
||||||
}
|
}
|
||||||
.background(Color(red: 0.2, green: 0.2, blue: 0.2))
|
.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>) {
|
func handleVisibilityChanged(_ id: String, change: VisibilityChange, tracker: VisibilityTracker<String>) {
|
||||||
|
|
||||||
|
|
||||||
var printRate: Int64 = 10
|
// var printRate: Int64 = 10
|
||||||
gTracker = tracker
|
gTracker = tracker
|
||||||
|
|
||||||
// @Environment(\.appDatabase) var appDatabase
|
// @Environment(\.appDatabase) var appDatabase
|
||||||
|
@ -557,13 +535,13 @@ struct ContentView: View {
|
||||||
// case .shown: print("\(id) shown")
|
// case .shown: print("\(id) shown")
|
||||||
// case .hidden: print("\(id) hidden")
|
// case .hidden: print("\(id) hidden")
|
||||||
// }
|
// }
|
||||||
if (printCount % printRate == 0) {
|
// if (printCount % printRate == 0) {
|
||||||
print("VISIBILITY CHANGED STARTED")
|
// print("VISIBILITY CHANGED STARTED")
|
||||||
print(tracker.visibleViews)
|
// print(tracker.visibleViews)
|
||||||
print(tracker.sortedViewIDs)
|
// print(tracker.sortedViewIDs)
|
||||||
print("VISIBILITY CHANGED ENDED")
|
// print("VISIBILITY CHANGED ENDED")
|
||||||
}
|
// }
|
||||||
printCount += 1
|
// printCount += 1
|
||||||
|
|
||||||
// if (currentId != nil) {
|
// if (currentId != nil) {
|
||||||
// currentOffset = tracker.visibleViews[currentId!]!
|
// currentOffset = tracker.visibleViews[currentId!]!
|
||||||
|
@ -575,15 +553,22 @@ struct ContentView: View {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
currentId = tracker.sortedViewIDs[0]
|
currentId = tracker.sortedViewIDs[tracker.sortedViewIDs.count - 1]
|
||||||
if (currentId != nil) {
|
currentOffset = tracker.visibleViews[currentId!]!
|
||||||
if (printCount % printRate == 0) {
|
if (Int(currentOffset!) < 0) {
|
||||||
print(printCount)
|
if (tracker.sortedViewIDs.count > 1) {
|
||||||
print("cat current ID:", currentId)
|
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