refactored button to external func, fixed bug where currentId and currentOffset wasnt saved on switch
parent
6ab9d30ba0
commit
d9ed0d2da9
|
@ -51,13 +51,13 @@ public class VisibilityTracker<ID: Hashable>: ObservableObject {
|
||||||
let isVisible = containerBounds.contains(topLeft) || containerBounds.contains(bottomRight)
|
let isVisible = containerBounds.contains(topLeft) || containerBounds.contains(bottomRight)
|
||||||
let wasVisible = visibleViews[id] != nil
|
let wasVisible = visibleViews[id] != nil
|
||||||
|
|
||||||
print("report content bounds start")
|
// print("report content bounds start")
|
||||||
print(id)
|
// print(id)
|
||||||
print(bounds.width)
|
// print(bounds.width)
|
||||||
print(bounds.height)
|
// print(bounds.height)
|
||||||
print(bounds.origin)
|
// print(bounds.origin)
|
||||||
print(containerBounds)
|
// print(containerBounds)
|
||||||
print("report content bounds end")
|
// print("report content bounds end")
|
||||||
|
|
||||||
|
|
||||||
visibleViews[id] = -1 * (bounds.origin.y - containerBounds.origin.y)
|
visibleViews[id] = -1 * (bounds.origin.y - containerBounds.origin.y)
|
||||||
|
|
Binary file not shown.
|
@ -9,89 +9,97 @@
|
||||||
<key>isShown</key>
|
<key>isShown</key>
|
||||||
<false/>
|
<false/>
|
||||||
<key>orderHint</key>
|
<key>orderHint</key>
|
||||||
<integer>3</integer>
|
<integer>12</integer>
|
||||||
</dict>
|
</dict>
|
||||||
<key>Associations (Playground) 2.xcscheme</key>
|
<key>Associations (Playground) 2.xcscheme</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>isShown</key>
|
<key>isShown</key>
|
||||||
<false/>
|
<false/>
|
||||||
<key>orderHint</key>
|
<key>orderHint</key>
|
||||||
<integer>4</integer>
|
<integer>13</integer>
|
||||||
</dict>
|
</dict>
|
||||||
<key>Associations (Playground).xcscheme</key>
|
<key>Associations (Playground).xcscheme</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>isShown</key>
|
<key>isShown</key>
|
||||||
<false/>
|
<false/>
|
||||||
<key>orderHint</key>
|
<key>orderHint</key>
|
||||||
<integer>2</integer>
|
<integer>11</integer>
|
||||||
</dict>
|
</dict>
|
||||||
<key>MyPlayground (Playground) 1.xcscheme</key>
|
<key>MyPlayground (Playground) 1.xcscheme</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>isShown</key>
|
<key>isShown</key>
|
||||||
<false/>
|
<false/>
|
||||||
<key>orderHint</key>
|
<key>orderHint</key>
|
||||||
<integer>6</integer>
|
<integer>9</integer>
|
||||||
</dict>
|
</dict>
|
||||||
<key>MyPlayground (Playground) 2.xcscheme</key>
|
<key>MyPlayground (Playground) 2.xcscheme</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>isShown</key>
|
<key>isShown</key>
|
||||||
<false/>
|
<false/>
|
||||||
<key>orderHint</key>
|
<key>orderHint</key>
|
||||||
<integer>7</integer>
|
<integer>10</integer>
|
||||||
</dict>
|
</dict>
|
||||||
<key>MyPlayground (Playground).xcscheme</key>
|
<key>MyPlayground (Playground).xcscheme</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>isShown</key>
|
<key>isShown</key>
|
||||||
<false/>
|
<false/>
|
||||||
<key>orderHint</key>
|
<key>orderHint</key>
|
||||||
<integer>5</integer>
|
<integer>8</integer>
|
||||||
</dict>
|
</dict>
|
||||||
<key>Tour (Playground) 1.xcscheme</key>
|
<key>Tour (Playground) 1.xcscheme</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>isShown</key>
|
<key>isShown</key>
|
||||||
<false/>
|
<false/>
|
||||||
<key>orderHint</key>
|
<key>orderHint</key>
|
||||||
<integer>9</integer>
|
<integer>6</integer>
|
||||||
</dict>
|
</dict>
|
||||||
<key>Tour (Playground) 2.xcscheme</key>
|
<key>Tour (Playground) 2.xcscheme</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>isShown</key>
|
<key>isShown</key>
|
||||||
<false/>
|
<false/>
|
||||||
<key>orderHint</key>
|
<key>orderHint</key>
|
||||||
<integer>10</integer>
|
<integer>7</integer>
|
||||||
</dict>
|
</dict>
|
||||||
<key>Tour (Playground).xcscheme</key>
|
<key>Tour (Playground).xcscheme</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>isShown</key>
|
<key>isShown</key>
|
||||||
<false/>
|
<false/>
|
||||||
<key>orderHint</key>
|
<key>orderHint</key>
|
||||||
<integer>8</integer>
|
<integer>5</integer>
|
||||||
</dict>
|
</dict>
|
||||||
<key>TransactionObserver (Playground) 1.xcscheme</key>
|
<key>TransactionObserver (Playground) 1.xcscheme</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>isShown</key>
|
<key>isShown</key>
|
||||||
<false/>
|
<false/>
|
||||||
<key>orderHint</key>
|
<key>orderHint</key>
|
||||||
<integer>12</integer>
|
<integer>3</integer>
|
||||||
</dict>
|
</dict>
|
||||||
<key>TransactionObserver (Playground) 2.xcscheme</key>
|
<key>TransactionObserver (Playground) 2.xcscheme</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>isShown</key>
|
<key>isShown</key>
|
||||||
<false/>
|
<false/>
|
||||||
<key>orderHint</key>
|
<key>orderHint</key>
|
||||||
<integer>13</integer>
|
<integer>4</integer>
|
||||||
</dict>
|
</dict>
|
||||||
<key>TransactionObserver (Playground).xcscheme</key>
|
<key>TransactionObserver (Playground).xcscheme</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>isShown</key>
|
<key>isShown</key>
|
||||||
<false/>
|
<false/>
|
||||||
<key>orderHint</key>
|
<key>orderHint</key>
|
||||||
<integer>11</integer>
|
<integer>1</integer>
|
||||||
</dict>
|
</dict>
|
||||||
<key>gloss.xcscheme_^#shared#^_</key>
|
<key>gloss.xcscheme_^#shared#^_</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>orderHint</key>
|
<key>orderHint</key>
|
||||||
<integer>0</integer>
|
<integer>2</integer>
|
||||||
|
</dict>
|
||||||
|
</dict>
|
||||||
|
<key>SuppressBuildableAutocreation</key>
|
||||||
|
<dict>
|
||||||
|
<key>85431A842905F4F500EE0760</key>
|
||||||
|
<dict>
|
||||||
|
<key>primary</key>
|
||||||
|
<true/>
|
||||||
</dict>
|
</dict>
|
||||||
</dict>
|
</dict>
|
||||||
</dict>
|
</dict>
|
||||||
|
|
|
@ -62,7 +62,7 @@ func goToRibbon(selectedRibbon: Ribbon,
|
||||||
// @Binding var scrollId : String?
|
// @Binding var scrollId : String?
|
||||||
// @Binding var scrollOffset : CGFloat?
|
// @Binding var scrollOffset : CGFloat?
|
||||||
// @Binding var refresh : Bool
|
// @Binding var refresh : Bool
|
||||||
print("SELECTED RIBBON", selectedRibbon)
|
// print("SELECTED RIBBON", selectedRibbon)
|
||||||
let userDefaults = UserDefaults.standard
|
let userDefaults = UserDefaults.standard
|
||||||
var scrollOffsetToSave = currentOffset
|
var scrollOffsetToSave = currentOffset
|
||||||
var scrollIdToSave = currentId
|
var scrollIdToSave = currentId
|
||||||
|
@ -77,13 +77,13 @@ func goToRibbon(selectedRibbon: Ribbon,
|
||||||
// refresh.toggle()
|
// refresh.toggle()
|
||||||
|
|
||||||
if (selectedRibbon.id != destRibbon.id!) {
|
if (selectedRibbon.id != destRibbon.id!) {
|
||||||
// Print("switching")
|
print("switching ribbons")
|
||||||
|
|
||||||
scrollId.wrappedValue = destRibbon.scrollId
|
scrollId.wrappedValue = destRibbon.scrollId
|
||||||
print("setting scroll offset")
|
// print("setting scroll offset")
|
||||||
scrollOffset.wrappedValue = CGFloat(destRibbon.scrollOffset)
|
scrollOffset.wrappedValue = CGFloat(destRibbon.scrollOffset)
|
||||||
print(scrollOffset.wrappedValue)
|
// print(scrollOffset.wrappedValue)
|
||||||
print("end setting scroll offset")
|
// print("end setting scroll offset")
|
||||||
refresh.wrappedValue.toggle()
|
refresh.wrappedValue.toggle()
|
||||||
|
|
||||||
//scrollId = "10"
|
//scrollId = "10"
|
||||||
|
@ -93,8 +93,8 @@ func goToRibbon(selectedRibbon: Ribbon,
|
||||||
userDefaults.set(scrollOffset.wrappedValue, forKey: "currentOffset")
|
userDefaults.set(scrollOffset.wrappedValue, forKey: "currentOffset")
|
||||||
|
|
||||||
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")
|
||||||
print(updateSelectRibbon)
|
// print(updateSelectRibbon)
|
||||||
do {
|
do {
|
||||||
_ = try await appDatabase.saveSelectedRibbon(&updateSelectRibbon)
|
_ = try await appDatabase.saveSelectedRibbon(&updateSelectRibbon)
|
||||||
} catch {
|
} catch {
|
||||||
|
@ -106,14 +106,14 @@ func goToRibbon(selectedRibbon: Ribbon,
|
||||||
updatedRibbon.scrollId = scrollIdToSave!
|
updatedRibbon.scrollId = scrollIdToSave!
|
||||||
|
|
||||||
_ = try await appDatabase.saveRibbon(&updatedRibbon)
|
_ = try await appDatabase.saveRibbon(&updatedRibbon)
|
||||||
print("saved updatedRibbon", updatedRibbon)
|
// print("saved updatedRibbon", updatedRibbon)
|
||||||
|
|
||||||
print("UPDATED")
|
// print("UPDATED")
|
||||||
scrollOffsetToSave = userDefaults.object(forKey: "currentOffset") as? CGFloat
|
scrollOffsetToSave = userDefaults.object(forKey: "currentOffset") as? CGFloat
|
||||||
scrollIdToSave = userDefaults.object(forKey: "currentId") as? String
|
scrollIdToSave = userDefaults.object(forKey: "currentId") as? String
|
||||||
|
|
||||||
print("scrollOffsetToSave: ", scrollOffsetToSave)
|
// print("scrollOffsetToSave: ", scrollOffsetToSave)
|
||||||
print("scrollIdToSave: ", scrollIdToSave)
|
// print("scrollIdToSave: ", scrollIdToSave)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,7 +128,6 @@ struct SwitchButton : View {
|
||||||
@Query(SelectedRibbonRequest()) private var sr: [Ribbon]
|
@Query(SelectedRibbonRequest()) private var sr: [Ribbon]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@State var saveOffset = CGFloat()
|
@State var saveOffset = CGFloat()
|
||||||
var body: some View {
|
var body: some View {
|
||||||
// ForEach(sr) { selectedRibbon in
|
// ForEach(sr) { selectedRibbon in
|
||||||
|
@ -396,13 +395,24 @@ struct ContentView: View {
|
||||||
//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")
|
||||||
|
Print(scrollId)
|
||||||
proxy.scrollTo(scrollId! , anchor: .top)
|
proxy.scrollTo(scrollId! , anchor: .top)
|
||||||
|
currentId = scrollId!
|
||||||
|
|
||||||
Task {
|
Task {
|
||||||
// try? await Task.sleep(nanoseconds: 1_000_000_000)
|
// try? await Task.sleep(nanoseconds: 1_000_000_000)
|
||||||
|
|
||||||
|
|
||||||
|
// try? await Task.sleep(nanoseconds: 1_000_000_000)
|
||||||
|
proxy.scrollTo(scrollId! , anchor: .top)
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
// setScrollOffset = CGFloat(scrollOffset!)
|
// setScrollOffset = CGFloat(scrollOffset!)
|
||||||
setScrollOffset = CGFloat(Int(currentOffset!) * -1 + Int(scrollOffset!))
|
setScrollOffset = CGFloat(Int(currentOffset!) * -1 + Int(scrollOffset!))
|
||||||
|
currentOffset = scrollOffset!
|
||||||
|
|
||||||
refresh2.toggle()
|
refresh2.toggle()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -410,18 +420,18 @@ struct ContentView: View {
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
.introspectScrollView { scrollView in
|
.introspectScrollView { scrollView in
|
||||||
Print("introspect")
|
// Print("introspect")
|
||||||
// scrollView.delegate = scrollDelegate
|
// scrollView.delegate = scrollDelegate
|
||||||
//Print("Scroll delegate offset", scrollDelegate.scrollOffset)
|
//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)
|
||||||
// }
|
// }
|
||||||
|
@ -475,15 +485,15 @@ struct ContentView: View {
|
||||||
|
|
||||||
|
|
||||||
// @Environment(\.appDatabase) var appDatabase
|
// @Environment(\.appDatabase) var appDatabase
|
||||||
switch change {
|
// switch change {
|
||||||
case .shown: print("\(id) shown")
|
// case .shown: print("\(id) shown")
|
||||||
case .hidden: print("\(id) hidden")
|
// case .hidden: print("\(id) hidden")
|
||||||
}
|
// }
|
||||||
print("VISIBILITY CHANGED STARTED")
|
// print("VISIBILITY CHANGED STARTED")
|
||||||
print(tracker.visibleViews)
|
// print(tracker.visibleViews)
|
||||||
gTracker = tracker
|
// gTracker = tracker
|
||||||
print(tracker.sortedViewIDs)
|
// print(tracker.sortedViewIDs)
|
||||||
print("VISIBILITY CHANGED ENDED")
|
// print("VISIBILITY CHANGED ENDED")
|
||||||
// if (currentId != nil) {
|
// if (currentId != nil) {
|
||||||
// currentOffset = tracker.visibleViews[currentId!]!
|
// currentOffset = tracker.visibleViews[currentId!]!
|
||||||
// }
|
// }
|
||||||
|
@ -496,6 +506,7 @@ struct ContentView: View {
|
||||||
|
|
||||||
currentId = tracker.sortedViewIDs[0]
|
currentId = tracker.sortedViewIDs[0]
|
||||||
if (currentId != nil) {
|
if (currentId != nil) {
|
||||||
|
print("current ID:", currentId)
|
||||||
|
|
||||||
// Access Shared Defaults Object
|
// Access Shared Defaults Object
|
||||||
// let userDefaults = UserDefaults.standard
|
// let userDefaults = UserDefaults.standard
|
||||||
|
@ -510,7 +521,7 @@ struct ContentView: View {
|
||||||
// var updateScrollState = ScrollState(id: Int64(1),
|
// var updateScrollState = ScrollState(id: Int64(1),
|
||||||
// scrollId: currentId!,
|
// scrollId: currentId!,
|
||||||
// scrollOffset: Int64(tracker.visibleViews[currentId!]!))
|
// scrollOffset: Int64(tracker.visibleViews[currentId!]!))
|
||||||
Print("Savingg")
|
// Print("Savingg")
|
||||||
//Print(updateScrollState)
|
//Print(updateScrollState)
|
||||||
// Task(priority: .default) {
|
// Task(priority: .default) {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue