Uh oh!
There was an error while loading. Please reload this page.
[Idea: ScrollView] Add getScrollResponder to ScrollView for composition - #766
[Idea: ScrollView] Add getScrollResponder to ScrollView for composition#766ide wants to merge 1 commit into
getScrollResponder to ScrollView for composition#766Conversation
nicklockwood
commented
Apr 9, 2015
I think I need a little more context about how this is used. Do you have an example implementation you can point me to? |
ide
commented
Apr 9, 2015
I'll start with some background to paint a complete picture: I'm building "higher-order" scroll views that have some extra functionality. For example, an infinite scroll view invokes a callback to fetch more data when the scroll position approaches the end. This could look like: classInfiniteScrollViewextendsReact.Component{scrollTo(destY,destX){this.refs.scrollView.scrollTo(destY,destX);}render(){return(<ScrollView{...this.props}ref="scrollView"onScroll={(event)=>{if(this._shouldLoadMoreContent(event)){this.props.onLoadMore();}}}>{this.props.children}</ScrollView>);}}// * this could be a mixin, but there are other advanced scroll views that require// a new component classNow I'd like to use a different kind of scroll view, like a ListView, ReversedScrollView, etc. so I add a prop like The one snag is implementing methods like
I prefer the first approach because if ScrollView's methods are added/removed/renamed, the code for all other scrollable components doesn't need to be updated. It's a little more verbose with the ScrollableMixin={scrollTo(destY,destX){invariant(this.getScrollResponder,'Scrollable components must implement getScrollResponder');this.getScrollResponder().scrollTo(destY,destX);}}; |
nicklockwood
commented
Apr 11, 2015
Thank you for the detailed explanation. That makes a lot of sense to me. @vjeux? |
vjeux
commented
Apr 11, 2015
I've been meaning to do something similar for a while in order to support both iOS and Android specific list views but a single ListView/InfiniteScrollView/RefreshableScrollView... We've been moving away from passing a class as props to passing a function. This way the call site can pass props and the implementation can cloneElement to pass props as well. |
ide
commented
Apr 11, 2015
@vjeux good idea with the function. Just wondering, is there a reason the prop takes a function instead of a component instance directly? Maybe how the ref owner is determined? |
vjeux
commented
Apr 11, 2015
More about future proofing the api, i can almost guarantee you that you're going to want to pass arguments computed from within the extended scroll view component at some point |
ide
commented
Apr 13, 2015
Thought about it some more - the function also lets us do nested composition e.g. <ScrollViewArenderScrollView={()=><ScrollViewBrenderScrollView={()=><ScrollViewC/>}/>}/> |
6286480 to
bf524eeComparebc49683 to
a02056fCompareThis is a proposal to add `getScrollResponder` to all ScrollView-like components, including ListView. This allows multiple higher-order scroll views to be composed while allowing the owner of the top-level scroll view to call `scrollableView.getScrollResponder().scrollTo(...)` regardless of whether `scrollableView` is a ScrollView, ListView, InvertedScrollView, etc.
getScrollResponder to ScrollView for compositiongetScrollResponder to ScrollView for compositionsahrens
commented
Jun 11, 2015
Oops, wrong PR. |
sahrens
commented
Jun 11, 2015
@facebook-github-bot import |
facebook-github-bot
commented
Jun 11, 2015
Thanks for importing. If you are an FB employee go to https://our.intern.facebook.com/intern/opensource/github/pull_request/622194451249017/int_phab to review. |
…tion Summary: This is a proposal to add `getScrollResponder` to all ScrollView-like components, including ListView. This allows multiple higher-order scroll views to be composed while allowing the owner of the top-level scroll view to call `scrollableView.getScrollResponder().scrollTo(...)` regardless of whether `scrollableView` is a ScrollView, ListView, InvertedScrollView, etc. Closesreact#766 Github Author: James Ide <ide@jameside.com> Test Plan: Imported from GitHub, without a `Test Plan:` line.
…tion Summary: This is a proposal to add `getScrollResponder` to all ScrollView-like components, including ListView. This allows multiple higher-order scroll views to be composed while allowing the owner of the top-level scroll view to call `scrollableView.getScrollResponder().scrollTo(...)` regardless of whether `scrollableView` is a ScrollView, ListView, InvertedScrollView, etc. Closesreact#766 Github Author: James Ide <ide@jameside.com> Test Plan: Imported from GitHub, without a `Test Plan:` line.
This is a proposal to add
getScrollResponderto all ScrollView-like components, including ListView. This allows multiple higher-order scroll views to be composed while allowing the owner of the top-level scroll view to callscrollableView.getScrollResponder().scrollTo(...)regardless of whetherscrollableViewis a ScrollView, ListView, InvertedScrollView, etc.