Uh oh!
There was an error while loading. Please reload this page.
ScrollView, HorizontalScrollView: do not ignore nullcontentOffset prop - #28760
ScrollView, HorizontalScrollView: do not ignore nullcontentOffset prop#28760vonovak wants to merge 1 commit into
nullcontentOffset prop#28760Conversation
analysis-bot
commented
Apr 26, 2020
Base commit: 30cc158 |
Base commit: 30cc158 |
JoshuaGross
commented
May 5, 2020
Hi @vonovak - what does iOS do, will it reset to 0,0 if you pass in null from JS? |
JoshuaGross
commented
May 5, 2020
Depending on what the behavior is for iOS, I actually don't think this is the correct thing to do. Passing in null equivalent to saying "delete this prop from the native side". I would intuitively expect that to actually cause no visible changes. If the engineer wants to reset the position to Treating null as 0,0 also prevents us from doing the following in a typesafe manner: "Pass in coordinates if they're present, otherwise pass along no value, which will cause a noop". The only other way is to pass in |
@JoshuaGross Let me start with a premise that rendering the following should always render the same result (I hope that makes sense 😃 ). To give an example, imagine we render this ScrollView, then re-render it with different props and the last render looks again like this: now if we take the example code I gave (I just changed first, we start with will be called with edit: iOS will scroll to top for both It's rather interesting on iOS, I don't know the internals, but if I pass |
vonovak
commented
Jun 5, 2020
@JoshuaGross would you please re-review? Thanks! |
vonovak
commented
Jun 29, 2020
@JoshuaGross sorry to ping you again, would you please take a look? The PR unifies behavior between ios and android. Thank you! |
JoshuaGross
commented
Jun 29, 2020
Thanks for clarifying that this will unify behavior! I will test a bit internally. |
facebook-github-bot
left a comment
There was a problem hiding this comment.
@JoshuaGross has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
react-native-bot
commented
Jun 30, 2020
This pull request was successfully merged by @vonovak in 9e85b7a. When will my fix make it into a release? | Upcoming Releases |
…` prop (#28760) Summary: motivation: I was just checking out 30cc158 and noticed that the commit, I believe, is missing logic for when `contentOffset` is actually `null`. That is, consider you render `ScrollView` with `contentOffset` { x: 0, y: 100 } and then change that to null / undefined. I'd expect the content offset to invalidate (set to 0 - hope that's the default). ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [Android] [Fixed] - ScrollView, HorizontalScrollView: do not ignore `null` `contentOffset` prop Pull Request resolved: #28760 Test Plan: Tested locally within RNTester <details><summary>code</summary> <p> ```js const Ex = () => { let _scrollView: ?React.ElementRef<typeof ScrollView> = React.useRef(null); const [offset, setOffset] = React.useState({x: 0, y: 20}); setTimeout(() => { setOffset(undefined); }, 2000); return ( <View> <ScrollView ref={_scrollView} automaticallyAdjustContentInsets={false} onScroll={() => { console.log('onScroll!'); }} contentOffset={offset} scrollEventThrottle={200} style={styles.scrollView}> {ITEMS.map(createItemRow)} </ScrollView> <Button label="Scroll to top" onPress={() => { nullthrows(_scrollView.current).scrollTo({y: 0}); }} /> <Button label="Scroll to bottom" onPress={() => { nullthrows(_scrollView.current).scrollToEnd({animated: true}); }} /> <Button label="Flash scroll indicators" onPress={() => { nullthrows(_scrollView.current).flashScrollIndicators(); }} /> </View> ); }; ``` </p> </details> Reviewed By: shergin Differential Revision: D22298676 Pulled By: JoshuaGross fbshipit-source-id: e411ba4c8a276908e354d59085d164a38ae253c0
Summary
motivation: I was just checking out 30cc158
and noticed that the commit, I believe, is missing logic for when
contentOffsetis actuallynull.That is, consider you render
ScrollViewwithcontentOffset{ x: 0, y: 100 } and then change that to null / undefined. I'd expect the content offset to invalidate (set to 0 - hope that's the default).Changelog
[Android] [Fixed] - ScrollView, HorizontalScrollView: do not ignore
nullcontentOffsetpropTest Plan
Tested locally within RNTester
code