Shopify / flash-list

A better list for React Native
https://shopify.github.io/flash-list/
MIT License
5.51k stars 283 forks source link

maintainVisibleContentPosition Not Working #547

Open nickcherry opened 2 years ago

nickcherry commented 2 years ago

Current behavior

When a maintainVisibleContentPosition prop is given to a FlashList and items are prepended to the data array, the user sees the list content move. This can be observed in the video below. On the left tab, we have React Native's FlatList, which does not scroll as content is prepended to its data array. On the right tab, we have FlashList, which does scroll as content is prepended, even when providing a valid keyExtractor and a maintainVisibleContentPosition of { minIndexForVisible: 0 }.

https://user-images.githubusercontent.com/229477/182754997-24c6ceaf-bb7f-481e-873d-5d65e2202862.mov

See https://github.com/nickcherry/flashlist-maintain-visible-content-position for reproducible demo.

Expected behavior

I would expect FlashList to behave like FlatList and not scroll when content is prepended to its data and maintainVisibleContentPosition is not undefined.

To Reproduce

https://github.com/nickcherry/flashlist-maintain-visible-content-position

Platform:

Environment

1.2.1

naqvitalha commented 2 years ago

maintainVisibleContent position is unsupported right now. We will update here once we get to it.

hirbod commented 2 years ago

The last missing piece for a almost perfect library :)

aweffr commented 1 year ago

+1 we really need maintainVisibleContentPosition, please

zedelashvililevani commented 1 year ago

+1 I copy repo and make custom bridge for android :/

harrisontaee commented 1 year ago

+1, extremely valuable prop... would perfect the library!

xmflsct commented 1 year ago

๐Ÿ‘€

superspike7 commented 1 year ago

any workaround?

yoann84 commented 1 year ago

Hey, I'd like to know the advancement on this feature ? Any news ?

irisjae commented 9 months ago

For using flash list to implement messaging interfaces, a workaround is to ignore changes on data passed to FlashList, and not update data unless the the scroll position is within a small distance of the bottom (my list is inverted). This does not exactly reproduce maintainVisibleContentPosition when the list is at the bottom and we update the list, so new messages push the rest of the list up, but it is acceptable for common messaging use cases.

Rohit3523 commented 9 months ago

@fortmarek Can you please handle this PR

robertontiu commented 8 months ago

Any news on this one?

isaachinman commented 5 months ago

Just ran into this myself. Might need to revert to FlatList. Would be grateful if anyone is able to work on this feature.

irisjae commented 5 months ago

FlashList as of now does not support the maintainVisibleContentPosition prop or similar functionality.

For those of you who may need similar functionality, I've published an analysis of this problem and a patch to solve it here; feel free to test it out.

Note that instead of attempting to replicate ScrollView's maintainVisibleContentPosition prop, my patch creates a new prop preserveVisiblePosition instead.

Marvin-Bai commented 5 months ago

Hey team, any updates on this issue? I see there is a fix about an experimental feature supporting MVCP from discord forked repo. Can't we merge it into this? ๐Ÿ‘€

Rohit3523 commented 5 months ago

Hey team, any updates on this issue? I see there is a fix about an experimental feature supporting MVCP from discord forked repo. Can't we merge it into this? ๐Ÿ‘€

Can you share the fork link @Marvin-Bai

Marvin-Bai commented 5 months ago

Hey team, any updates on this issue? I see there is a fix about an experimental feature supporting MVCP from discord forked repo. Can't we merge it into this? ๐Ÿ‘€

Can you share the fork link @Marvin-Bai

Here it is. https://github.com/discord/flash-list

irisjae commented 5 months ago

If what you're referring to is this branch, the commits appear to be just a squash of this PR, which for the reasons I explain in the link from my above comment, cannot fully solve the issue (with problems like not working well during scrolling and not working if the indexes shift too much).

See if my linked fork/patch works well for you, and if it does, it would be great if you added support for my PR to get thoughts and attention of the maintainers.

P.S. With respect to the two flaws I specifically linked to, my fork/patch addresses it respectively in:

Besides these two flaws, my patch addresses a good deal of other edge cases; in the latter part of my explainer, essentially each section corresponds to the presence of an edge case, and how we have dealt with/can deal with it properly.

Nasseratic commented 4 months ago

Would be amazing to get this ๐Ÿฅฒ

GeorgeFlorian commented 3 days ago

Any news on this ?