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