builds
parent
1275ad4f96
commit
3746682941
113
Fenestra.swift
113
Fenestra.swift
|
@ -76,14 +76,16 @@ struct SegRow: View {
|
|||
}
|
||||
|
||||
|
||||
// struct Fenestra: View {
|
||||
// struct Pane: View {
|
||||
// @State var paneConnector = PaneConnector()
|
||||
|
||||
// @State var segs: [SegDenorm]
|
||||
// @State var selectedRibbon: [Ribbon]
|
||||
|
||||
// @State var dragOffset = CGFloat()
|
||||
|
||||
// @State var refresh: Bool = false
|
||||
// @State var refresh2: Bool = false
|
||||
|
||||
|
||||
// // var handleVisibilityChanged: (String, VisibilityChange, VisibilityTracker<String>) -> Void
|
||||
|
||||
|
@ -104,7 +106,6 @@ struct SegRow: View {
|
|||
// }
|
||||
|
||||
// .onAppear {
|
||||
// Print("APPEAR")
|
||||
// goToRibbon(selectedRibbon: selectedRibbon[0],
|
||||
// destRibbon: selectedRibbon[0],
|
||||
// scrollId: $scrollId,
|
||||
|
@ -112,32 +113,42 @@ struct SegRow: View {
|
|||
// refresh: $refresh,
|
||||
// showOverlay: $showOverlay,
|
||||
// appDatabase: appDatabase,
|
||||
// paneConnector: $paneConnector,
|
||||
// loading: true)
|
||||
// }
|
||||
// .onChange(of: refresh) { _ in
|
||||
// .onChange(of: paneConnector.refresh) { _ in
|
||||
|
||||
// Task {
|
||||
// DispatchQueue.main.async {
|
||||
// Print("scroll Id target: \(scrollId)")
|
||||
// proxy.scrollTo(scrollId!, anchor: .top)
|
||||
// let gTracker = paneConnector.visibilityTracker!
|
||||
|
||||
// Print("scroll Id target: \(paneConnector.scrollId)")
|
||||
// proxy.scrollTo(paneConnector.scrollId, anchor: .top)
|
||||
|
||||
// DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
|
||||
// Print(" scroll id target", scrollId)
|
||||
// Print(" current id ", currentId)
|
||||
// Print(gTracker!.sortedViewIDs)
|
||||
// if currentId! != scrollId! {
|
||||
// Print(" scroll id target", paneConnector.scrollId)
|
||||
// Print(" current id ", paneConnector.currentId)
|
||||
// Print(gTracker.sortedViewIDs)
|
||||
// if paneConnector.currentId != paneConnector.scrollId {
|
||||
// Print("NO MATCH")
|
||||
// }
|
||||
|
||||
// Print(" current offset ", gTracker!.visibleViews[scrollId!])
|
||||
// var curOffset = gTracker!.visibleViews[scrollId!]
|
||||
// Print(" stats", gTracker!.visibleViews)
|
||||
// Print(" current offset ", gTracker.visibleViews[paneConnector.scrollId])
|
||||
// var curOffset = gTracker.visibleViews[paneConnector.scrollId]
|
||||
// Print(" stats", gTracker.visibleViews)
|
||||
// if curOffset != nil {
|
||||
// setScrollOffset = CGFloat(Int(scrollOffset!) - Int(curOffset!))
|
||||
// paneConnector.setScrollOffset = CGFloat(Int(paneConnector.scrollOffset) - Int(curOffset!))
|
||||
// // setScrollOffset = CGFloat(Int(paneConnector.scrollOffset) - Int(curOffset!))
|
||||
// // setScrollOffset = CGFloat(Int(paneConnector.scrollOffset) - Int(curOffset!))
|
||||
// Print("applying scroll offset \(setScrollOffset)")
|
||||
// refresh2.toggle()
|
||||
// Print("applying scroll offset \(paneConnector.setScrollOffset)")
|
||||
|
||||
// // paneConnector = paneConnector.copy() as! PaneConnector
|
||||
// self.refresh.toggle()
|
||||
// } else {
|
||||
// var adjust = (Int(scrollId!)! - Int(currentId!)!) * 200
|
||||
// var adjust = (Int(paneConnector.scrollId)! - Int(paneConnector.currentId)!) * 200
|
||||
// Print("adjusting \(adjust)")
|
||||
|
||||
// setScrollOffset = CGFloat(adjust)
|
||||
// refresh.toggle()
|
||||
// }
|
||||
|
@ -145,62 +156,44 @@ struct SegRow: View {
|
|||
// }
|
||||
// }
|
||||
// }
|
||||
// .introspect(.scrollView, on: .iOS(.v13, .v14, .v15, .v16, .v17)) { scrollView in Print("introspect")
|
||||
// if setScrollOffset != nil {
|
||||
// .introspect(.scrollView, on: .iOS(.v13, .v14, .v15, .v16, .v17)) { scrollView in
|
||||
// Print("introspect")
|
||||
|
||||
// // Weird hack for reactivity
|
||||
// if self.refresh {
|
||||
// let reactive = self.refresh
|
||||
// }
|
||||
|
||||
// // if self.paneConnector != nil {
|
||||
// // let reactive = self.paneConnector
|
||||
// // }
|
||||
|
||||
// if paneConnector.setScrollOffset != nil {
|
||||
// DispatchQueue.main.async {
|
||||
// scrollView.contentOffset.y = scrollView.contentOffset.y + setScrollOffset!
|
||||
// setScrollOffset = nil
|
||||
// withAnimation {
|
||||
// showOverlay = false
|
||||
// scrollView.contentOffset.y = scrollView.contentOffset.y + paneConnector.setScrollOffset!
|
||||
// paneConnector.setScrollOffset = nil
|
||||
|
||||
// withAnimation(.easeIn(duration: 0.2)) {
|
||||
// paneConnector.showOverlay = false
|
||||
// self.refresh.toggle()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// Print("end introspect")
|
||||
// }
|
||||
// .listStyle(PlainListStyle())
|
||||
// }
|
||||
// .zIndex(1)
|
||||
// .background(Color(red: 0.2, green: 0.2, blue: 0.2))
|
||||
// .frame(width: geometry.size.width - 50, height: geometry.size.height / 2 - vertSep)
|
||||
// .offset(x: 30, y: 0)
|
||||
// .offset(x: pulledOut.width)
|
||||
// .offset(x: viewState.width, y: viewState.height)
|
||||
// .gesture(
|
||||
// DragGesture()
|
||||
// .onChanged { gesture in
|
||||
|
||||
// if endedDrag {
|
||||
// endedDrag = false
|
||||
// scrollOffset = readOffset.y - 20
|
||||
// }
|
||||
// Print(viewState.width)
|
||||
// if abs(gesture.translation.width) > 20 {
|
||||
// viewState.width = gesture.translation.width
|
||||
// if gesture.translation.width < -50, pulledOut.width == CGFloat(0) {
|
||||
// dragOffset = gesture.translation.width + 50
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// .onEnded { _ in
|
||||
// endedDrag = true
|
||||
// var pulledOutWidth = CGFloat(0)
|
||||
// if viewState.width < 0 {
|
||||
// pulledOutWidth = CGFloat(0)
|
||||
// } else if abs(viewState.width + pulledOut.width) > 30 {
|
||||
// pulledOutWidth = CGFloat(200)
|
||||
// }
|
||||
|
||||
// withAnimation(.spring(response: 0.2)) {
|
||||
// pulledOut.width = pulledOutWidth
|
||||
// viewState = .zero
|
||||
// dragOffset = .zero
|
||||
// }
|
||||
// }
|
||||
// )
|
||||
// }
|
||||
|
||||
// func handleVisibilityChanged(_: String, change _: VisibilityChange, tracker: VisibilityTracker<String>) {
|
||||
// // var printRate: Int64 = 10
|
||||
// gTracker = tracker
|
||||
// // gTracker = tracker
|
||||
// self.paneConnector.visibilityTracker = tracker
|
||||
|
||||
|
||||
// let visibleViews2 = Array(tracker.visibleViews.keys)
|
||||
// if visibleViews2.count == 0 {
|
||||
|
@ -210,7 +203,11 @@ struct SegRow: View {
|
|||
// // currentId = tracker.sortedViewIDs[tracker.sortedViewIDs.count - 1]
|
||||
// currentId = tracker.sortedViewIDs[0]
|
||||
// currentOffset = tracker.visibleViews[currentId!]!
|
||||
|
||||
// self.paneConnector.currentId = tracker.sortedViewIDs[0]
|
||||
// self.paneConnector.currentOffset = tracker.visibleViews[currentId!]!
|
||||
// }
|
||||
|
||||
|
||||
// }
|
||||
|
||||
|
|
|
@ -41,10 +41,6 @@ public extension UserDefaults {
|
|||
|
||||
func goToRibbon(selectedRibbon: Ribbon,
|
||||
destRibbon: Ribbon,
|
||||
scrollId: Binding<String?>,
|
||||
scrollOffset: Binding<CGFloat?>,
|
||||
refresh: Binding<Bool>,
|
||||
showOverlay: Binding<Bool>,
|
||||
appDatabase: AppDatabase,
|
||||
paneConnector: Binding<PaneConnector>,
|
||||
loading: Bool)
|
||||
|
@ -59,7 +55,6 @@ func goToRibbon(selectedRibbon: Ribbon,
|
|||
print("switching ribbons")
|
||||
|
||||
paneConnector.wrappedValue.showOverlay = true
|
||||
showOverlay.wrappedValue = true
|
||||
|
||||
if loading {
|
||||
paneConnector.wrappedValue.currentId = destRibbon.scrollId
|
||||
|
@ -102,10 +97,6 @@ extension View {
|
|||
|
||||
struct RibbonCrown: View {
|
||||
var ribbon: Ribbon
|
||||
@Binding var scrollId: String?
|
||||
@Binding var scrollOffset: CGFloat?
|
||||
@Binding var showOverlay: Bool
|
||||
@Binding var refresh: Bool
|
||||
@Binding var paneConnector: PaneConnector
|
||||
var draggedRibbon: Ribbon?
|
||||
var isDragging: Bool
|
||||
|
@ -147,10 +138,6 @@ struct RibbonCrown: View {
|
|||
Task {
|
||||
goToRibbon(selectedRibbon: sr[0],
|
||||
destRibbon: ribbon,
|
||||
scrollId: $scrollId,
|
||||
scrollOffset: $scrollOffset,
|
||||
refresh: $refresh,
|
||||
showOverlay: $showOverlay,
|
||||
appDatabase: appDatabase,
|
||||
paneConnector: $paneConnector,
|
||||
loading: false)
|
||||
|
@ -184,7 +171,7 @@ func makeVerseView(seg: SegDenorm) -> some View {
|
|||
return retView
|
||||
}
|
||||
|
||||
class PaneConnector: NSObject {
|
||||
class PaneConnector: NSObject, NSCopying {
|
||||
// var scrollId: String
|
||||
// var scrollOffset: CGFloat
|
||||
// var setScrollOffset: CGFloat
|
||||
|
@ -196,7 +183,42 @@ class PaneConnector: NSObject {
|
|||
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 {
|
||||
// this is for the whole view swiping
|
||||
|
@ -206,29 +228,28 @@ struct ContentView: View {
|
|||
@State var paneConnector = PaneConnector()
|
||||
|
||||
// scroll location of the main Pane
|
||||
@State var scrollId: String?
|
||||
@State var scrollOffset: CGFloat?
|
||||
@State var setScrollOffset: CGFloat?
|
||||
@State var foocat = "meow"
|
||||
@State var showOverlay: Bool = false
|
||||
// @State var scrollId: String?
|
||||
// @State var scrollOffset: CGFloat?
|
||||
// @State var setScrollOffset: CGFloat?
|
||||
// @State var showOverlay: Bool = false
|
||||
|
||||
@State var refresh: Bool = false
|
||||
@State var refresh3: Bool = false
|
||||
|
||||
@State var vertSep = CGFloat(20)
|
||||
|
||||
|
||||
@State var endedDrag = true
|
||||
|
||||
@State var readOffset = CGPoint()
|
||||
@State var dragOffset = CGFloat()
|
||||
|
||||
@State var refresh2: Bool = false
|
||||
|
||||
@State var draggedRibbon: Ribbon?
|
||||
@State var isDragging = false
|
||||
|
||||
@Environment(\.appDatabase) private var appDatabase
|
||||
|
||||
@Query(SegDenormRequest(book: "bible.mark")) private var segs: [SegDenorm]
|
||||
|
||||
@Query(RibbonRequest()) private var ribbons: [Ribbon]
|
||||
@Query<SelectedRibbonRequest> var selectedRibbon: [Ribbon]
|
||||
|
||||
|
@ -251,10 +272,6 @@ struct ContentView: View {
|
|||
VStack {
|
||||
ForEach(ribbons) { ribbon in
|
||||
RibbonCrown(ribbon: ribbon,
|
||||
scrollId: $scrollId,
|
||||
scrollOffset: $scrollOffset,
|
||||
showOverlay: $showOverlay,
|
||||
refresh: $refresh,
|
||||
paneConnector: $paneConnector,
|
||||
draggedRibbon: draggedRibbon,
|
||||
isDragging: isDragging)
|
||||
|
@ -281,6 +298,7 @@ struct ContentView: View {
|
|||
.frame(alignment: .topLeading)
|
||||
|
||||
VStack {
|
||||
// Top pane
|
||||
ScrollViewReader { proxy in
|
||||
VisibilityTrackingScrollView(action: handleVisibilityChanged) {
|
||||
LazyVStack {
|
||||
|
@ -299,10 +317,6 @@ struct ContentView: View {
|
|||
.onAppear {
|
||||
goToRibbon(selectedRibbon: selectedRibbon[0],
|
||||
destRibbon: selectedRibbon[0],
|
||||
scrollId: $scrollId,
|
||||
scrollOffset: $scrollOffset,
|
||||
refresh: $refresh,
|
||||
showOverlay: $showOverlay,
|
||||
appDatabase: appDatabase,
|
||||
paneConnector: $paneConnector,
|
||||
loading: true)
|
||||
|
@ -331,15 +345,15 @@ struct ContentView: View {
|
|||
paneConnector.setScrollOffset = CGFloat(Int(paneConnector.scrollOffset) - Int(curOffset!))
|
||||
// setScrollOffset = CGFloat(Int(paneConnector.scrollOffset) - Int(curOffset!))
|
||||
// setScrollOffset = CGFloat(Int(paneConnector.scrollOffset) - Int(curOffset!))
|
||||
Print("applying scroll offset \(setScrollOffset)")
|
||||
Print("applying scroll offset \(paneConnector.setScrollOffset)")
|
||||
Print("applying scroll offset2 \(foocat)")
|
||||
|
||||
// paneConnector = paneConnector.copy() as! PaneConnector
|
||||
self.refresh.toggle()
|
||||
} else {
|
||||
var adjust = (Int(paneConnector.scrollId)! - Int(paneConnector.currentId)!) * 200
|
||||
Print("adjusting \(adjust)")
|
||||
|
||||
setScrollOffset = CGFloat(adjust)
|
||||
paneConnector.setScrollOffset = CGFloat(adjust)
|
||||
refresh.toggle()
|
||||
}
|
||||
}
|
||||
|
@ -354,6 +368,10 @@ struct ContentView: View {
|
|||
let reactive = self.refresh
|
||||
}
|
||||
|
||||
// if self.paneConnector != nil {
|
||||
// let reactive = self.paneConnector
|
||||
// }
|
||||
|
||||
if paneConnector.setScrollOffset != nil {
|
||||
DispatchQueue.main.async {
|
||||
scrollView.contentOffset.y = scrollView.contentOffset.y + paneConnector.setScrollOffset!
|
||||
|
@ -374,6 +392,8 @@ struct ContentView: View {
|
|||
.background(Color(red: 0.2, green: 0.2, blue: 0.2))
|
||||
.frame(width: geometry.size.width - 50, height: geometry.size.height / 2 - vertSep)
|
||||
|
||||
//////
|
||||
|
||||
Text("separator").foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00)))
|
||||
.gesture(
|
||||
DragGesture()
|
||||
|
@ -598,8 +618,8 @@ struct ContentView_Previews: PreviewProvider {
|
|||
}
|
||||
}
|
||||
|
||||
//@discardableResult
|
||||
extension View {
|
||||
@discardableResult
|
||||
func Print(_ vars: Any...) -> some View {
|
||||
for v in vars {
|
||||
print(v)
|
||||
|
|
Loading…
Reference in New Issue