building and jumps working now
using observed object instead of binding works actuallyundo
parent
3a7c83c2d9
commit
ae49a5cbfe
|
@ -77,7 +77,7 @@ struct SegRow: View {
|
||||||
|
|
||||||
|
|
||||||
struct Pane: View {
|
struct Pane: View {
|
||||||
@State var paneConnector = PaneConnector()
|
@ObservedObject var paneConnector: PaneConnector
|
||||||
|
|
||||||
@State var segs: [SegDenorm]
|
@State var segs: [SegDenorm]
|
||||||
@State var selectedRibbon: [Ribbon]
|
@State var selectedRibbon: [Ribbon]
|
||||||
|
@ -95,7 +95,7 @@ struct Pane: View {
|
||||||
|
|
||||||
// var handleVisibilityChanged: (String, VisibilityChange, VisibilityTracker<String>) -> Void
|
// var handleVisibilityChanged: (String, VisibilityChange, VisibilityTracker<String>) -> Void
|
||||||
|
|
||||||
var body: some View {
|
var body: some View{
|
||||||
ScrollViewReader { proxy in
|
ScrollViewReader { proxy in
|
||||||
VisibilityTrackingScrollView(action: handleVisibilityChanged) {
|
VisibilityTrackingScrollView(action: handleVisibilityChanged) {
|
||||||
LazyVStack {
|
LazyVStack {
|
||||||
|
@ -115,11 +115,12 @@ struct Pane: View {
|
||||||
goToRibbon(selectedRibbon: selectedRibbon[0],
|
goToRibbon(selectedRibbon: selectedRibbon[0],
|
||||||
destRibbon: selectedRibbon[0],
|
destRibbon: selectedRibbon[0],
|
||||||
appDatabase: appDatabase,
|
appDatabase: appDatabase,
|
||||||
paneConnector: $paneConnector,
|
paneConnector: paneConnector,
|
||||||
refresh: $refresh,
|
refresh: $refresh,
|
||||||
loading: true)
|
loading: true)
|
||||||
}
|
}
|
||||||
.onChange(of: paneConnector.refresh) { _ in
|
.onChange(of: paneConnector.refresh) { _ in
|
||||||
|
print("inside change")
|
||||||
print("on change")
|
print("on change")
|
||||||
|
|
||||||
Task {
|
Task {
|
||||||
|
|
|
@ -42,50 +42,60 @@ public extension UserDefaults {
|
||||||
func goToRibbon(selectedRibbon: Ribbon,
|
func goToRibbon(selectedRibbon: Ribbon,
|
||||||
destRibbon: Ribbon,
|
destRibbon: Ribbon,
|
||||||
appDatabase: AppDatabase,
|
appDatabase: AppDatabase,
|
||||||
paneConnector: Binding<PaneConnector>,
|
paneConnector: PaneConnector,
|
||||||
refresh: Binding<Bool>,
|
refresh: Binding<Bool>,
|
||||||
loading: Bool)
|
loading: Bool)
|
||||||
{
|
{
|
||||||
Task {
|
|
||||||
var scrollOffsetToSave = paneConnector.wrappedValue.currentOffset
|
|
||||||
var scrollIdToSave = paneConnector.wrappedValue.currentId
|
|
||||||
|
|
||||||
var updatedRibbon = selectedRibbon
|
DispatchQueue.main.asyncAfter(deadline: .now()) {
|
||||||
|
Task {
|
||||||
|
var scrollOffsetToSave = paneConnector.currentOffset
|
||||||
|
var scrollIdToSave = paneConnector.currentId
|
||||||
|
|
||||||
if selectedRibbon.id != destRibbon.id! || loading {
|
var updatedRibbon = selectedRibbon
|
||||||
print("switching ribbons")
|
print("go to ribbon")
|
||||||
|
print("\(selectedRibbon.id) \(destRibbon.id!)")
|
||||||
|
|
||||||
paneConnector.wrappedValue.showOverlay = true
|
if selectedRibbon.id != destRibbon.id! || loading {
|
||||||
|
print("switching ribbons")
|
||||||
|
|
||||||
if loading {
|
paneConnector.showOverlay = true
|
||||||
paneConnector.wrappedValue.currentId = destRibbon.scrollId
|
|
||||||
|
if loading {
|
||||||
|
paneConnector.currentId = destRibbon.scrollId
|
||||||
|
}
|
||||||
|
|
||||||
|
paneConnector.scrollId = destRibbon.scrollId
|
||||||
|
paneConnector.scrollOffset = CGFloat(destRibbon.scrollOffset)
|
||||||
|
paneConnector.refresh.toggle()
|
||||||
|
|
||||||
|
print("toggling")
|
||||||
|
print("paneconnector: \(paneConnector.refresh)")
|
||||||
|
|
||||||
|
refresh.wrappedValue.toggle()
|
||||||
|
|
||||||
|
var updateSelectRibbon = SelectedRibbon(id: Int64(1), ribbonId: destRibbon.id!)
|
||||||
|
// print("Saving selected ribbon")
|
||||||
|
// print(updateSelectRibbon)
|
||||||
|
do {
|
||||||
|
_ = try await appDatabase.saveSelectedRibbon(&updateSelectRibbon)
|
||||||
|
} catch {
|
||||||
|
// Print("something wrong")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
paneConnector.wrappedValue.scrollId = destRibbon.scrollId
|
if !loading {
|
||||||
paneConnector.wrappedValue.scrollOffset = CGFloat(destRibbon.scrollOffset)
|
print("not loading")
|
||||||
paneConnector.wrappedValue.refresh.toggle()
|
updatedRibbon.scrollOffset = Int(floor(scrollOffsetToSave))
|
||||||
|
updatedRibbon.scrollId = scrollIdToSave
|
||||||
|
_ = try await appDatabase.saveRibbon(&updatedRibbon)
|
||||||
|
|
||||||
var updateSelectRibbon = SelectedRibbon(id: Int64(1), ribbonId: destRibbon.id!)
|
} else {
|
||||||
// print("Saving selected ribbon")
|
print("loading")
|
||||||
// print(updateSelectRibbon)
|
|
||||||
do {
|
|
||||||
_ = try await appDatabase.saveSelectedRibbon(&updateSelectRibbon)
|
|
||||||
} catch {
|
|
||||||
// Print("something wrong")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !loading {
|
|
||||||
print("not loading")
|
|
||||||
updatedRibbon.scrollOffset = Int(floor(scrollOffsetToSave))
|
|
||||||
updatedRibbon.scrollId = scrollIdToSave
|
|
||||||
_ = try await appDatabase.saveRibbon(&updatedRibbon)
|
|
||||||
|
|
||||||
} else {
|
|
||||||
print("loading")
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension View {
|
extension View {
|
||||||
|
@ -98,7 +108,7 @@ extension View {
|
||||||
|
|
||||||
struct RibbonCrown: View {
|
struct RibbonCrown: View {
|
||||||
var ribbon: Ribbon
|
var ribbon: Ribbon
|
||||||
@Binding var paneConnector: PaneConnector
|
@ObservedObject var paneConnector: PaneConnector
|
||||||
var draggedRibbon: Ribbon?
|
var draggedRibbon: Ribbon?
|
||||||
var isDragging: Bool
|
var isDragging: Bool
|
||||||
|
|
||||||
|
@ -142,7 +152,7 @@ struct RibbonCrown: View {
|
||||||
goToRibbon(selectedRibbon: sr[0],
|
goToRibbon(selectedRibbon: sr[0],
|
||||||
destRibbon: ribbon,
|
destRibbon: ribbon,
|
||||||
appDatabase: appDatabase,
|
appDatabase: appDatabase,
|
||||||
paneConnector: $paneConnector,
|
paneConnector: paneConnector,
|
||||||
refresh: $refresh,
|
refresh: $refresh,
|
||||||
loading: false)
|
loading: false)
|
||||||
}
|
}
|
||||||
|
@ -175,53 +185,18 @@ func makeVerseView(seg: SegDenorm) -> some View {
|
||||||
return retView
|
return retView
|
||||||
}
|
}
|
||||||
|
|
||||||
class PaneConnector: NSObject, NSCopying {
|
class PaneConnector: NSObject, ObservableObject {
|
||||||
// var scrollId: String
|
// var scrollId: String
|
||||||
// var scrollOffset: CGFloat
|
// var scrollOffset: CGFloat
|
||||||
// var setScrollOffset: CGFloat
|
// var setScrollOffset: CGFloat
|
||||||
var showOverlay: Bool = false
|
var showOverlay: Bool = false
|
||||||
var refresh: Bool = false
|
@Published var refresh: Bool = false
|
||||||
var currentId = ""
|
var currentId = ""
|
||||||
var currentOffset = CGFloat()
|
var currentOffset = CGFloat()
|
||||||
var visibilityTracker: VisibilityTracker<String>?
|
var visibilityTracker: VisibilityTracker<String>?
|
||||||
var scrollId = ""
|
var scrollId = ""
|
||||||
var scrollOffset = CGFloat()
|
var scrollOffset = CGFloat()
|
||||||
var setScrollOffset: CGFloat?
|
var setScrollOffset: CGFloat?
|
||||||
|
|
||||||
required override init() {}
|
|
||||||
|
|
||||||
// convenience init(showOverlay _: Bool, refresh _: Bool, currentId _: String,
|
|
||||||
// currentOffset _: CGFloat, visibilityTracker _: VisibilityTracker<String>?, scrollId _: String,
|
|
||||||
// scrollOffset _: CGFloat, setScrollOffset _: CGFloat) {
|
|
||||||
// self.init()
|
|
||||||
|
|
||||||
// self.showOverlay = showOverlay
|
|
||||||
// self.refresh = refresh
|
|
||||||
// self.currentId = currentId
|
|
||||||
// self.currentOffset = currentOffset
|
|
||||||
// self.visibilityTracker = visibilityTracker
|
|
||||||
// self.scrollId = scrollId
|
|
||||||
// self.scrollOffset = scrollOffset
|
|
||||||
// self.setScrollOffset = setScrollOffset
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func copy(with _: NSZone? = nil) -> Any {
|
|
||||||
// let item = PaneConnector(
|
|
||||||
// return item
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
func copy(with _: NSZone? = nil) -> Any {
|
|
||||||
let item = type(of: self).init()
|
|
||||||
item.showOverlay = showOverlay
|
|
||||||
item.refresh = refresh
|
|
||||||
item.currentId = currentId
|
|
||||||
item.currentOffset = currentOffset
|
|
||||||
item.visibilityTracker = visibilityTracker
|
|
||||||
item.scrollId = scrollId
|
|
||||||
item.setScrollOffset = setScrollOffset
|
|
||||||
return item
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ContentView: View {
|
struct ContentView: View {
|
||||||
|
@ -229,7 +204,7 @@ struct ContentView: View {
|
||||||
@State var viewState = CGSize.zero
|
@State var viewState = CGSize.zero
|
||||||
@State var pulledOut = CGSize.zero
|
@State var pulledOut = CGSize.zero
|
||||||
|
|
||||||
@State var paneConnector = PaneConnector()
|
@StateObject var paneConnector = PaneConnector()
|
||||||
|
|
||||||
@State var refresh: Bool = false
|
@State var refresh: Bool = false
|
||||||
|
|
||||||
|
@ -270,7 +245,7 @@ struct ContentView: View {
|
||||||
VStack {
|
VStack {
|
||||||
ForEach(ribbons) { ribbon in
|
ForEach(ribbons) { ribbon in
|
||||||
RibbonCrown(ribbon: ribbon,
|
RibbonCrown(ribbon: ribbon,
|
||||||
paneConnector: $paneConnector,
|
paneConnector: paneConnector,
|
||||||
draggedRibbon: draggedRibbon,
|
draggedRibbon: draggedRibbon,
|
||||||
isDragging: isDragging,
|
isDragging: isDragging,
|
||||||
refresh: $refresh)
|
refresh: $refresh)
|
||||||
|
@ -297,14 +272,12 @@ struct ContentView: View {
|
||||||
.frame(alignment: .topLeading)
|
.frame(alignment: .topLeading)
|
||||||
|
|
||||||
VStack {
|
VStack {
|
||||||
// Top pane
|
// Top pane
|
||||||
Pane(paneConnector: paneConnector,
|
Pane(paneConnector: paneConnector,
|
||||||
segs: segs,
|
segs: segs,
|
||||||
selectedRibbon: selectedRibbon,
|
selectedRibbon: selectedRibbon,
|
||||||
width: geometry.size.width - 50,
|
width: geometry.size.width - 50,
|
||||||
height: geometry.size.height / 2 - vertSep
|
height: geometry.size.height / 2 - vertSep)
|
||||||
)
|
|
||||||
|
|
||||||
//////
|
//////
|
||||||
|
|
||||||
Text("separator").foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00)))
|
Text("separator").foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00)))
|
||||||
|
@ -410,6 +383,10 @@ struct ContentView: View {
|
||||||
// .zIndex(2)
|
// .zIndex(2)
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.onChange(of: paneConnector.refresh) { _ in
|
||||||
|
Print("we changing changing")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue