-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Add allowScrollOutOfBounds to ScrollView #22769
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
Conversation
If I understand correctly, you are changing I'm not very familiar with ScrollView behavior but I'm curious if the current behavior would be seen as a bug that we should just change without adding the additional prop. Maybe @sahrens or @wcandillon have some thoughts. |
When using the scrollTo() function the user can specify a x/y position that tells the ScrollView to scroll to. Prior to this patch the x/y were not validated which could cause the SrollView to scroll to a position outside the content view bounds, leaving the screen empty (the content disapears, since it goes outside the screen). In order to fix this problem, this commit imposes that the x/y must be inside the view bounds if allowScrollOutOfBounds is set to false. This new prop is also set to true automatically to not break existing apps which may depends on this feature. Note that this behavior does not occur on Android, because the Android's framework itself implements this features via [1] and [2], which are used by React Native. [1]: https://developer.android.com/reference/android/widget/ScrollView#smoothScrollTo(int,%20int) [2]: https://developer.android.com/reference/android/widget/ScrollView.html#scrollTo(int,%20int)
Hello @TheSavior, yes you're correct. I'm only adding this prop to do not break the current behavior in iOS in case someone depends on this. But if you guys think it's not necessary I'll be glad to remove it. I also updated my PR in order to fixing a problem that may happen on scrollviews that support both horizontal and vertical directions By the way, thank you for your review and happy new year! |
Hey guys, any news on this? |
I was actually going to open an issue/PR to prevent this same programatic overscroll behaviour. I don't think RN should expose a prop to keep the "existing" behaviour. This behaviour sounds entirely like a bug, especially since the first user interaction causes a rubber-band effect & the behaviour differs from Android (consistent behaviour should be used wherever possible between platforms) I can't speak for Facebook on this matter, but I'd highly suggest taking this PR without the |
@berickson1 I'm happy to remove the flag. I just to know what Facebook has to say |
@cabelitos can you rebase this PR and remove the |
@cpojer as a matter of fact a fix for this was already merged #23427 . This is soo sad, because I have this PR sitting here for months and that other PR was merged even though it was newer than mime. I have no idea why @zhongwuzw implemented a fix for for a bug which I created and I provided the fix for it. He even links my bug in his PR. |
Oh you are right! I'm so sorry about that. Up until recently we didn't have the bandwidth to take care of all contributions. We recently worked through 600 Pull Requests (See https://facebook.github.io/react-native/blog/2019/03/01/react-native-open-source-update ) and are now much more active on the React Native repo. As you can see, the number of open Pull Requests is less than 50, which is much more manageable than it was in the past :) Again, I'm so sorry this happened but I'm hoping to see your contributions again in the future, and I'll make sure to provide feedback quickly and get your changes merged. |
@cpojer np at all, these things happens specially when you have 500+ PRs. I have another PR open which fixes problems for ART on Android. I hope you guys are able to take a look into it! |
@cabelitos Ahha, I'm sorry, I didn't see this PR when I linked your bug report. And I see your fix now, we try to fix in different way, you add an option to enable/disable overflow, maybe you can try to create a new PR to let react native team for review. |
- (CGPoint)getMaxYOffset | ||
{ | ||
CGFloat offsetY = _scrollView.contentSize.height - _scrollView.bounds.size.height + _scrollView.contentInset.bottom; | ||
return CGPointMake(0, fmax(offsetY, 0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The minimum is not 0, we also need to consider _scrollView.contentInset.top
.
@zhongwuzw we agreed that your solution is fine, and that we don't want to add a new flag for this. |
@cpojer Get it ! 👍 |
@cpojer So there is no chance of adding a new flag for this to re-enable the old behavior? We were using the behavior quite extensively as an alternative way to position TextInputs/Dropdowns/etc on the screen when selected/focused and oftentimes that caused some over scroll of the content. |
I agree with you, I used this old behavior to position TextInputs in previous projects, but now,I have to edit the native code to use the old behavior |
@sheepmiee Hey, |
When using the scrollTo() function the user can specify a x/y position
that tells the ScrollView to scroll to. Prior to this patch the x/y were
not validated which could cause the SrollView to scroll to a position
outside the content view bounds, leaving the screen empty (the content
disapears, since it goes outside the screen). In order to fix this problem,
this commit imposes that the x/y must be inside the view bounds if allowScrollOutOfBounds
is set to false. This new prop is also set to true automatically to not break
existing apps which may depends on this feature.
Note that this behavior does not occur on Android, because the
Android's framework itself implements this features via 1 and 2, which are used
by React Native.
Changelog:
[iOS] [Added] - Add allowScrollOutOfBounds to ScrollView
Test Plan:
Run the following code on a iOS simulator/device and play around with the new
allowScrollOutOfBounds
property.false
thescrollToOffset
will stop at the last item (the item 12)true
thescrollToOffset
will scroll outside the content bounds and leave the screen completely white.GIF demo
Without the patch
With the patch
fixes #22768