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

Fix content offset validation #15670

Closed

Conversation

janicduplessis
Copy link
Contributor

Content offset was broken because on initial render contentSize is {0,0} so any positive offset is lost. Also inset top/bottom and left/right were inversed 🙃, this led to bad initial scrolling offset when using contentInset. This fixes it by making sure contentSize is actually measured (not {0,0}. I guess it's possible that the content is ACTUALLY {0,0} but in that case I don't think it really matters).

Test plan
Tested that a scrollview has proper scroll position when specifying contentOffset. Also tested that it works well with contentInset.

<ScrollView contentOffset={{y: 100}}>
  <View style={{height: 1000}} />
</ScrollView>

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. GH Review: review-needed labels Aug 27, 2017
@janicduplessis
Copy link
Contributor Author

This and 950c2b2 should be cherry picked into 0.48.0-rc

@pull-bot
Copy link

pull-bot commented Aug 27, 2017

@facebook-github-bot label Core Team

Attention: @shergin

Generated by 🚫 dangerJS

@shergin
Copy link
Contributor

shergin commented Aug 28, 2017

@janicduplessis I think, the problem here is that this code can produce incorrect (overscrolled) layout at a first run/layout?

@janicduplessis
Copy link
Contributor Author

@shergin Maybe if you specify contentOffset that is actually overscrolling but otherwise it should be fine. From what I understand the issue was with overscrolling when the scrollview changes frame (on sonething like screen rotation) and in that case it should work.

@shergin
Copy link
Contributor

shergin commented Aug 28, 2017

@janicduplessis Don't get me wring, your solution is great indeed. But... you actually convinced me to dislike whole concept of having contentOffset as prop. 😂

Now I am thinking that right plan can be:

  1. Land this PR. It is fixing the regression, so, even if will hurt second bullet, it is good thing to do.
  2. Mark contentOffset as deprecated and enable yellowbox for it.
  3. Investigate how we should improve RN to make calling scrollTo in componentDidMount buttery slick.

What do you think?

@janicduplessis
Copy link
Contributor Author

Yes I like that plan, I think we should find a solution for point #3 before doing #2 though.

@facebook-github-bot facebook-github-bot added GH Review: accepted Import Started This pull request has been imported. This does not imply the PR has been approved. and removed GH Review: review-needed labels Sep 5, 2017
@facebook-github-bot
Copy link
Contributor

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

@wschurman
Copy link
Contributor

@shergin - Is the plan to merge this and related fixes into 0.48 (prod), 0.49 (rc), or just keep it in master for 0.50?

@shergin
Copy link
Contributor

shergin commented Sep 9, 2017

@wschurman You could advocate including this into RC if you want to. I have no strong point here.

@janicduplessis
Copy link
Contributor Author

I posted in the 0.49-rc issue to get it cherry picked

nixoz added a commit to nixoz/react-native that referenced this pull request Sep 15, 2017
@henrikra
Copy link

@janicduplessis Would it be possible for you to implement contentOffset to Android too? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Import Started This pull request has been imported. This does not imply the PR has been approved.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants