-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
[Android] ScrollView is missing initial scroll position for Android #6849
Comments
render() {
return (
<ScrollView ref={(view) => this._scrollView = view}>
</ScrollView>
);
}
this._scrollView.getScrollResponder().scrollTo({x: 0, y: 0, animated: true}) |
@hufeng That will cause flickering after render, first you will see the 0,0 position, then it will scroll. Also if you are using a ListView, then you will have to render all the data until the scroll position you want, then you can scroll there.. Which will slow your app dramatically. |
https://productpains.com/post/react-native/content-offsetinset-for-scrollview I started a product pains post for this a while back, but it hasn't gained any traction. While @hufeng's approach does the correct thing, it's very janky and even if you set animated: false, it will be noticeable to the end-user that the scrollview is jumping to its initial position. I've wanted to take a crack at a PR for this for a while but haven't had the bandwidth outside of work but for me this would be one of the most welcomed features for Android/iOS parity |
When I try to call componentDidMount() {
setTimeout(() => this.refs._scrollView.scrollTo({ x: 100, y: 0 }) , 0);
} |
It'll be awesome if someone could send a pull request for it. |
@madox2 Because the scroll position you want to scroll is not rendered yet, you have to wait for all rows to be rendered before you scroll to that position. So setTimeout is not a solution, which may not work. iOS ListView does't have this issue, because it has a initial scroll position property, so it can start rendering from that position, not from zero. |
Hi there! This issue is being closed because it has been inactive for a while. But don't worry, it will live on with ProductPains! Check out its new home: https://productpains.com/post/react-native/android-scrollview-is-missing-initial-scroll-position-for-android Product Pains has been very useful in highlighting the top bugs and feature requests: Also, if this issue is a bug, please consider sending a pull request with a fix. |
Was this fixed or just closed? The productpain page links back to this issue. |
+1 |
+1 , please |
+1 |
If someone is willing to send a PR, please do |
Insted of initial scroll position for android, you might look at using ViewPagerAndroid instead, and setting the initialPage property |
@tangkunyin No. What if you need a to use it on an infinite scrolling page? Think about the instagram app. Go to the explore tab, you will see the grids of posts, then click on an any post, the new page is an infinite scrolling listview, but started from an initial scroll position. So because of this issue, you can't make an instagram clone for android using React Native. |
Has there been any further discussion on this issue? I would really love to set: |
Using |
New link for the product pain: |
@alvaromb It won't work when you try to scroll to position that is not rendered yet. initial scroll position lets your app to start rendering from your initial scroll position, not from zero. You you won't have to wait for all of the rows to be rendered, which is a massive performance impact. |
@bcalik yeah, I agree, it's not an ideal solution but for some cases it's working for us. |
has anybody found a solution for this? I'm trying to start at the end of a horizontal ScrollView and animate towards the left once the component has rendered (making it obvious that this is a section which is scrollable) |
@cdimitroulas I just did what @alvaromb suggested. |
Thanks @SudoPlz but I tried this and it didn't seem to do anything at all.
my ScrollView looks something like this:
|
Nevermind, I got it to work by making sure the Navigator animation had finished before using |
@cdimitroulas Oooh right, I had to put it inside a Try componentDidMount() {
setTimeout(() => {
this.scrollView.scrollTo({x: 100});
}, 0);
} Keep in mind that |
This SO question seems to give directions on how to implement this : http://stackoverflow.com/questions/22307239/how-to-set-the-starting-position-of-a-scrollview @bcalik where did you find about these attributes? I have no experience whatsoever in Android dev, but I really need this feature. Can anyone help me make a PR? |
Because `contentOffset` on ScrollView is not implemented on android. See facebook/react-native#6849
Because `contentOffset` on ScrollView is not implemented on android. See facebook/react-native#6849
I am closing this issue because according to the comment by @shergin from the past, we have decided that setting offset by a prop is not optimal and method That said, we will not be adding support for the (to be deprecated) prop on iOS. |
@grabbou what do you mean by "not optimal"? Currently, it is using |
@AlexSugak I think the issue is that is that the ScrollView (at least on Android) doesn't know its size until it has been laid out. This means you're forced to manually call |
@mmazzarolo thanks, the "visibility" trick is interesting, will give it a try! In my case I am trying to use FlatList to implement a swiper (image gallery). Here I know exactly the size of each element in the list (I am forced to set it for FlatList items anyway to be able to use paging). So I would expect for underlying android control to be able to render itself with initial offset (but I am no android expert). |
Guys, I solve this this by using onContentSizeChange prop:
And my method:
|
Yup, I think it's the same as using the |
Is it big deal to add it as |
These simple things just make me disappointed to use RN for my projects.. |
This is still an issue, using scrollTo causes a flash which most people here don't want but rather want to just start at that possition |
I can't believe this issue has been open for 3 years and there is still no better solution to the problem... For me, I am using scrollTo() in componentDidMount() with setTimeout at 0ms, but flickering still occurs once every 3 refreshes or so... Will there every be a solution for this? Because it seems like a pretty common feature that a lot of people need... |
I would suggest you to give it a try to on of these solutions if you can and, if it works, send a PR or start a discussion. |
I have not read this issue but I have found that the |
Workaround for "blinking" - is use the overlay.
I apply both of InteractionManager and setTimeout in componentDidMount. And then hide overlay
Overlay stylesheet:
|
i have tried many methonds,
no one can fix the blinking or flash problem,it is a big problem。i am hurted so much。。。。 |
this is the best |
such an important feature still not solved for andorid :( its almost 2020 |
I really hate that React Native has these iOS only and Android only features. The team should implement the missing features to each platform to make the components behave identically. |
Kind of surprising that this is still not fixed upstream. Based on the suggestions mentioned, I developed this drop-in It starts with It also adds a new prop option — |
4 year have passed, blinking problem is still, so sad..... |
Support for |
ScrollView
has acontentOffset
prop for iOS, which sets the initial scroll offset.But it lacks on Android, so you can not set the initial scroll position.
For anyone who can make this, these are the attributes in Android's native ScrollView.
The text was updated successfully, but these errors were encountered: