Scroll restore actually working this time. scrollTo(:id) is not exact on device, so have to offset the overshoot before applying saved scrollOffset
parent
9e19199b87
commit
e4797f7fa8
Binary file not shown.
|
@ -68,7 +68,7 @@ struct SwitchButton : View {
|
||||||
action: {
|
action: {
|
||||||
Task {
|
Task {
|
||||||
var selectedRibbon = sr[0]
|
var selectedRibbon = sr[0]
|
||||||
Print("SELECTED RIBBON", selectedRibbon)
|
// Print("SELECTED RIBBON", selectedRibbon)
|
||||||
let userDefaults = UserDefaults.standard
|
let userDefaults = UserDefaults.standard
|
||||||
|
|
||||||
// var scrollOffsetToSave = userDefaults.object(forKey: "currentOffset") as? CGFloat
|
// var scrollOffsetToSave = userDefaults.object(forKey: "currentOffset") as? CGFloat
|
||||||
|
@ -77,8 +77,8 @@ struct SwitchButton : View {
|
||||||
var scrollOffsetToSave = currentOffset
|
var scrollOffsetToSave = currentOffset
|
||||||
var scrollIdToSave = currentId
|
var scrollIdToSave = currentId
|
||||||
|
|
||||||
Print("scrollOffsetToSave: ", scrollOffsetToSave)
|
// Print("scrollOffsetToSave: ", scrollOffsetToSave)
|
||||||
Print("scrollIdToSave: ", scrollIdToSave)
|
// Print("scrollIdToSave: ", scrollIdToSave)
|
||||||
|
|
||||||
var updatedRibbon = selectedRibbon
|
var updatedRibbon = selectedRibbon
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ struct SwitchButton : View {
|
||||||
|
|
||||||
|
|
||||||
if (selectedRibbon.id != ribbon.id!) {
|
if (selectedRibbon.id != ribbon.id!) {
|
||||||
Print("switching")
|
// Print("switching")
|
||||||
|
|
||||||
scrollId = ribbon.scrollId
|
scrollId = ribbon.scrollId
|
||||||
scrollOffset = CGFloat(ribbon.scrollOffset)
|
scrollOffset = CGFloat(ribbon.scrollOffset)
|
||||||
|
@ -102,12 +102,12 @@ struct SwitchButton : View {
|
||||||
userDefaults.set(scrollOffset, forKey: "currentOffset")
|
userDefaults.set(scrollOffset, forKey: "currentOffset")
|
||||||
|
|
||||||
var updateSelectRibbon = SelectedRibbon(id: Int64(1), ribbonId: ribbon.id!)
|
var updateSelectRibbon = SelectedRibbon(id: Int64(1), ribbonId: ribbon.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 {
|
||||||
Print("something wrong")
|
// Print("something wrong")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,14 +116,14 @@ struct SwitchButton : View {
|
||||||
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)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -209,7 +209,7 @@ private struct SegRow: View {
|
||||||
// .id(seg.id)
|
// .id(seg.id)
|
||||||
//.onTapGesture {
|
//.onTapGesture {
|
||||||
// selectedLine = seg.id
|
// selectedLine = seg.id
|
||||||
// //Print(selectedLine)
|
//Print(selectedLine)
|
||||||
//}
|
//}
|
||||||
|
|
||||||
// .listRowBackground(Color(red: 0.2, green: 0.8, blue: 0.2))
|
// .listRowBackground(Color(red: 0.2, green: 0.8, blue: 0.2))
|
||||||
|
@ -220,7 +220,7 @@ private struct SegRow: View {
|
||||||
// .id(seg.id)
|
// .id(seg.id)
|
||||||
//.onTapGesture {
|
//.onTapGesture {
|
||||||
// selectedLine = seg.id
|
// selectedLine = seg.id
|
||||||
// //Print(selectedLine)
|
//Print(selectedLine)
|
||||||
//}
|
//}
|
||||||
})
|
})
|
||||||
// }
|
// }
|
||||||
|
@ -279,7 +279,7 @@ struct ContentView: View {
|
||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Print("rendering")
|
// Print("rendering")
|
||||||
|
|
||||||
GeometryReader { geometry in
|
GeometryReader { geometry in
|
||||||
ZStack{
|
ZStack{
|
||||||
|
@ -306,8 +306,8 @@ struct ContentView: View {
|
||||||
refresh:$refresh
|
refresh:$refresh
|
||||||
)
|
)
|
||||||
.buttonStyle(BlueButtonStyle())
|
.buttonStyle(BlueButtonStyle())
|
||||||
Print("RIBBON")
|
// Print("RIBBON")
|
||||||
Print(ribbon)
|
// Print(ribbon)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.frame(width: geometry.size.width, height: geometry.size.height, alignment: .topLeading)
|
.frame(width: geometry.size.width, height: geometry.size.height, alignment: .topLeading)
|
||||||
|
@ -331,8 +331,8 @@ struct ContentView: View {
|
||||||
.trackVisibility(id: "\(seg.id)")
|
.trackVisibility(id: "\(seg.id)")
|
||||||
|
|
||||||
// .onChange(of: geometry.frame(in: .named("scrollView"))) { imageRect in
|
// .onChange(of: geometry.frame(in: .named("scrollView"))) { imageRect in
|
||||||
// Print(imageRect)
|
//Print(imageRect)
|
||||||
// Print(outerProxy)
|
//Print(outerProxy)
|
||||||
// if isInView(innerRect: imageRect, isIn: outerProxy) {
|
// if isInView(innerRect: imageRect, isIn: outerProxy) {
|
||||||
// visibleIndex.insert(item)
|
// visibleIndex.insert(item)
|
||||||
// } else {
|
// } else {
|
||||||
|
@ -346,29 +346,34 @@ struct ContentView: View {
|
||||||
.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())
|
||||||
proxy.scrollTo(scrollId! , anchor: .top)
|
proxy.scrollTo(scrollId! , anchor: .top)
|
||||||
|
Task {
|
||||||
|
// try? await Task.sleep(nanoseconds: 1_000_000_000)
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
setScrollOffset = CGFloat(scrollOffset!)
|
// setScrollOffset = CGFloat(scrollOffset!)
|
||||||
|
setScrollOffset = CGFloat(Int(currentOffset!) * -1 + Int(scrollOffset!))
|
||||||
refresh2.toggle()
|
refresh2.toggle()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
.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", setScrollOffset)
|
// Print("Setting scroll offset", 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)
|
||||||
// }
|
// }
|
||||||
|
@ -387,11 +392,11 @@ struct ContentView: View {
|
||||||
if (endedDrag) {
|
if (endedDrag) {
|
||||||
endedDrag = false
|
endedDrag = false
|
||||||
scrollOffset = readOffset.y - 20
|
scrollOffset = readOffset.y - 20
|
||||||
_ = Print("meow")
|
// _ = Print("meow")
|
||||||
}
|
}
|
||||||
// logger.error("hello222")
|
// logger.error("hello222")
|
||||||
// NSLog("hellooo")
|
// NSLog("hellooo")
|
||||||
//Print(viewState.width)
|
Print(viewState.width)
|
||||||
if (abs(gesture.translation.width) > 20) {
|
if (abs(gesture.translation.width) > 20) {
|
||||||
viewState.width = gesture.translation.width
|
viewState.width = gesture.translation.width
|
||||||
}
|
}
|
||||||
|
@ -448,7 +453,7 @@ struct ContentView: View {
|
||||||
// let userDefaults = UserDefaults.standard
|
// let userDefaults = UserDefaults.standard
|
||||||
|
|
||||||
// Write/Set Value
|
// Write/Set Value
|
||||||
Print(currentId!)
|
// Print(currentId!)
|
||||||
// Print(tracker.visibleViews[currentId?]!)
|
// Print(tracker.visibleViews[currentId?]!)
|
||||||
// userDefaults.set(currentId, forKey: "currentId")
|
// userDefaults.set(currentId, forKey: "currentId")
|
||||||
// userDefaults.set(tracker.visibleViews[currentId]!, forKey: "currentOffset")
|
// userDefaults.set(tracker.visibleViews[currentId]!, forKey: "currentOffset")
|
||||||
|
@ -457,15 +462,15 @@ 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) {
|
||||||
|
|
||||||
// do {
|
// do {
|
||||||
// _ = try await appDatabase.saveScrollState(&updateScrollState)
|
// _ = try await appDatabase.saveScrollState(&updateScrollState)
|
||||||
|
|
||||||
// } catch {
|
// } catch {
|
||||||
// Print("something wrong")
|
Print("something wrong")
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue