ScrollViewProxy scrollTo scrolls beyond the maximum offset

Hi,

I've been trying to implement a scrollIfNeeded() method for the ScrollView in SwiftUI.

My aim is to make the ScrollView scroll to the selected item if it is not visible already, and don't do anything otherwise.

I managed to determine if the selected item is currently visible or not, when I do this while the last item on the list is selected:

proxy.scrollTo(selectedItem.id, anchor: .center)

The ScrollView scrolls beyond the maximum contentOffset it can have to center the last item. What I expected it to do was scrolling to the end of the list and not going beyond that.

Is this the intended behavior? It seems like a bug because the moment I tap on the scrollView, it immediately jumps to the correct offset.

ScrollViewProxy scrollTo scrolls beyond the maximum offset
 
 
Q