scroll bookmark works!
parent
111c6e395d
commit
e0f48e7841
|
@ -47,7 +47,7 @@ struct SelectedRibbonRequest: Queryable {
|
||||||
var ret2 = try SelectedRibbon.fetchAll(db, sql: "SELECT * FROM selectedRibbon") // [Player]
|
var ret2 = try SelectedRibbon.fetchAll(db, sql: "SELECT * FROM selectedRibbon") // [Player]
|
||||||
print(ret2)
|
print(ret2)
|
||||||
print("FETCH JOIN RIBBON")
|
print("FETCH JOIN RIBBON")
|
||||||
var ret = try Ribbon.fetchAll(db, sql: "SELECT ribbon.* FROM selectedRibbon join ribbon on selectedRibbon.ribbonId = ribbon.rowid") // [Player]
|
var ret = try Ribbon.fetchAll(db, sql: "SELECT ribbon.* FROM selectedRibbon join ribbon on selectedRibbon.ribbonId = ribbon.rowid WHERE selectedRibbon.rowid = 1") // [Player]
|
||||||
print(ret)
|
print(ret)
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
|
@ -15,7 +15,6 @@ let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "network
|
||||||
// var curBook = "John"
|
// var curBook = "John"
|
||||||
|
|
||||||
extension UserDefaults {
|
extension UserDefaults {
|
||||||
|
|
||||||
public func optionalInt(forKey defaultName: String) -> Int? {
|
public func optionalInt(forKey defaultName: String) -> Int? {
|
||||||
let defaults = self
|
let defaults = self
|
||||||
if let value = defaults.value(forKey: defaultName) {
|
if let value = defaults.value(forKey: defaultName) {
|
||||||
|
@ -33,27 +32,7 @@ extension UserDefaults {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension UINavigationController {
|
|
||||||
override open func viewDidLoad() {
|
|
||||||
super.viewDidLoad()
|
|
||||||
|
|
||||||
let standard = UINavigationBarAppearance()
|
|
||||||
standard.backgroundColor = .red //When you scroll or you have title (small one)
|
|
||||||
|
|
||||||
let compact = UINavigationBarAppearance()
|
|
||||||
compact.backgroundColor = .green //compact-height
|
|
||||||
|
|
||||||
let scrollEdge = UINavigationBarAppearance()
|
|
||||||
scrollEdge.backgroundColor = .blue //When you have large title
|
|
||||||
|
|
||||||
navigationBar.standardAppearance = standard
|
|
||||||
navigationBar.compactAppearance = compact
|
|
||||||
navigationBar.scrollEdgeAppearance = scrollEdge
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct BlueButtonStyle: ButtonStyle {
|
struct BlueButtonStyle: ButtonStyle {
|
||||||
|
|
||||||
func makeBody(configuration: Self.Configuration) -> some View {
|
func makeBody(configuration: Self.Configuration) -> some View {
|
||||||
configuration.label
|
configuration.label
|
||||||
.font(.headline)
|
.font(.headline)
|
||||||
|
@ -65,78 +44,12 @@ struct BlueButtonStyle: ButtonStyle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct PositionObservingView<Content: View>: View {
|
|
||||||
var coordinateSpace: CoordinateSpace
|
|
||||||
@Binding var position: CGPoint
|
|
||||||
@ViewBuilder var content: () -> Content
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
content()
|
|
||||||
.background(GeometryReader { geometry in
|
|
||||||
Color.clear.preference(
|
|
||||||
key: PreferenceKey.self,
|
|
||||||
value: geometry.frame(in: coordinateSpace).origin
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.onPreferenceChange(PreferenceKey.self) { position in
|
|
||||||
self.position = position
|
|
||||||
// Print(self.position)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private extension PositionObservingView {
|
|
||||||
struct PreferenceKey: SwiftUI.PreferenceKey {
|
|
||||||
static var defaultValue: CGPoint { .zero }
|
|
||||||
|
|
||||||
static func reduce(value: inout CGPoint, nextValue: () -> CGPoint) {
|
|
||||||
// No-op
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct OffsetObservingScrollView<Content: View>: View {
|
|
||||||
var axes: Axis.Set = [.vertical]
|
|
||||||
var showsIndicators = true
|
|
||||||
@Binding var offset: CGPoint
|
|
||||||
@ViewBuilder var content: () -> Content
|
|
||||||
|
|
||||||
// The name of our coordinate space doesn't have to be
|
|
||||||
// stable between view updates (it just needs to be
|
|
||||||
// consistent within this view), so we'll simply use a
|
|
||||||
// plain UUID for it:
|
|
||||||
private let coordinateSpaceName = UUID()
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
ScrollView(axes, showsIndicators: showsIndicators) {
|
|
||||||
PositionObservingView(
|
|
||||||
coordinateSpace: .named(coordinateSpaceName),
|
|
||||||
position: Binding(
|
|
||||||
get: { offset },
|
|
||||||
set: { newOffset in
|
|
||||||
offset = CGPoint(
|
|
||||||
x: -newOffset.x,
|
|
||||||
y: -newOffset.y
|
|
||||||
)
|
|
||||||
}
|
|
||||||
),
|
|
||||||
content: content
|
|
||||||
)
|
|
||||||
}
|
|
||||||
.coordinateSpace(name: coordinateSpaceName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
struct SwitchButton : View {
|
struct SwitchButton : View {
|
||||||
var ribbon: Ribbon
|
var ribbon: Ribbon
|
||||||
// var selectedRibbon: SelectedRibbon
|
// var selectedRibbon: SelectedRibbon
|
||||||
|
|
||||||
@Binding var book : String
|
@Binding var book : String
|
||||||
@Binding var scrollView : UIScrollView?
|
@Binding var scrollView : UIScrollView?
|
||||||
@Binding var scrollOffset : CGFloat
|
|
||||||
@Binding var readOffset: CGPoint
|
|
||||||
|
|
||||||
@Environment(\.appDatabase) private var appDatabase
|
@Environment(\.appDatabase) private var appDatabase
|
||||||
|
|
||||||
|
@ -146,23 +59,28 @@ 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.scrollOffset),
|
Button(String(sr[0].id!) + " " + String(ribbon.id!) + " " + String(ribbon.scrollOffset),
|
||||||
// Button("meow",
|
// Button("meow",
|
||||||
action: {
|
action: {
|
||||||
Task {
|
Task {
|
||||||
var selectedRibbon = sr[0]
|
var selectedRibbon = sr[0]
|
||||||
Print("SELECTED RIBBON", selectedRibbon)
|
Print("SELECTED RIBBON", selectedRibbon)
|
||||||
|
|
||||||
scrollView!.contentOffset.y = CGFloat(2000)
|
var saveScrollOffset = scrollView!.contentOffset.y
|
||||||
|
|
||||||
saveOffset = CGFloat(readOffset.y)
|
var editedRibbon = selectedRibbon
|
||||||
Print("selected ribbon", selectedRibbon)
|
editedRibbon.scrollOffset = Int(saveScrollOffset)
|
||||||
Print("view ribbon", ribbon)
|
|
||||||
|
_ = try await appDatabase.saveRibbon(&editedRibbon)
|
||||||
|
_ = Print("editedRibbon", editedRibbon)
|
||||||
|
_ = Print("ribbon", ribbon)
|
||||||
|
|
||||||
|
Print("ribbon offset saved")
|
||||||
|
|
||||||
if (selectedRibbon.id != ribbon.id!) {
|
if (selectedRibbon.id != ribbon.id!) {
|
||||||
Print("switching")
|
Print("switching")
|
||||||
book = ribbon.book
|
book = ribbon.book
|
||||||
scrollOffset = CGFloat(ribbon.scrollOffset)
|
scrollView!.contentOffset.y = CGFloat(ribbon.scrollOffset)
|
||||||
// scrollOffset = CGFloat(1500)
|
// scrollOffset = CGFloat(1500)
|
||||||
var updateSelectRibbon = SelectedRibbon(id: Int64(1), ribbonId: ribbon.id!)
|
var updateSelectRibbon = SelectedRibbon(id: Int64(1), ribbonId: ribbon.id!)
|
||||||
Print("Savingg")
|
Print("Savingg")
|
||||||
|
@ -174,15 +92,6 @@ struct SwitchButton : View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Print("saveOffset", saveOffset)
|
|
||||||
var editedRibbon = ribbon
|
|
||||||
editedRibbon.scrollOffset = Int(saveOffset)
|
|
||||||
|
|
||||||
_ = try await appDatabase.saveRibbon(&editedRibbon)
|
|
||||||
_ = Print("editedRibbon", editedRibbon)
|
|
||||||
_ = Print("ribbon", ribbon)
|
|
||||||
|
|
||||||
Print("ribbon offset saved")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,10 +165,7 @@ struct ContentView: View {
|
||||||
//ForEach(selectedRibbon) { sr in
|
//ForEach(selectedRibbon) { sr in
|
||||||
SwitchButton(ribbon: ribbon,
|
SwitchButton(ribbon: ribbon,
|
||||||
book: $lines.book,
|
book: $lines.book,
|
||||||
scrollView:$thisScrollView,
|
scrollView:$thisScrollView
|
||||||
// selectedRibbon:selectedRibbon[0],
|
|
||||||
scrollOffset: $scrollOffset,
|
|
||||||
readOffset: $readOffset
|
|
||||||
)
|
)
|
||||||
.buttonStyle(BlueButtonStyle())
|
.buttonStyle(BlueButtonStyle())
|
||||||
//}
|
//}
|
||||||
|
@ -312,6 +218,7 @@ struct ContentView: View {
|
||||||
|
|
||||||
if (thisScrollView == nil) {
|
if (thisScrollView == nil) {
|
||||||
thisScrollView = scrollView
|
thisScrollView = scrollView
|
||||||
|
scrollView.contentOffset.y = CGFloat(selectedRibbon[0].scrollOffset)
|
||||||
}
|
}
|
||||||
|
|
||||||
// scrollView.contentOffset.y = scrollOffset
|
// scrollView.contentOffset.y = scrollOffset
|
||||||
|
|
Loading…
Reference in New Issue