indieSoftware/NavigationStack

Scroll offset unable to be kept when back

Opened this issue · 3 comments

When back to a scroll view, the scroll view's Y offset will be reset.
Is it due to the single-page architecture?
Any suggestions on how to handle this issue?

Yes, it's because the view with the scroll view gets replaced by the destination view. I'm currently not sure if there is a possibility to fix this within the architecture. To workaround this maybe you can read out the current scroll position before transitioning and then apply it again when going back? I'm not sure about that, need to investigate further.

Hi, I recently start to develop in SwiftUI and also very interesting in custom navigation managers.
As I can see all of single page implementations have this issue with scroll offset. Standard navigation via NavigationView hides the parent view, but also saves the offset.
About scroll offset - this is possible to obtain scroll offset via GeometryReader, but you cannot use it for restore the offset. Change of the scroll position is possible only via ScrollViewReader, but this way requires not an offset but id of a required view.

@AlexeyTernopolsky Have you being able to find any library to be used for such case?