react-native icon indicating copy to clipboard operation
react-native copied to clipboard

Add maintainVisibleContentPosition support on Android

Open janicduplessis opened this issue 1 year ago • 18 comments

Summary

This adds support for maintainVisibleContentPosition on Android. The implementation is heavily inspired from iOS, it works by finding the first visible view and its frame before views are update, then adjusting the scroll position once the views are updated.

Most of the logic is abstracted away in MaintainVisibleScrollPositionHelper to be used in both vertical and horizontal scrollview implementations.

Note that this only works for the old architecture, I have a follow up ready to add fabric support.

Changelog

[Android] [Added] - Add maintainVisibleContentPosition support on Android

Test Plan

Test in RN tester example on Android

https://user-images.githubusercontent.com/2677334/197319855-d81ced33-a80b-495f-a688-4106fc699f3c.mov

janicduplessis avatar Oct 22 '22 04:10 janicduplessis

Platform Engine Arch Size (bytes) Diff
ios - universal n/a --

Base commit: 8c2a4d0d26dbfcb026aee4628a5458e7d22092b8 Branch: main

analysis-bot avatar Oct 22 '22 04:10 analysis-bot

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 7,759,751 +658,847
android hermes armeabi-v7a 7,163,330 +692,730
android hermes x86 8,071,503 +552,756
android hermes x86_64 8,042,324 +664,951
android jsc arm64-v8a 9,614,859 +649,826
android jsc armeabi-v7a 8,380,813 +684,396
android jsc x86 9,561,682 +534,159
android jsc x86_64 10,154,595 +648,941

Base commit: 8c2a4d0d26dbfcb026aee4628a5458e7d22092b8 Branch: main

analysis-bot avatar Oct 22 '22 04:10 analysis-bot

PR build artifact for c069ae3e39595e7d7e7a3259c6004d1313ad6ba8 is ready. To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

pull-bot avatar Oct 22 '22 05:10 pull-bot

PR build artifact for c069ae3e39595e7d7e7a3259c6004d1313ad6ba8 is ready. To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

pull-bot avatar Oct 22 '22 05:10 pull-bot

@skinsshark has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Oct 24 '22 17:10 facebook-github-bot

I have tested this PR out in my app (closed-source) which is using VirtualizedList with maintainVisibleContentPosition={{ minIndexForVisible: 0 }} and it is not working. The property works correctly for my use case on iOS and I was previously using a modified version of https://github.com/GetStream/flat-list-mvcp for Android support which was working. From my understanding this property only affects the ScrollView directly and all of the lists built on top such as VirtualizedList should not need any modification to integrate it, but please let me know if that understanding is incorrect and additional changes are required to support the lists built on top of ScrollView.

mmmoussa avatar Oct 31 '22 20:10 mmmoussa

any progress on this?

aweffr avatar Nov 11 '22 05:11 aweffr

PR build artifact for 2764db0d2e0b49c1532ba45deeee0b142a7d0c32 is ready. To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

pull-bot avatar Nov 12 '22 17:11 pull-bot

PR build artifact for 2764db0d2e0b49c1532ba45deeee0b142a7d0c32 is ready. To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

pull-bot avatar Nov 12 '22 17:11 pull-bot

@skinsshark has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Nov 15 '22 21:11 facebook-github-bot

@skinsshark @ryancat Any updates on this? I think the only unaddressed point is https://github.com/facebook/react-native/pull/35049#discussion_r1009966255.

janicduplessis avatar Dec 02 '22 18:12 janicduplessis

Need an update on this please.

areebbajwa avatar Dec 12 '22 21:12 areebbajwa

Any update? 🙏

paula-morales avatar Dec 27 '22 16:12 paula-morales

ANy update on this?

codal-mpawar avatar Jan 02 '23 06:01 codal-mpawar

hey all! thank you for your patience and sorry for the delay, there are a couple things we want to test internally but haven't had the bandwidth just yet- i will get this prioritized and be back with updates! happy new year!

skinsshark avatar Jan 03 '23 23:01 skinsshark

@pull-bot could yours rebuild the tarball in CircleCI ?, cause it had been removed after 30days , thx~~~

siu666 avatar Jan 07 '23 17:01 siu666

Hi, many happy returns and thanks for the update. Is there any rough estimate RE: when this will be released? could it happen this month or next month? Many thanks for your help.

matt-alice avatar Jan 12 '23 11:01 matt-alice

I would like to know that as well

areebbajwa avatar Jan 12 '23 15:01 areebbajwa

Would love to have this as well along with documentation with an example on how to set the parameters. Thank you so much!

conoremclaughlin avatar Jan 18 '23 04:01 conoremclaughlin

hi! i'll follow up again, but i expect to finish this for tomorrow. thanks all for your patience =)

skinsshark avatar Jan 19 '23 23:01 skinsshark

(ah! thought i clicked comment on friday....) hey @janicduplessis, thanks for this change! this looks good to go but i'm going to wait to land this on Monday so i can be online when it ships!

skinsshark avatar Jan 23 '23 06:01 skinsshark

@skinsshark merged this pull request in facebook/react-native@c19548728c9be3ecc91e6fefb35bc14929109d60.

facebook-github-bot avatar Jan 23 '23 20:01 facebook-github-bot

Thanks @skinsshark !!

janicduplessis avatar Jan 24 '23 17:01 janicduplessis

So this maintanVisibleContentPosition prop is now available on what version of RN? And is available on FlatList as well, right?

hadnet avatar Apr 22 '23 02:04 hadnet

It is available in 0.72. It also works with FlatList but there are a few known issues that will be fixed in https://github.com/facebook/react-native/pull/35993 which isn’t merged yet.

janicduplessis avatar Apr 22 '23 05:04 janicduplessis

@janicduplessis I have tried it in 0.72-rc06. Everything seems fine but I found a problem with my chat app with scenario:

  1. In first request I load message from 30 to 0 and show it on FlatList with reverse.
  2. In second request I load message from 35-31 and append to leading page.

If all messages are short content then maintainVisibleContentPosition is working fine. But messages from 35-31 is very long text (greater than 3000 char) then FlatList still auto scroll to first position.

Do you have any suggestions for me?

hantrungkien avatar Jun 16 '23 03:06 hantrungkien

@hantrungkien did you ever experiment further with that? thanks!

haileyok avatar Feb 02 '24 22:02 haileyok

We also have noticed some issues on android, I will look at it soon.

janicduplessis avatar Feb 03 '24 01:02 janicduplessis

@janicduplessis Following up in case this is helpful, I can open a new issue too:

https://snack.expo.dev/@haileyok/flatlist-repro

/**
 * To repro:
 * - On initial render, we can add 10 or 20 items to the list without issue while maxToRenderPerBatch is set to 20.
 * - If we increase this number to 30, we will get a jump in position after adding the items above.
 * - If we then increase the maxToRenderPerBatch to 30, we can add 30 items above without issue.
 * 
 * Notice that the maxToRenderPerBatch seems to need to be set to >= the number of items we are adding.
 * 
 * Notably, after resetting the list, the issue isn't present anymore. It is only on the initial render that we see problems.
 */

Video: https://streamable.com/almoal

haileyok avatar Feb 05 '24 21:02 haileyok

Thanks, this will help, planning to look at it this week.

janicduplessis avatar Feb 06 '24 01:02 janicduplessis