I've found that using scrollTo inside of an onChange closure doesn't scroll to the correct location if the row height of the List item is greater than a single row. It will scroll to the height of a single row leaving everything else in the row hidden. If I use the scrollTo inside a Button action it will accurately read the height of the VStack and scroll to a position that shows the full row.
The second image is a result of clicking the button, the first is the triggering of the onChange event.
Here is the code I'm working with:
Button("Scroll To ") {
readerProxy?.scrollTo(careLogItems.last)
}
ScrollViewReader { reader in
List(careLogItems) { i in
VStack {
Text(i.logText)
Text(i.logDate.description)
}.id(i)
}.onAppear {
readerProxy = reader
//reader.scrollTo(careLogItems.last)
}
CareLogItemDetail(careLogItem: $newCareLogItem, addItem: addCareLogItem)
}
}
.onChange(of: careLogItems) { _ in
print("changed \(careLogItems.count)")
readerProxy?.scrollTo(careLogItems.last)
}
.onAppear {
if (hasAppeared == false) {
hasAppeared = true
loadCareLogItems()
}
}


Post
Replies
Boosts
Views
Activity
This seems like a bug to me or I am just missing something obvious...as soon as I add the .tabViewStyle(.page) modifier to the below code it breaks the NavStack navigation. I can click the NavLink once and when I go back from the detail view I can't click on anything again. Here is the code:
struct TabbedView: View {
var body: some View {
TabView {
NavStack()
.tag(1)
NavStack()
.tag(2)
}
.tabViewStyle(.page) //this BREAKS navigation
}
}
struct NavStack: View {
let arrs: [String] = ["First Group", "Second Group"]
var body: some View {
NavigationStack {
ForEach(arrs, id: \.self) {_ in
NavigationLink("Link") {
Text("test")
}
}
.listStyle(PlainListStyle())
}
}
}