can scroll to arbitrary point from any point
parent
3820bdff16
commit
ea3ac33f99
|
@ -30,8 +30,8 @@ struct SegDenormRequest: Queryable {
|
|||
do {
|
||||
var ret = try SegDenorm.fetchAll(db, sql: sql) // [Player]
|
||||
|
||||
print("SEGS DENORM")
|
||||
print(ret)
|
||||
// print("SEGS DENORM")
|
||||
// print(ret)
|
||||
return ret
|
||||
} catch let error {
|
||||
print(error.localizedDescription)
|
||||
|
|
|
@ -53,7 +53,7 @@ public class VisibilityTracker<ID: Hashable>: ObservableObject {
|
|||
|
||||
|
||||
visibleViews[id] = -1 * (bounds.origin.y - containerBounds.origin.y)
|
||||
if (abs(visibleViews[id]! ) > 1000) {
|
||||
if (abs(visibleViews[id]! ) > 500) {
|
||||
visibleViews.removeValue(forKey: id)
|
||||
}
|
||||
sortViews()
|
||||
|
|
Binary file not shown.
|
@ -68,7 +68,7 @@ struct AppDatabase {
|
|||
t.column("scrollOffset", .integer).notNull()
|
||||
}
|
||||
|
||||
try db.create(table: "foo2") { t in
|
||||
try db.create(table: "foo3") { t in
|
||||
t.autoIncrementedPrimaryKey("id")
|
||||
t.column("ribbonId", .integer).notNull()
|
||||
}
|
||||
|
@ -170,10 +170,9 @@ extension AppDatabase {
|
|||
// print("cat")
|
||||
// try createRandomLines(db)
|
||||
|
||||
_ = try Ribbon(id: 1, book: "bible.john", scrollOffset: 0).inserted(db)
|
||||
_ = try Ribbon(id: 2, book: "bible.john", scrollOffset: 2000).inserted(db)
|
||||
_ = try Ribbon(id: 1, book: "bible.john", scrollId: "1", scrollOffset: 0).inserted(db)
|
||||
_ = try Ribbon(id: 2, book: "bible.john", scrollId: "1", scrollOffset: 300).inserted(db)
|
||||
_ = try SelectedRibbon(id: 1, ribbonId: 1).inserted(db)
|
||||
_ = try ScrollState(id: 1, scrollId: "1", scrollOffset: 1).inserted(db)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,12 +47,9 @@ struct BlueButtonStyle: ButtonStyle {
|
|||
|
||||
struct SwitchButton : View {
|
||||
var ribbon: Ribbon
|
||||
// var selectedRibbon: SelectedRibbon
|
||||
|
||||
// @Binding var book : String
|
||||
// @Binding var scrollDelegate : ScrollViewHandler
|
||||
@Binding var scrollView : UIScrollView?
|
||||
@Binding var scrollUpdate : Bool
|
||||
@Binding var scrollId : String?
|
||||
@Binding var scrollOffset : CGFloat?
|
||||
@Binding var refresh : Bool
|
||||
|
||||
@Environment(\.appDatabase) private var appDatabase
|
||||
|
||||
|
@ -61,32 +58,42 @@ struct SwitchButton : View {
|
|||
@State var saveOffset = CGFloat()
|
||||
var body: some View {
|
||||
// ForEach(sr) { selectedRibbon in
|
||||
Button(String(sr[0].id!) + " " + String(ribbon.id!) + " " + String(ribbon.scrollOffset),
|
||||
// Button("meow",
|
||||
let ribbonString = String(ribbon.scrollOffset) + " " + ribbon.scrollId
|
||||
Button(String(sr[0].id!) + " " + String(ribbon.id!) + " " + ribbonString,
|
||||
action: {
|
||||
Task {
|
||||
var selectedRibbon = sr[0]
|
||||
Print("SELECTED RIBBON", selectedRibbon)
|
||||
let userDefaults = UserDefaults.standard
|
||||
|
||||
// var saveScrollOffset = scrollDelegate.scrollOffset
|
||||
var scrollOffsetToSave = userDefaults.object(forKey: "currentOffset") as? CGFloat
|
||||
var scrollIdToSave = userDefaults.object(forKey: "currentId") as? String
|
||||
|
||||
var editedRibbon = selectedRibbon
|
||||
Print("scrollOffsetToSave: ", scrollOffsetToSave)
|
||||
Print("scrollIdToSave: ", scrollIdToSave)
|
||||
|
||||
Print("ribbon offset saved")
|
||||
var updatedRibbon = selectedRibbon
|
||||
|
||||
scrollId = "10"
|
||||
scrollOffset = CGFloat(100)
|
||||
refresh.toggle()
|
||||
|
||||
|
||||
scrollUpdate = true
|
||||
if (selectedRibbon.id != ribbon.id!) {
|
||||
Print("switching")
|
||||
// book = ribbon.book
|
||||
// Print("applying offset", CGFloat(ribbon.scrollOffset))
|
||||
|
||||
// scrollId = ribbon.scrollId
|
||||
// scrollOffset = CGFloat(ribbon.scrollOffset)
|
||||
// scrollDelegate.scrollOffset = CGFloat(ribbon.scrollOffset)
|
||||
// scrollDelegate.scrollOffset = CGFloat(ribbon.scrollOffset)
|
||||
// scrollView!.contentOffset.y = CGFloat(ribbon.scrollOffset)
|
||||
// scrollOffset = CGFloat(1500)
|
||||
|
||||
//scrollId = "10"
|
||||
//scrollOffset = CGFloat(100)
|
||||
|
||||
|
||||
userDefaults.set(scrollId, forKey: "currentId")
|
||||
userDefaults.set(scrollOffset, forKey: "currentOffset")
|
||||
|
||||
var updateSelectRibbon = SelectedRibbon(id: Int64(1), ribbonId: ribbon.id!)
|
||||
Print("Savingg")
|
||||
Print("Saving selected ribbon")
|
||||
Print(updateSelectRibbon)
|
||||
do {
|
||||
_ = try await appDatabase.saveSelectedRibbon(&updateSelectRibbon)
|
||||
|
@ -95,12 +102,19 @@ struct SwitchButton : View {
|
|||
}
|
||||
}
|
||||
|
||||
// editedRibbon.scrollOffset = Int(saveScrollOffset)
|
||||
|
||||
_ = try await appDatabase.saveRibbon(&editedRibbon)
|
||||
_ = Print("editedRibbon", editedRibbon)
|
||||
_ = Print("ribbon", ribbon)
|
||||
updatedRibbon.scrollOffset = Int(scrollOffsetToSave!)
|
||||
updatedRibbon.scrollId = scrollIdToSave!
|
||||
|
||||
_ = try await appDatabase.saveRibbon(&updatedRibbon)
|
||||
_ = Print("saved updatedRibbon", updatedRibbon)
|
||||
|
||||
Print("UPDATED")
|
||||
scrollOffsetToSave = userDefaults.object(forKey: "currentOffset") as? CGFloat
|
||||
scrollIdToSave = userDefaults.object(forKey: "currentId") as? String
|
||||
|
||||
Print("scrollOffsetToSave: ", scrollOffsetToSave)
|
||||
Print("scrollIdToSave: ", scrollIdToSave)
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -224,6 +238,8 @@ struct ContentView: View {
|
|||
@State var scrollId : String?
|
||||
@State var scrollOffset: CGFloat?
|
||||
|
||||
@State var setScrollOffset: CGFloat?
|
||||
|
||||
|
||||
@Query(SegDenormRequest(book: "bible.mark")) private var segs: [SegDenorm]
|
||||
|
||||
|
@ -240,6 +256,7 @@ struct ContentView: View {
|
|||
@State var readOffset = CGPoint()
|
||||
|
||||
@State var refresh: Bool = false
|
||||
@State var refresh2: Bool = false
|
||||
|
||||
|
||||
@Query(RibbonRequest()) private var ribbons: [Ribbon]
|
||||
|
@ -258,31 +275,30 @@ struct ContentView: View {
|
|||
GeometryReader { geometry in
|
||||
ZStack{
|
||||
VStack{
|
||||
|
||||
Text("MRK")
|
||||
.font(Font.custom("AveriaSerifLibre-Regular", size: 20))
|
||||
.foregroundColor(Color.white)
|
||||
.background(Color(red: 0.3, green: 0.3, blue: 0.3))
|
||||
.overlay( MyCustomShape().frame(width: 120, height: 100).foregroundColor(.white))
|
||||
.frame(width: 120, height: 120)
|
||||
// Text("MRK")
|
||||
// .font(Font.custom("AveriaSerifLibre-Regular", size: 20))
|
||||
// .foregroundColor(Color.white)
|
||||
// .background(Color(red: 0.3, green: 0.3, blue: 0.3))
|
||||
// .overlay( MyCustomShape().frame(width: 120, height: 100).foregroundColor(.white))
|
||||
// .frame(width: 120, height: 120)
|
||||
|
||||
|
||||
Text("MTW")
|
||||
.font(Font.custom("AveriaSerifLibre-Regular", size: 20))
|
||||
.foregroundColor(Color.white)
|
||||
.overlay( MyCustomShape().frame(width: 120, height: 100))
|
||||
.frame(width: 120, height: 120)
|
||||
// Text("MTW")
|
||||
// .font(Font.custom("AveriaSerifLibre-Regular", size: 20))
|
||||
// .foregroundColor(Color.white)
|
||||
// .overlay( MyCustomShape().frame(width: 120, height: 100))
|
||||
// .frame(width: 120, height: 120)
|
||||
|
||||
|
||||
ForEach(ribbons) { ribbon in
|
||||
//ForEach(selectedRibbon) { sr in
|
||||
SwitchButton(ribbon: ribbon,
|
||||
// scrollDelegate: $scrollDelegate,
|
||||
scrollView:$thisScrollView,
|
||||
scrollUpdate:$scrollUpdate
|
||||
)
|
||||
.buttonStyle(BlueButtonStyle())
|
||||
//}
|
||||
SwitchButton(ribbon: ribbon,
|
||||
scrollId:$scrollId,
|
||||
scrollOffset:$scrollOffset,
|
||||
refresh:$refresh
|
||||
)
|
||||
.buttonStyle(BlueButtonStyle())
|
||||
Print("RIBBON")
|
||||
Print(ribbon)
|
||||
}
|
||||
}
|
||||
.frame(width: geometry.size.width, height: geometry.size.height, alignment: .topLeading)
|
||||
|
@ -318,29 +334,25 @@ struct ContentView: View {
|
|||
}
|
||||
.background(Color(red: 0.2, green: 0.2, blue: 0.2))
|
||||
}
|
||||
.onChange(of: scrollId) { target in
|
||||
if let target = target {
|
||||
.onChange(of: refresh) { target in
|
||||
//if let target = target {
|
||||
proxy.scrollTo(scrollId! , anchor: .top)
|
||||
//scrollId = nil
|
||||
|
||||
DispatchQueue.main.async {
|
||||
scrollOffset = -299
|
||||
refresh.toggle()
|
||||
setScrollOffset = scrollOffset
|
||||
refresh2.toggle()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//}
|
||||
}
|
||||
.introspectScrollView { scrollView in
|
||||
// Print("introspect")
|
||||
// scrollView.delegate = scrollDelegate
|
||||
// Print("Scroll delegate offset", scrollDelegate.scrollOffset)
|
||||
|
||||
if (scrollOffset != nil) {
|
||||
Print("Setting scroll offset")
|
||||
scrollView.contentOffset.y = scrollView.contentOffset.y + scrollOffset!
|
||||
DispatchQueue.main.async { scrollOffset = nil }
|
||||
if (setScrollOffset != nil) {
|
||||
Print("Setting scroll offset", setScrollOffset)
|
||||
scrollView.contentOffset.y = scrollView.contentOffset.y + setScrollOffset!
|
||||
DispatchQueue.main.async { setScrollOffset = nil }
|
||||
}
|
||||
|
||||
// if (thisScrollView == nil) {
|
||||
|
@ -406,6 +418,12 @@ struct ContentView: View {
|
|||
// currentOffset = tracker.visibleViews[currentId!]!
|
||||
// }
|
||||
|
||||
let visibleViews = Array(tracker.visibleViews.keys)
|
||||
if (visibleViews.count == 0) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
let currentId = Array(tracker.visibleViews.keys)[0]
|
||||
if (currentId != nil) {
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ struct Ribbon: Identifiable, Equatable {
|
|||
/// Use nil for players that are not inserted yet in the database.
|
||||
var id: Int64?
|
||||
var book: String
|
||||
var scrollId: String
|
||||
var scrollOffset: Int
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue