Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintain scroll position when adding rows to the top of the list #44

Open
AbdallaElabd opened this issue Sep 19, 2017 · 18 comments
Open

Comments

@AbdallaElabd
Copy link

When I call dataProvider.cloneWithRows() and add more rows to the top of the list. The scroll position is lost. I tried investigating by reading the source code. I'd appreciate it if you could help with this!

And thanks for the great library! Its performance is amazing.

@naqvitalha
Copy link
Collaborator

Sadly, we do not have anchoring support for items added to top of the list as of now. Can you specify the use case? We are considering adding it soon though. Have you tried FlatList? Does it preserve scroll position? We do perform much faster but never tried scroll anchoring with FlatList.

@AbdallaElabd
Copy link
Author

Flatlist's performance is horrible. The reason I switched to RecyclerListView is because of its impressive smooth performance.

And sadly Flatlist doesn't support preserving the scroll positioning when adding items to the top of the list as well. Do you have an idea of a possible work around? I could invest sometime in trying to fix it and make a PR for it

@naqvitalha
Copy link
Collaborator

Yeah we'll be more than happy to accept PRs, however, this might not be as simple as a small bugfix. @surya-kanoria from out team is already thinking of solutions around this. Maybe you guys can collaborate.

@AbdallaElabd
Copy link
Author

@surya-kanoria I've read most of the source code and I have an idea of how things work. Would love to help implement this. How do you suggest we contact each other?

@surya-kanoria
Copy link
Contributor

@abdallamohamed Let us connect on hangouts. Can you please share your gmail id and a suitable time to talk?

@AbdallaElabd
Copy link
Author

@surya-kanoria feel free to mail me at ame@churchdesk.com anytime

@nsantacruz
Copy link

Any updates on this, @surya-kanoria ?

@AbdallaElabd
Copy link
Author

Just checking if there's any news updates on this. @naqvitalha

@miladrasooli
Copy link

Any updates on this issue?

@z98361
Copy link

z98361 commented Nov 21, 2018

1 year ago...

@mayconmesquita
Copy link

2 years ago...

@pribeh
Copy link

pribeh commented Jul 26, 2019

Has anybody given this a shot yet

@soulfly
Copy link

soulfly commented Aug 5, 2019

Is it already implemented?

I can give a real use case - a chat stream. A user can search for chat messages, then find something in the middle and jump into it, so the middle of chat stream will be rendered. Then a user can scroll back n forth, so a scroll position preserving must be implemented when insert messages in both directions when scroll

Could someone give an update here?

@timurridjanovic
Copy link

dang.. this is still not implemented?

@Jade-Jade-Jade
Copy link

+1 is there any plan for it?

@jack-guy
Copy link

I was exploring this library as an alternative to FlatList because it has this issue. Is there a way to build on top of the React Native ScrollView and solve this problem of anchoring, or is that something that will need to be solved in ScrollView itself?

@paulxuca
Copy link

I've got this to work with some success:

requestAnimationFrame(() => {
      const listView = listViewRef.current;

      if (listView) {
        listView.scrollToIndex(measuredHeights.length, false);

        // Meh
        setTimeout(() => {
          const renderer = (listView as any).getVirtualRenderer() as VirtualRenderer;

          const heightOffset = measuredHeights.reduce(
            (heightOffset, measuredHeight) =>
              heightOffset + measuredHeight.measuredHeight,
            0
          );

          renderer.updateOffset(0, heightOffset, true, {
            windowShift: 0,
            startCorrection: 0,
            endCorrection: 0
          });
        }, 50);
      }
    });

where measuredHeights is an array of items you're adding to the beginning of the list and measuredHeight.measuredHeight is the measured height of an individual element in your newly added array.

@timurridjanovic
Copy link

@paulxuca I have a similar issue where the scroll position resets itself when I change the local state and trigger a rerender.. Would this work in my situation you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests