Learn Courses My Dashboard

LazyVGrid update gives wrong scroll position upon switching between different grid layouts

I'm trying to build a photo app that displays a collection of coffee photos. In the app, it provides a feature for users to change the layout. By default, it shows the list of photos in a single column. The user can tap a Grid button to change the list view to a grid view with 2 columns. But in the process of switching from single column to 2 column the app always loses the scroll position. For ex. if I am on 7th image of coffee on single column view and when I tap grid button for 2 column view, it jumps over to the 15th and 16th image of the coffee.Please check the gif for more clarification. My question is how to maintain a scroll offset.

i think it just “maintained” where it is physically… when you made it two columns ofcourse the other images are higher up which means maintaining position 7 will make it show you position 14 or something close to that.

you might want to add a code to change your offset depending on the “position” you have detected and just multiply it by 2 or divide it by 2 if it is the opposite