scroll working more
parent
65563f84fc
commit
111c6e395d
|
@ -23,13 +23,9 @@ struct SelectedRibbonRequest: Queryable {
|
||||||
|
|
||||||
/// The ordering used by the player request.
|
/// The ordering used by the player request.
|
||||||
// var ordering: Ordering
|
// var ordering: Ordering
|
||||||
var id: Int64!
|
static var defaultValue: [Ribbon] { [] }
|
||||||
|
|
||||||
// MARK: - Queryable Implementation
|
|
||||||
|
|
||||||
static var defaultValue: [SelectedRibbon] { [] }
|
func publisher(in appDatabase: AppDatabase) -> AnyPublisher<[Ribbon], Error> {
|
||||||
|
|
||||||
func publisher(in appDatabase: AppDatabase) -> AnyPublisher<[SelectedRibbon], Error> {
|
|
||||||
// Build the publisher from the general-purpose read-only access
|
// Build the publisher from the general-purpose read-only access
|
||||||
// granted by `appDatabase.reader`.
|
// granted by `appDatabase.reader`.
|
||||||
// Some apps will prefer to call a dedicated method of `appDatabase`.
|
// Some apps will prefer to call a dedicated method of `appDatabase`.
|
||||||
|
@ -45,24 +41,14 @@ struct SelectedRibbonRequest: Queryable {
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method is not required by Queryable, but it makes it easier
|
// This method is not required by Queryable, but it makes it easier
|
||||||
func fetchValue(_ db: Database) throws -> [SelectedRibbon] {
|
func fetchValue(_ db: Database) throws -> [Ribbon] {
|
||||||
if (id == nil) {
|
|
||||||
return try SelectedRibbon.fetchAll(db)
|
|
||||||
} else {
|
|
||||||
return try SelectedRibbon.filter(idColumn == id).fetchAll(db)
|
|
||||||
}
|
|
||||||
|
|
||||||
// if book == "" {
|
print("FETCH SELECTED RIBBON")
|
||||||
// return try SelectedRibbon.filter(bookColumn == SelectedRibbon.randomBook()).fetchAll(db)
|
var ret2 = try SelectedRibbon.fetchAll(db, sql: "SELECT * FROM selectedRibbon") // [Player]
|
||||||
// } else {
|
print(ret2)
|
||||||
// return try SelectedRibbon.filter(bookColumn == book).fetchAll(db)
|
print("FETCH JOIN RIBBON")
|
||||||
// }
|
var ret = try Ribbon.fetchAll(db, sql: "SELECT ribbon.* FROM selectedRibbon join ribbon on selectedRibbon.ribbonId = ribbon.rowid") // [Player]
|
||||||
// switch ordering {
|
print(ret)
|
||||||
// case .byScore:
|
return ret
|
||||||
// return try SelectedRibbon.all().fetchAll(db)
|
|
||||||
// case .byName:
|
|
||||||
// // return try SelectedRibbon.all().orderedByName().fetchAll(db)
|
|
||||||
// return try SelectedRibbon.all().fetchAll(db)
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
|
@ -101,15 +101,17 @@ extension AppDatabase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func saveSelectedRibbon(_ selectedRibbon: inout SelectedRibbon) async throws {
|
func saveSelectedRibbon(_ selectedRibbon: inout SelectedRibbon) async throws {
|
||||||
// if selectedRibbon.name.isEmpty {
|
// if ribbon.name.isEmpty {
|
||||||
// throw ValidationError.missingName
|
// throw ValidationError.missingName
|
||||||
// }
|
// }
|
||||||
selectedRibbon = try await dbWriter.write { [selectedRibbon] db in
|
try await dbWriter.write { [selectedRibbon] db in
|
||||||
try selectedRibbon.saved(db)
|
try selectedRibbon.update(db)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Create random Lines if the database is empty.
|
/// Create random Lines if the database is empty.
|
||||||
func createRandomLinesIfEmpty() throws {
|
func createRandomLinesIfEmpty() throws {
|
||||||
|
|
||||||
|
|
|
@ -130,70 +130,82 @@ struct OffsetObservingScrollView<Content: View>: View {
|
||||||
|
|
||||||
|
|
||||||
struct SwitchButton : View {
|
struct SwitchButton : View {
|
||||||
@State var ribbon: Ribbon
|
var ribbon: Ribbon
|
||||||
// @State var selectedRibbon: SelectedRibbon
|
// var selectedRibbon: SelectedRibbon
|
||||||
|
|
||||||
@Binding var book : String
|
@Binding var book : String
|
||||||
|
@Binding var scrollView : UIScrollView?
|
||||||
@Binding var scrollOffset : CGFloat
|
@Binding var scrollOffset : CGFloat
|
||||||
@Binding var readOffset: CGPoint
|
@Binding var readOffset: CGPoint
|
||||||
|
|
||||||
@Environment(\.appDatabase) private var appDatabase
|
@Environment(\.appDatabase) private var appDatabase
|
||||||
|
|
||||||
|
|
||||||
@Query(SelectedRibbonRequest()) private var sr: [SelectedRibbon]
|
@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
|
||||||
Button("meow",
|
Button(String(sr[0].id!) + " " + String(ribbon.scrollOffset),
|
||||||
action: {
|
// Button("meow",
|
||||||
Task {
|
action: {
|
||||||
var selectedRibbon = sr[0]
|
Task {
|
||||||
|
var selectedRibbon = sr[0]
|
||||||
|
Print("SELECTED RIBBON", selectedRibbon)
|
||||||
|
|
||||||
saveOffset = CGFloat(readOffset.y)
|
scrollView!.contentOffset.y = CGFloat(2000)
|
||||||
Print("save/read offset", readOffset.y)
|
|
||||||
|
|
||||||
Print("START")
|
saveOffset = CGFloat(readOffset.y)
|
||||||
_ = Print(ribbon)
|
Print("selected ribbon", selectedRibbon)
|
||||||
_ = Print(selectedRibbon)
|
Print("view ribbon", ribbon)
|
||||||
Print("START2")
|
|
||||||
|
|
||||||
if (selectedRibbon.ribbonId != ribbon.id!) {
|
if (selectedRibbon.id != ribbon.id!) {
|
||||||
Print(ribbon.id!)
|
Print("switching")
|
||||||
Print("switching")
|
book = ribbon.book
|
||||||
book = ribbon.book
|
scrollOffset = CGFloat(ribbon.scrollOffset)
|
||||||
scrollOffset = CGFloat(ribbon.scrollOffset)
|
// scrollOffset = CGFloat(1500)
|
||||||
// scrollOffset = CGFloat(1500)
|
var updateSelectRibbon = SelectedRibbon(id: Int64(1), ribbonId: ribbon.id!)
|
||||||
Print("setted offset value", scrollOffset)
|
Print("Savingg")
|
||||||
selectedRibbon.ribbonId = ribbon.id!
|
Print(updateSelectRibbon)
|
||||||
_ = try await appDatabase.saveSelectedRibbon(&selectedRibbon)
|
do {
|
||||||
_ = Print(selectedRibbon)
|
_ = try await appDatabase.saveSelectedRibbon(&updateSelectRibbon)
|
||||||
|
} catch {
|
||||||
|
Print("something wrong")
|
||||||
}
|
}
|
||||||
var editedRibbon = ribbon
|
|
||||||
editedRibbon.scrollOffset = Int(saveOffset)
|
|
||||||
Print("current ribbon offset after potential switch", editedRibbon.scrollOffset)
|
|
||||||
|
|
||||||
_ = try await appDatabase.saveRibbon(&editedRibbon)
|
|
||||||
_ = Print(editedRibbon)
|
|
||||||
|
|
||||||
Print("ribbon offset saved")
|
|
||||||
|
|
||||||
Print("set offset value", scrollOffset)
|
|
||||||
Print("read offset value", readOffset.y)
|
|
||||||
|
|
||||||
|
|
||||||
Print("END")
|
|
||||||
_ = Print(ribbon)
|
|
||||||
_ = Print(selectedRibbon)
|
|
||||||
Print("END2")
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
)
|
Print("saveOffset", saveOffset)
|
||||||
.buttonStyle(BlueButtonStyle())
|
var editedRibbon = ribbon
|
||||||
// }
|
editedRibbon.scrollOffset = Int(saveOffset)
|
||||||
|
|
||||||
|
_ = try await appDatabase.saveRibbon(&editedRibbon)
|
||||||
|
_ = Print("editedRibbon", editedRibbon)
|
||||||
|
_ = Print("ribbon", ribbon)
|
||||||
|
|
||||||
|
Print("ribbon offset saved")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
)
|
||||||
|
.buttonStyle(BlueButtonStyle())
|
||||||
|
}
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class ScrollViewHandler: NSObject {
|
||||||
|
}
|
||||||
|
|
||||||
|
extension ScrollViewHandler: UIScrollViewDelegate {
|
||||||
|
func scrollViewDidScroll(_ scrollView: UIScrollView) {
|
||||||
|
print("delegate", scrollView.contentOffset.y)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct ContentView: View {
|
struct ContentView: View {
|
||||||
|
|
||||||
@State var viewState = CGSize.zero
|
@State var viewState = CGSize.zero
|
||||||
|
@ -204,13 +216,18 @@ struct ContentView: View {
|
||||||
@State var selectedLine : Int64?
|
@State var selectedLine : Int64?
|
||||||
@State var scrollOffset = CGFloat()
|
@State var scrollOffset = CGFloat()
|
||||||
|
|
||||||
|
@State var thisScrollView : UIScrollView?
|
||||||
|
@State var initLoad = false
|
||||||
|
|
||||||
|
var scrollDelegate = ScrollViewHandler()
|
||||||
|
|
||||||
// @State var selectedRibbon: Ribbon!,
|
// @State var selectedRibbon: Ribbon!,
|
||||||
// @State var selectedRibbon: Ribbon!
|
// @State var selectedRibbon: Ribbon!
|
||||||
|
|
||||||
// @State var selectedRibbonId = Int64(UserDefaults.standard.optionalInt(forKey: "selectedRibbonId") ?? 1)
|
// @State var selectedRibbonId = Int64(UserDefaults.standard.optionalInt(forKey: "selectedRibbonId") ?? 1)
|
||||||
|
|
||||||
|
// ribbon
|
||||||
@Query(SelectedRibbonRequest()) private var selectedRibbon: [SelectedRibbon]
|
@Query(SelectedRibbonRequest()) private var selectedRibbon: [Ribbon]
|
||||||
|
|
||||||
@State var endedDrag = true
|
@State var endedDrag = true
|
||||||
|
|
||||||
|
@ -234,16 +251,18 @@ struct ContentView: View {
|
||||||
GeometryReader { geometry in
|
GeometryReader { geometry in
|
||||||
ZStack{
|
ZStack{
|
||||||
VStack{
|
VStack{
|
||||||
|
Text("cat" + String(selectedRibbon[0].id!))
|
||||||
ForEach(ribbons) { ribbon in
|
ForEach(ribbons) { ribbon in
|
||||||
ForEach(selectedRibbon) { sr in
|
//ForEach(selectedRibbon) { sr in
|
||||||
SwitchButton(ribbon: ribbon,
|
SwitchButton(ribbon: ribbon,
|
||||||
// selectedRibbon:sr,
|
|
||||||
book: $lines.book,
|
book: $lines.book,
|
||||||
|
scrollView:$thisScrollView,
|
||||||
|
// selectedRibbon:selectedRibbon[0],
|
||||||
scrollOffset: $scrollOffset,
|
scrollOffset: $scrollOffset,
|
||||||
readOffset: $readOffset
|
readOffset: $readOffset
|
||||||
)
|
)
|
||||||
.buttonStyle(BlueButtonStyle())
|
.buttonStyle(BlueButtonStyle())
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.frame(width: geometry.size.width, height: geometry.size.height, alignment: .topLeading)
|
.frame(width: geometry.size.width, height: geometry.size.height, alignment: .topLeading)
|
||||||
|
@ -252,7 +271,8 @@ struct ContentView: View {
|
||||||
// VStack (spacing: 0){
|
// VStack (spacing: 0){
|
||||||
ScrollViewReader { proxy in
|
ScrollViewReader { proxy in
|
||||||
//ScrollableView($offset, animationDuration: 0) {
|
//ScrollableView($offset, animationDuration: 0) {
|
||||||
OffsetObservingScrollView(offset: $readOffset)
|
// OffsetObservingScrollView(offset: $readOffset)
|
||||||
|
ScrollView
|
||||||
{
|
{
|
||||||
// List {
|
// List {
|
||||||
LazyVStack {
|
LazyVStack {
|
||||||
|
@ -287,10 +307,17 @@ struct ContentView: View {
|
||||||
.introspectScrollView { scrollView in
|
.introspectScrollView { scrollView in
|
||||||
//let width = scrollView.contentSize.width - scrollView.frame.width
|
//let width = scrollView.contentSize.width - scrollView.frame.width
|
||||||
//Print(scrollView.contentOffset.x)
|
//Print(scrollView.contentOffset.x)
|
||||||
// Print("here")
|
Print("introspect")
|
||||||
if (scrollOffset != scrollView.contentOffset.y) {
|
scrollView.delegate = scrollDelegate
|
||||||
scrollView.contentOffset.y = scrollOffset
|
|
||||||
|
if (thisScrollView == nil) {
|
||||||
|
thisScrollView = scrollView
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// scrollView.contentOffset.y = scrollOffset
|
||||||
|
// if (scrollOffset != scrollView.contentOffset.y) {
|
||||||
|
// scrollView.contentOffset.y = scrollOffset
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
.listStyle(PlainListStyle())
|
.listStyle(PlainListStyle())
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue