NavigationStack icon indicating copy to clipboard operation
NavigationStack copied to clipboard

Scroll offset unable to be kept when back

Open devolaw opened this issue 4 years ago • 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?

devolaw avatar Aug 23 '21 18:08 devolaw

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.

indieSoftware avatar Aug 25 '21 04:08 indieSoftware

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 avatar Sep 19 '21 21:09 AlexeyTernopolsky

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

PhilipDukhov avatar Apr 19 '22 11:04 PhilipDukhov