scroll seems to be working good
parent
ea3ac33f99
commit
9e19199b87
|
@ -51,11 +51,28 @@ public class VisibilityTracker<ID: Hashable>: ObservableObject {
|
|||
let isVisible = containerBounds.contains(topLeft) || containerBounds.contains(bottomRight)
|
||||
let wasVisible = visibleViews[id] != nil
|
||||
|
||||
print("report content bounds start")
|
||||
print(id)
|
||||
print(bounds.width)
|
||||
print(bounds.height)
|
||||
print(bounds.origin)
|
||||
print(containerBounds)
|
||||
print("report content bounds end")
|
||||
|
||||
|
||||
visibleViews[id] = -1 * (bounds.origin.y - containerBounds.origin.y)
|
||||
if (abs(visibleViews[id]! ) > 500) {
|
||||
// if (abs(visibleViews[id]! ) > 500 || visibleViews[id]! < 0) {
|
||||
if (((id.hashValue) != "1".hashValue && visibleViews[id]! < 0) ||
|
||||
|
||||
bounds.width == 0 || bounds.height == 0
|
||||
|| bounds.origin.x == 0 || bounds.origin.y == 0
|
||||
|| abs(visibleViews[id]! ) > 500 ) {
|
||||
visibleViews.removeValue(forKey: id)
|
||||
}
|
||||
|
||||
// if (visibleViews[id]! > 0) {
|
||||
// visibleViews.removeValue(forKey: id)
|
||||
// }
|
||||
sortViews()
|
||||
action(id, .shown, self)
|
||||
|
||||
|
@ -75,7 +92,8 @@ public class VisibilityTracker<ID: Hashable>: ObservableObject {
|
|||
}
|
||||
|
||||
func sortViews() {
|
||||
let sortedPairs = visibleViews.sorted(by: { $0.1 < $1.1 })
|
||||
let sortedPairs = visibleViews.sorted(by: { Int($0.1) < Int($1.1) })
|
||||
// let sortedPairs = visibleViews.sorted(by: { $0 < $1 })
|
||||
sortedViewIDs = sortedPairs.map { $0.0 }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -443,7 +443,7 @@
|
|||
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
|
||||
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
|
||||
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 16.2;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
|
@ -479,7 +479,7 @@
|
|||
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
|
||||
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
|
||||
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 16.2;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
|
|
Binary file not shown.
|
@ -13,6 +13,11 @@ import os
|
|||
|
||||
let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "network")
|
||||
|
||||
var currentId : String?
|
||||
var currentOffset : CGFloat?
|
||||
|
||||
var gTracker: VisibilityTracker<String>?
|
||||
|
||||
// var curBook = "John"
|
||||
|
||||
extension UserDefaults {
|
||||
|
@ -66,24 +71,28 @@ struct SwitchButton : View {
|
|||
Print("SELECTED RIBBON", selectedRibbon)
|
||||
let userDefaults = UserDefaults.standard
|
||||
|
||||
var scrollOffsetToSave = userDefaults.object(forKey: "currentOffset") as? CGFloat
|
||||
var scrollIdToSave = userDefaults.object(forKey: "currentId") as? String
|
||||
// var scrollOffsetToSave = userDefaults.object(forKey: "currentOffset") as? CGFloat
|
||||
// var scrollIdToSave = userDefaults.object(forKey: "currentId") as? String
|
||||
|
||||
var scrollOffsetToSave = currentOffset
|
||||
var scrollIdToSave = currentId
|
||||
|
||||
Print("scrollOffsetToSave: ", scrollOffsetToSave)
|
||||
Print("scrollIdToSave: ", scrollIdToSave)
|
||||
|
||||
var updatedRibbon = selectedRibbon
|
||||
|
||||
scrollId = "10"
|
||||
scrollOffset = CGFloat(100)
|
||||
refresh.toggle()
|
||||
// scrollId = "10"
|
||||
// scrollOffset = CGFloat(100)
|
||||
// refresh.toggle()
|
||||
|
||||
|
||||
if (selectedRibbon.id != ribbon.id!) {
|
||||
Print("switching")
|
||||
|
||||
// scrollId = ribbon.scrollId
|
||||
// scrollOffset = CGFloat(ribbon.scrollOffset)
|
||||
scrollId = ribbon.scrollId
|
||||
scrollOffset = CGFloat(ribbon.scrollOffset)
|
||||
refresh.toggle()
|
||||
|
||||
//scrollId = "10"
|
||||
//scrollOffset = CGFloat(100)
|
||||
|
@ -152,13 +161,13 @@ func makeVerseView(seg: SegDenorm) -> some View {
|
|||
let verse = try! decoder.decode(Verse.self, from: item.data(using: .utf8)!)
|
||||
|
||||
retView = retView + Text(String(verse.verse))
|
||||
.font(Font.custom("AveriaSerifLibre-Regular", size: 20))
|
||||
.font(Font.custom("AveriaSerifLibre-Regular", size: 6))
|
||||
.baselineOffset(6.0)
|
||||
.foregroundColor(Color.white)
|
||||
|
||||
retView = retView + Text(verse.body)
|
||||
.foregroundColor(Color.white)
|
||||
.font(Font.custom("AveriaSerifLibre-Regular", size: 30))
|
||||
.font(Font.custom("AveriaSerifLibre-Regular", size: 15))
|
||||
})
|
||||
return retView
|
||||
}
|
||||
|
@ -183,7 +192,7 @@ private struct SegRow: View {
|
|||
retView = retView + Text(String(verse.verse))
|
||||
// Text(seg.body)
|
||||
// .contentShape(Rectangle())
|
||||
.font(Font.custom("AveriaSerifLibre-Regular", size: 20))
|
||||
.font(Font.custom("AveriaSerifLibre-Regular", size: 10))
|
||||
.baselineOffset(6.0)
|
||||
.foregroundColor(Color.white)
|
||||
|
||||
|
@ -191,7 +200,7 @@ private struct SegRow: View {
|
|||
// .frame(maxWidth: .infinity, alignment: .leading)
|
||||
// .contentShape(Rectangle())
|
||||
.foregroundColor(Color.white)
|
||||
.font(Font.custom("AveriaSerifLibre-Regular", size: 30))
|
||||
.font(Font.custom("AveriaSerifLibre-Regular", size: 20))
|
||||
// .listRowBackground(Color(red: 0.2, green: 0.8, blue: 0.2))
|
||||
// .listRowInsets(EdgeInsets())
|
||||
// .padding(EdgeInsets(top: 10, leading: 20, bottom: 40, trailing: 20))
|
||||
|
@ -231,8 +240,8 @@ struct ContentView: View {
|
|||
@State var scrollUpdate = false
|
||||
@State var initLoad = false
|
||||
|
||||
@State var currentId : String?
|
||||
@State var currentOffset = CGFloat()
|
||||
// @State var currentId : String?
|
||||
// @State var currentOffset = CGFloat()
|
||||
|
||||
// set this to scroll to area
|
||||
@State var scrollId : String?
|
||||
|
@ -336,11 +345,14 @@ struct ContentView: View {
|
|||
}
|
||||
.onChange(of: refresh) { target in
|
||||
//if let target = target {
|
||||
//gTracker!.visibleViews["123123"] = CGFloat(100)
|
||||
Print("ON CHANGE", gTracker!.visibleViews)
|
||||
Print("removing", gTracker!.visibleViews.removeAll())
|
||||
proxy.scrollTo(scrollId! , anchor: .top)
|
||||
|
||||
DispatchQueue.main.async {
|
||||
setScrollOffset = scrollOffset
|
||||
setScrollOffset = CGFloat(scrollOffset!)
|
||||
refresh2.toggle()
|
||||
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
@ -408,33 +420,39 @@ struct ContentView: View {
|
|||
|
||||
func handleVisibilityChanged(_ id: String, change: VisibilityChange, tracker: VisibilityTracker<String>) {
|
||||
|
||||
|
||||
// @Environment(\.appDatabase) var appDatabase
|
||||
switch change {
|
||||
case .shown: print("\(id) shown")
|
||||
case .hidden: print("\(id) hidden")
|
||||
}
|
||||
print("VISIBILITY CHANGED STARTED")
|
||||
print(tracker.visibleViews)
|
||||
gTracker = tracker
|
||||
print(tracker.sortedViewIDs)
|
||||
print("VISIBILITY CHANGED ENDED")
|
||||
// if (currentId != nil) {
|
||||
// currentOffset = tracker.visibleViews[currentId!]!
|
||||
// }
|
||||
|
||||
let visibleViews = Array(tracker.visibleViews.keys)
|
||||
if (visibleViews.count == 0) {
|
||||
let visibleViews2 = Array(tracker.visibleViews.keys)
|
||||
if (visibleViews2.count == 0) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
let currentId = Array(tracker.visibleViews.keys)[0]
|
||||
currentId = tracker.sortedViewIDs[0]
|
||||
if (currentId != nil) {
|
||||
|
||||
// Access Shared Defaults Object
|
||||
let userDefaults = UserDefaults.standard
|
||||
// let userDefaults = UserDefaults.standard
|
||||
|
||||
// Write/Set Value
|
||||
Print(currentId)
|
||||
Print(tracker.visibleViews[currentId]!)
|
||||
userDefaults.set(currentId, forKey: "currentId")
|
||||
userDefaults.set(tracker.visibleViews[currentId]!, forKey: "currentOffset")
|
||||
Print(currentId!)
|
||||
// Print(tracker.visibleViews[currentId?]!)
|
||||
// userDefaults.set(currentId, forKey: "currentId")
|
||||
// userDefaults.set(tracker.visibleViews[currentId]!, forKey: "currentOffset")
|
||||
currentOffset = tracker.visibleViews[currentId!]!
|
||||
// userDefaults.set(tracker.visibleViews[currentId!]!, forKey: "currentOffset")
|
||||
// var updateScrollState = ScrollState(id: Int64(1),
|
||||
// scrollId: currentId!,
|
||||
|
@ -451,6 +469,8 @@ struct ContentView: View {
|
|||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
// gTracker!.visibleViews.removeAll()
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue