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 {
|
||||
@State var paneConnector = PaneConnector()
|
||||
@ObservedObject var paneConnector: PaneConnector
|
||||
|
||||
@State var segs: [SegDenorm]
|
||||
@State var selectedRibbon: [Ribbon]
|
||||
|
@ -95,7 +95,7 @@ struct Pane: View {
|
|||
|
||||
// var handleVisibilityChanged: (String, VisibilityChange, VisibilityTracker<String>) -> Void
|
||||
|
||||
var body: some View {
|
||||
var body: some View{
|
||||
ScrollViewReader { proxy in
|
||||
VisibilityTrackingScrollView(action: handleVisibilityChanged) {
|
||||
LazyVStack {
|
||||
|
@ -115,11 +115,12 @@ struct Pane: View {
|
|||
goToRibbon(selectedRibbon: selectedRibbon[0],
|
||||
destRibbon: selectedRibbon[0],
|
||||
appDatabase: appDatabase,
|
||||
paneConnector: $paneConnector,
|
||||
paneConnector: paneConnector,
|
||||
refresh: $refresh,
|
||||
loading: true)
|
||||
}
|
||||
.onChange(of: paneConnector.refresh) { _ in
|
||||
print("inside change")
|
||||
print("on change")
|
||||
|
||||
Task {
|
||||
|
|
|
@ -42,28 +42,37 @@ public extension UserDefaults {
|
|||
func goToRibbon(selectedRibbon: Ribbon,
|
||||
destRibbon: Ribbon,
|
||||
appDatabase: AppDatabase,
|
||||
paneConnector: Binding<PaneConnector>,
|
||||
paneConnector: PaneConnector,
|
||||
refresh: Binding<Bool>,
|
||||
loading: Bool)
|
||||
{
|
||||
|
||||
DispatchQueue.main.asyncAfter(deadline: .now()) {
|
||||
Task {
|
||||
var scrollOffsetToSave = paneConnector.wrappedValue.currentOffset
|
||||
var scrollIdToSave = paneConnector.wrappedValue.currentId
|
||||
var scrollOffsetToSave = paneConnector.currentOffset
|
||||
var scrollIdToSave = paneConnector.currentId
|
||||
|
||||
var updatedRibbon = selectedRibbon
|
||||
print("go to ribbon")
|
||||
print("\(selectedRibbon.id) \(destRibbon.id!)")
|
||||
|
||||
if selectedRibbon.id != destRibbon.id! || loading {
|
||||
print("switching ribbons")
|
||||
|
||||
paneConnector.wrappedValue.showOverlay = true
|
||||
paneConnector.showOverlay = true
|
||||
|
||||
if loading {
|
||||
paneConnector.wrappedValue.currentId = destRibbon.scrollId
|
||||
paneConnector.currentId = destRibbon.scrollId
|
||||
}
|
||||
|
||||
paneConnector.wrappedValue.scrollId = destRibbon.scrollId
|
||||
paneConnector.wrappedValue.scrollOffset = CGFloat(destRibbon.scrollOffset)
|
||||
paneConnector.wrappedValue.refresh.toggle()
|
||||
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")
|
||||
|
@ -84,8 +93,9 @@ func goToRibbon(selectedRibbon: Ribbon,
|
|||
} else {
|
||||
print("loading")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension View {
|
||||
|
@ -98,7 +108,7 @@ extension View {
|
|||
|
||||
struct RibbonCrown: View {
|
||||
var ribbon: Ribbon
|
||||
@Binding var paneConnector: PaneConnector
|
||||
@ObservedObject var paneConnector: PaneConnector
|
||||
var draggedRibbon: Ribbon?
|
||||
var isDragging: Bool
|
||||
|
||||
|
@ -142,7 +152,7 @@ struct RibbonCrown: View {
|
|||
goToRibbon(selectedRibbon: sr[0],
|
||||
destRibbon: ribbon,
|
||||
appDatabase: appDatabase,
|
||||
paneConnector: $paneConnector,
|
||||
paneConnector: paneConnector,
|
||||
refresh: $refresh,
|
||||
loading: false)
|
||||
}
|
||||
|
@ -175,53 +185,18 @@ func makeVerseView(seg: SegDenorm) -> some View {
|
|||
return retView
|
||||
}
|
||||
|
||||
class PaneConnector: NSObject, NSCopying {
|
||||
class PaneConnector: NSObject, ObservableObject {
|
||||
// var scrollId: String
|
||||
// var scrollOffset: CGFloat
|
||||
// var setScrollOffset: CGFloat
|
||||
var showOverlay: Bool = false
|
||||
var refresh: Bool = false
|
||||
@Published var refresh: Bool = false
|
||||
var currentId = ""
|
||||
var currentOffset = CGFloat()
|
||||
var visibilityTracker: VisibilityTracker<String>?
|
||||
var scrollId = ""
|
||||
var scrollOffset = 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 {
|
||||
|
@ -229,7 +204,7 @@ struct ContentView: View {
|
|||
@State var viewState = CGSize.zero
|
||||
@State var pulledOut = CGSize.zero
|
||||
|
||||
@State var paneConnector = PaneConnector()
|
||||
@StateObject var paneConnector = PaneConnector()
|
||||
|
||||
@State var refresh: Bool = false
|
||||
|
||||
|
@ -270,7 +245,7 @@ struct ContentView: View {
|
|||
VStack {
|
||||
ForEach(ribbons) { ribbon in
|
||||
RibbonCrown(ribbon: ribbon,
|
||||
paneConnector: $paneConnector,
|
||||
paneConnector: paneConnector,
|
||||
draggedRibbon: draggedRibbon,
|
||||
isDragging: isDragging,
|
||||
refresh: $refresh)
|
||||
|
@ -302,9 +277,7 @@ struct ContentView: View {
|
|||
segs: segs,
|
||||
selectedRibbon: selectedRibbon,
|
||||
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)))
|
||||
|
@ -410,6 +383,10 @@ struct ContentView: View {
|
|||
// .zIndex(2)
|
||||
// }
|
||||
}
|
||||
|
||||
.onChange(of: paneConnector.refresh) { _ in
|
||||
Print("we changing changing")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue