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()
}
}

