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