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