From 2c9da90662fff4411cb6676733fdcfdb24c964cf Mon Sep 17 00:00:00 2001 From: saint Date: Mon, 20 May 2024 13:53:47 -0400 Subject: [PATCH] Starting to refactor --- Fenestra.swift | 216 +++++++++++++++++ gloss.xcodeproj/project.pbxproj | 4 + gloss/ContentView.swift | 402 +++++--------------------------- 3 files changed, 274 insertions(+), 348 deletions(-) create mode 100644 Fenestra.swift diff --git a/Fenestra.swift b/Fenestra.swift new file mode 100644 index 0000000..4e3c7f1 --- /dev/null +++ b/Fenestra.swift @@ -0,0 +1,216 @@ +// +// Fenestra.swift +// gloss +// +// Created by Saint on 5/20/24. +// + +import Foundation +import SwiftUI +import WrappingHStack + +struct SegRow: View { + var seg: SegDenorm + var ribbonId: Int64 + @State var highlights = Set() + + var body: some View { + var segSplit = seg.body.components(separatedBy: ";;") + let decoder = JSONDecoder() + var retView = WrappingHStack(alignment: .leading, horizontalSpacing: 0) { + ForEach(0 ..< segSplit.count, id: \.self) { segIndex in + + let verse = try! decoder.decode(Verse.self, from: segSplit[segIndex].data(using: .utf8)!) + let arrayOfText = verse.body.components(separatedBy: " ") + + let lineHeight = CGFloat(30) + let fontSize = CGFloat(20) + let highlightColor = "470000" + ForEach(0 ..< arrayOfText.count, id: \.self) { index in + HStack(spacing: 0) { + if index == 0 { + Text("") + .foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00))) + .font(Font.custom("AveriaSerifLibre-Regular", size: fontSize)) + .if(self.highlights.contains(verse.verse)) { $0.background(Color(hex: highlightColor)) } + + VStack(spacing: 0) { + ZStack { + Text(" ") + .foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00))) + .font(Font.custom("AveriaSerifLibre-Regular", size: fontSize)) + .if(self.highlights.contains(verse.verse)) { $0.background(Color(hex: highlightColor)) } + Text(String(verse.verse)) + .font(Font.custom("AveriaSerifLibre-Regular", size: 10)) + .padding(.horizontal, 0) + .foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00))) + .if(self.highlights.contains(verse.verse)) { $0.background(Color(hex: highlightColor)) } + } + .if(self.highlights.contains(verse.verse)) { $0.background(Color(hex: highlightColor)) } + } + } + + Text(arrayOfText[index]) + .foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00))) + .font(Font.custom("AveriaSerifLibre-Regular", size: fontSize)) + .padding(.horizontal, 1.5) // intra word spacing + .if(self.highlights.contains(verse.verse)) { $0.background(Color(hex: highlightColor)) } + .foregroundColor(Color.white) + .onTapGesture { + Print(arrayOfText[index]) + Print(verse.verse) + if self.highlights.contains(verse.verse) { + self.highlights.remove(verse.verse) + } else { + self.highlights.insert(verse.verse) + } + } + } + .frame(height: 16) // intra line spacing + .padding(.vertical, 0) + } + } + } + return retView + } +} + + +// struct Fenestra: View { +// @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) -> Void + +// var body: some View { +// ScrollViewReader { proxy in +// VisibilityTrackingScrollView(action: handleVisibilityChanged) { +// LazyVStack { +// ForEach(segs) { seg in +// SegRow(seg: seg, +// ribbonId: selectedRibbon[0].id!) +// .id("\(seg.id)") +// .offset(x: -dragOffset) +// .padding(EdgeInsets(top: 10, leading: 20, bottom: 40, trailing: 20)) +// .trackVisibility(id: "\(seg.id)") +// } +// } +// .background(Color(red: 0.18, green: 0.18, blue: 0.18)) +// } + +// .onAppear { +// Print("APPEAR") +// goToRibbon(selectedRibbon: selectedRibbon[0], +// destRibbon: selectedRibbon[0], +// scrollId: $scrollId, +// scrollOffset: $scrollOffset, +// refresh: $refresh, +// showOverlay: $showOverlay, +// appDatabase: appDatabase, +// loading: true) +// } +// .onChange(of: refresh) { _ in +// Task { +// DispatchQueue.main.async { +// Print("scroll Id target: \(scrollId)") +// proxy.scrollTo(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("NO MATCH") +// } + +// Print(" current offset ", gTracker!.visibleViews[scrollId!]) +// var curOffset = gTracker!.visibleViews[scrollId!] +// Print(" stats", gTracker!.visibleViews) +// if curOffset != nil { +// setScrollOffset = CGFloat(Int(scrollOffset!) - Int(curOffset!)) +// Print("applying scroll offset \(setScrollOffset)") +// refresh2.toggle() +// } else { +// var adjust = (Int(scrollId!)! - Int(currentId!)!) * 200 +// Print("adjusting \(adjust)") +// setScrollOffset = CGFloat(adjust) +// refresh.toggle() +// } +// } +// } +// } +// } +// .introspect(.scrollView, on: .iOS(.v13, .v14, .v15, .v16, .v17)) { scrollView in Print("introspect") +// if setScrollOffset != nil { +// DispatchQueue.main.async { +// scrollView.contentOffset.y = scrollView.contentOffset.y + setScrollOffset! +// setScrollOffset = nil +// withAnimation { +// showOverlay = false +// } +// } +// } +// } +// .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) { +// // var printRate: Int64 = 10 +// gTracker = tracker + +// let visibleViews2 = Array(tracker.visibleViews.keys) +// if visibleViews2.count == 0 { +// return +// } + +// // currentId = tracker.sortedViewIDs[tracker.sortedViewIDs.count - 1] +// currentId = tracker.sortedViewIDs[0] +// currentOffset = tracker.visibleViews[currentId!]! +// } + +// } + diff --git a/gloss.xcodeproj/project.pbxproj b/gloss.xcodeproj/project.pbxproj index 387d765..a76ccad 100644 --- a/gloss.xcodeproj/project.pbxproj +++ b/gloss.xcodeproj/project.pbxproj @@ -22,6 +22,7 @@ 85431A902905F4F600EE0760 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 85431A8F2905F4F600EE0760 /* Preview Assets.xcassets */; }; 85431A922905F4F600EE0760 /* Persistence.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85431A912905F4F600EE0760 /* Persistence.swift */; }; 85431A9C2905F5D800EE0760 /* SwiftUIView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85431A9B2905F5D800EE0760 /* SwiftUIView.swift */; }; + 857C34492BFB7DC800661A63 /* Fenestra.swift in Sources */ = {isa = PBXBuildFile; fileRef = 857C34482BFB7DC800661A63 /* Fenestra.swift */; }; 8590D96729A183EE001EF84F /* AppDatabase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8590D96629A183EE001EF84F /* AppDatabase.swift */; }; 8590D96929A18A6D001EF84F /* LineRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8590D96829A18A6C001EF84F /* LineRequest.swift */; }; 8590D96C29A92146001EF84F /* JsonImport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8590D96B29A92146001EF84F /* JsonImport.swift */; }; @@ -57,6 +58,7 @@ 85431A8F2905F4F600EE0760 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 85431A912905F4F600EE0760 /* Persistence.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Persistence.swift; sourceTree = ""; }; 85431A9B2905F5D800EE0760 /* SwiftUIView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftUIView.swift; sourceTree = ""; }; + 857C34482BFB7DC800661A63 /* Fenestra.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Fenestra.swift; sourceTree = ""; }; 8590D96629A183EE001EF84F /* AppDatabase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDatabase.swift; sourceTree = ""; }; 8590D96829A18A6C001EF84F /* LineRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LineRequest.swift; sourceTree = ""; }; 8590D96B29A92146001EF84F /* JsonImport.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JsonImport.swift; sourceTree = ""; }; @@ -106,6 +108,7 @@ 85431A7C2905F4F500EE0760 = { isa = PBXGroup; children = ( + 857C34482BFB7DC800661A63 /* Fenestra.swift */, 8594ED972BF6845F001213F2 /* HexColor.swift */, 85E00E7B29F34D2D00FF9E78 /* ScrollState.swift */, 85E00E7D29F34D3700FF9E78 /* ScrollStateRequest.swift */, @@ -279,6 +282,7 @@ buildActionMask = 2147483647; files = ( 85431A922905F4F600EE0760 /* Persistence.swift in Sources */, + 857C34492BFB7DC800661A63 /* Fenestra.swift in Sources */, 85942EEB29AD55A400307621 /* RibbonRequest.swift in Sources */, 85431A8B2905F4F500EE0760 /* ContentView.swift in Sources */, 85942EF529B108C600307621 /* Seg.swift in Sources */, diff --git a/gloss/ContentView.swift b/gloss/ContentView.swift index 1695fe0..7d2c321 100644 --- a/gloss/ContentView.swift +++ b/gloss/ContentView.swift @@ -10,7 +10,6 @@ import GRDBQuery import os import SwiftUI import SwiftUIIntrospect -import WrappingHStack let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "network") @@ -22,8 +21,6 @@ var printCount: Int64 = 0 var disableDrop = false -// var curBook = "John" - public extension UserDefaults { func optionalInt(forKey defaultName: String) -> Int? { let defaults = self @@ -126,7 +123,6 @@ struct RibbonCrown: View { var isDragging: Bool var height = CGFloat(45) - var xOffset = CGFloat(25) var scale = 0.65 @Environment(\.appDatabase) private var appDatabase @@ -144,12 +140,8 @@ struct RibbonCrown: View { .contentShape(.dragPreview, RoundedRectangle(cornerRadius: 32)) .if(draggedRibbon != nil && draggedRibbon!.id == ribbon.id && isDragging) { $0.overlay(Color(red: 0.1, green: 0.1, blue: 0.1)) } - // .offset(x: 10) - Text(ribbon.title) .foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00))) - // .foregroundColor(.white)) - // .foregroundColor(.black) .frame(minWidth: CGFloat(70), maxWidth: CGFloat(70), minHeight: height, @@ -157,19 +149,24 @@ struct RibbonCrown: View { alignment: .center) .if(draggedRibbon != nil && draggedRibbon!.id == ribbon.id && isDragging) { $0.overlay(Color(red: 0.1, green: 0.1, blue: 0.1)) } - - // .if(!isDragging || draggedRibbon == nil || draggedRibbon!.id != ribbon.id) { $0.background(Color(red: 0.1, green: 0.1, blue: 0.1)) } - // .if(draggedRibbon != nil && draggedRibbon!.id == ribbon.id) { $0.background(.red) } .background(Color(red: 0.1, green: 0.1, blue: 0.1)) - // .offset(x: 10) - // .background(Color(red: 0.1, green: 0.1, blue: 0.1)) - // .background(.red) - // .background(.yellow) .multilineTextAlignment(.center) // .minimumScaleFactor(0.5) // .padding([.top, .bottom], 10) .font(Font.custom("AveriaSerifLibre-Regular", size: CGFloat(10))) } + .onTapGesture { + Task { + goToRibbon(selectedRibbon: sr[0], + destRibbon: ribbon, + scrollId: $scrollId, + scrollOffset: $scrollOffset, + refresh: $refresh, + showOverlay: $showOverlay, + appDatabase: appDatabase, + loading: false) + } + } .frame(width: CGFloat(100 * 1.66 * scale + 10), height: CGFloat(100 * scale + 5)) } } @@ -198,79 +195,9 @@ func makeVerseView(seg: SegDenorm) -> some View { return retView } -private struct SegRow: View { - var seg: SegDenorm - var ribbonId: Int64 - @State var highlights = Set() - - var body: some View { - var segSplit = seg.body.components(separatedBy: ";;") - let decoder = JSONDecoder() - var retView = WrappingHStack(alignment: .leading, horizontalSpacing: 0) { - ForEach(0 ..< segSplit.count, id: \.self) { segIndex in - - let verse = try! decoder.decode(Verse.self, from: segSplit[segIndex].data(using: .utf8)!) - let arrayOfText = verse.body.components(separatedBy: " ") - - let lineHeight = CGFloat(30) - let fontSize = CGFloat(20) - let highlightColor = "470000" - ForEach(0 ..< arrayOfText.count, id: \.self) { index in - HStack(spacing: 0) { - if index == 0 { - Text("") - .foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00))) - .font(Font.custom("AveriaSerifLibre-Regular", size: fontSize)) - .if(self.highlights.contains(verse.verse)) { $0.background(Color(hex: highlightColor)) } - - VStack(spacing: 0) { - ZStack { - Text(" ") - .foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00))) - .font(Font.custom("AveriaSerifLibre-Regular", size: fontSize)) - .if(self.highlights.contains(verse.verse)) { $0.background(Color(hex: highlightColor)) } - Text(String(verse.verse)) - .font(Font.custom("AveriaSerifLibre-Regular", size: 10)) - .padding(.horizontal, 0) - .foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00))) - .if(self.highlights.contains(verse.verse)) { $0.background(Color(hex: highlightColor)) } - } - .if(self.highlights.contains(verse.verse)) { $0.background(Color(hex: highlightColor)) } - } - } - - Text(arrayOfText[index]) - .foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00))) - .font(Font.custom("AveriaSerifLibre-Regular", size: fontSize)) - .padding(.horizontal, 1.5) // intra word spacing - .if(self.highlights.contains(verse.verse)) { $0.background(Color(hex: highlightColor)) } - .foregroundColor(Color.white) - .onTapGesture { - Print(arrayOfText[index]) - Print(verse.verse) - if self.highlights.contains(verse.verse) { - self.highlights.remove(verse.verse) - } else { - self.highlights.insert(verse.verse) - } - } - } - .frame(height: 16) // intra line spacing - .padding(.vertical, 0) - // .if( index == 0 ) { $0.offset(x: -6) } - } - } - } - return retView - } -} - struct ContentView: View { @State var viewState = CGSize.zero @State var pulledOut = CGSize.zero - @State var taskTitle: String = "FIRST DOGGG" - @State var curBook: String = "Matthew" - @State var selectedLine: Int64? @State var thisScrollView: UIScrollView? @State var scrollUpdate = false @@ -288,21 +215,12 @@ struct ContentView: View { @Environment(\.appDatabase) private var appDatabase @Query(SegDenormRequest(book: "bible.mark")) private var segs: [SegDenorm] - // @State var scrollDelegate: ScrollViewHandler - // @State var scrollDelegate = ScrollViewHandler() - - // @State var selectedRibbonId = Int64(UserDefaults.standard.optionalInt(forKey: "selectedRibbonId") ?? 1) - - // ribbon - // @Query(SelectedRibbonRequest()) private var selectedRibbon: [Ribbon] - @State var endedDrag = true @State var readOffset = CGPoint() @State var dragOffset = CGFloat() @State var refresh: Bool = false - @State var refresh2: Bool = false @State var draggedRibbon: Ribbon? @@ -313,36 +231,23 @@ struct ContentView: View { @Query(RibbonRequest()) private var ribbons: [Ribbon] @Query var selectedRibbon: [Ribbon] - // @Query(RibbonRequest(id: Int64(UserDefaults.standard.optionalInt(forKey: "lastRibbonId") ?? 1))) private var selectedRibbon: [Ribbon] - init() { UITableView.appearance().backgroundColor = UIColor(Color(red: 0.2, green: 0.2, blue: 0.2)) _selectedRibbon = Query(SelectedRibbonRequest()) - - // self._scrollDelegate = State(initialValue: ScrollViewHandler()) } var body: some View { - // Print("rendering") - var size1 = CGFloat(11) - var size2 = CGFloat(100) var fontSize = CGFloat(15) var scale = 0.65 var height = CGFloat(50) - var xOffset = CGFloat(25) var width = CGFloat(100 * 1.66 * scale) - // ForEach(ribbons) { ribbon in - // data.append(ribbon) - // } - GeometryReader { geometry in ZStack(alignment: .top) { VStack(alignment: .leading) { VStack { - // ReorderableForEach($data, allowReordering: $reorder) { item, isDragged in ForEach(ribbons) { ribbon in RibbonCrown(ribbon: ribbon, scrollId: $scrollId, @@ -362,8 +267,6 @@ struct ContentView: View { appDatabase: appDatabase)) .offset(x: 6, y: 6) } - - // .foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00))) } .frame(width: geometry.size.width, height: geometry.size.height - 100, alignment: .topLeading) .background(Color(red: 0.1, green: 0.1, blue: 0.1)) @@ -371,26 +274,9 @@ struct ContentView: View { .animation(.default, value: ribbons) .onDrop(of: [.item], delegate: DropViewDelegate2(isDragging: $isDragging)) - - // Spacer() - - // ForEach(ribbons) { ribbon in - // RibbonCrown(ribbon: ribbon, - // scrollId:$scrollId, - // scrollOffset:$scrollOffset, - // showOverlay: $showOverlay, - // refresh:$refresh - // ) - // // .buttonStyle(BlueButtonStyle()) - // // .frame(alignment: .topLeading) - - // // .background(Color(red: 0.4, green: 0.4, blue: 0.1)) - // .animation(nil) - // } } .background(Color(red: 0.1, green: 0.1, blue: 0.1)) .frame(alignment: .topLeading) - // .animation(nil) VStack { ScrollViewReader { proxy in @@ -407,16 +293,6 @@ struct ContentView: View { .padding(EdgeInsets(top: 10, leading: 20, bottom: 40, trailing: 20)) .trackVisibility(id: "\(seg.id)") - - // .onChange(of: geometry.frame(in: .named("scrollView"))) { imageRect in - // Print(imageRect) - // Print(outerProxy) - // if isInView(innerRect: imageRect, isIn: outerProxy) { - // visibleIndex.insert(item) - // } else { - // visibleIndex.remove(item) - // } - // } } } .background(Color(red: 0.18, green: 0.18, blue: 0.18)) @@ -452,7 +328,7 @@ struct ContentView: View { // currentId = scrollId! // if (currentId != scrollId!) { - DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { + DispatchQueue.main.asyncAfter(deadline: .now() + 1) { Print(" scroll id target", scrollId) Print(" current id ", currentId) Print(gTracker!.sortedViewIDs) @@ -490,10 +366,7 @@ struct ContentView: View { } } .introspect(.scrollView, on: .iOS(.v13, .v14, .v15, .v16, .v17)) { scrollView in Print("introspect") - // Print("Scroll delegate offset", scrollDelegate.scrollOffset) - if setScrollOffset != nil { - // Print("Setting scroll offset in introspect", setScrollOffset) DispatchQueue.main.async { scrollView.contentOffset.y = scrollView.contentOffset.y + setScrollOffset! setScrollOffset = nil @@ -505,12 +378,6 @@ struct ContentView: View { } } - // if (thisScrollView == nil) { - // Print("init scroll") - // thisScrollView = scrollView - // scrollView.contentOffset.y = CGFloat(selectedRibbon[0].scrollOffset) - // } - Print("end introspect") } .listStyle(PlainListStyle()) @@ -518,46 +385,6 @@ struct ContentView: View { .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("meow") - } - // logger.error("hello222") - // NSLog("hellooo") - 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 - } - } - // offset.y = gesture.translation.width - // logger.log("hello") - } - .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 - } - } - ) Text("separator").foregroundColor(Color(UIColor(red: 0.76, green: 0.76, blue: 0.76, alpha: 1.00))) .gesture( @@ -629,144 +456,54 @@ struct ContentView: View { .onAppear { Print("APPEAR") - // Print(selectedRibbon[0]) - // scrollId = "3" - // scrollOffset = 103 - // refresh.toggle() - - // goToRibbon(selectedRibbon: selectedRibbon[0], - // destRibbon: selectedRibbon[0], - // scrollId: $scrollId, - // scrollOffset: $scrollOffset, - // refresh: $refresh, - // showOverlay: $showOverlay, - // appDatabase: appDatabase, - // loading: true) } - // .onChange(of: refresh) { target in - // //if let target = target { - // //gTracker!.visibleViews["123123"] = CGFloat(100) - // // Print("ON CHANGE", gTracker!.visibleViews) - // // Print("removing", gTracker!.visibleViews.removeAll()) - - // Task { - // DispatchQueue.main.async { - - // Print("scroll Id target: \(scrollId)") - - // proxy.scrollTo(scrollId! , anchor: .top) - - // // proxy.scrollTo(String(Int(scrollId!)! + 1)) - - // // currentId = scrollId! - - // // if (currentId != scrollId!) { - - // DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { - - // Print(" scroll id target", scrollId) - // Print(" current id ", currentId) - // Print(gTracker!.sortedViewIDs) - // if (currentId! != scrollId!) { - // Print("NO MATCH") - // } - - // // Print(" scroll offset target", scrollOffset) - // Print(" current offset ", gTracker!.visibleViews[scrollId!]) - // var curOffset = gTracker!.visibleViews[scrollId!] - // Print(" stats", gTracker!.visibleViews) - // // // setScrollOffset = CGFloat(Int(currentOffset!) * -1 + Int(scrollOffset!)) - // if (curOffset != nil) { - // setScrollOffset = CGFloat(Int(scrollOffset!) - Int(curOffset!)) - // Print("applying scroll offset \(setScrollOffset)") - // // // setScrollOffset = CGFloat(Int(scrollOffset!)) - // // Print("setting scroll offset", setScrollOffset) - // refresh2.toggle() - // } else { - // var adjust = (Int(scrollId!)! - Int(currentId!)!) * 200 - // Print("adjusting \(adjust)") - - // setScrollOffset = CGFloat(adjust) - // refresh.toggle() - - // } - // // // currentId = scrollId! - - // // DispatchQueue.main.async { - - // // currentOffset = scrollOffset! - // // currentId = scrollId! - // // } - // } - // } - // } - // } - // .introspectScrollView { scrollView in - // Print("introspect") - // // scrollView.delegate = scrollDelegate - // //Print("Scroll delegate offset", scrollDelegate.scrollOffset) - - // if (setScrollOffset != nil) { - // // Print("Setting scroll offset in introspect", setScrollOffset) - // DispatchQueue.main.async { - // scrollView.contentOffset.y = scrollView.contentOffset.y + setScrollOffset! - // setScrollOffset = nil - // withAnimation { - // showOverlay = false - // } - // } - // } - - // // if (thisScrollView == nil) { - // // Print("init scroll") - // // thisScrollView = scrollView - // // scrollView.contentOffset.y = CGFloat(selectedRibbon[0].scrollOffset) - // // } - - // Print("end instrospect") - // } .listStyle(PlainListStyle()) } .zIndex(1) .background(Color(red: 0.2, green: 0.2, blue: 0.2)) .frame(width: geometry.size.width - 50) - .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("meow") - } - // logger.error("hello222") - // NSLog("hellooo") - Print(viewState.width) - if abs(gesture.translation.width) > 20 { - viewState.width = gesture.translation.width - } - // offset.y = gesture.translation.width - // logger.log("hello") - } - .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 - } - } - ) } + .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("meow") + } + // logger.error("hello222") + // NSLog("hellooo") + 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 + } + } + // offset.y = gesture.translation.width + // logger.log("hello") + } + .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 + } + } + ) + if showOverlay { Rectangle() @@ -793,23 +530,6 @@ struct ContentView: View { // var printRate: Int64 = 10 gTracker = tracker - // @Environment(\.appDatabase) var appDatabase - // switch change { - // case .shown: print("\(id) shown") - // case .hidden: print("\(id) hidden") - // } - // if (printCount % printRate == 0) { - // print("VISIBILITY CHANGED STARTED") - // print(tracker.visibleViews) - // print(tracker.sortedViewIDs) - // print("VISIBILITY CHANGED ENDED") - // } - // printCount += 1 - - // if (currentId != nil) { - // currentOffset = tracker.visibleViews[currentId!]! - // } - let visibleViews2 = Array(tracker.visibleViews.keys) if visibleViews2.count == 0 { return @@ -818,20 +538,6 @@ struct ContentView: View { // currentId = tracker.sortedViewIDs[tracker.sortedViewIDs.count - 1] currentId = tracker.sortedViewIDs[0] currentOffset = tracker.visibleViews[currentId!]! - // if (Int(currentOffset!) != -1 && Int(currentOffset!) < 0) { - // if (tracker.sortedViewIDs.count > 1) { - // currentId = tracker.sortedViewIDs[1] - // currentOffset = tracker.visibleViews[currentId!]! - // } - // } - // if (currentId != nil) { - // // if (printCount % printRate == 0) { - // // print(printCount) - // // print("cat current ID:", currentId) - // // } - // // print("got here") - // currentOffset = tracker.visibleViews[currentId!]! - // } } }