diff --git a/Libraries/Components/ScrollView/ScrollView.js b/Libraries/Components/ScrollView/ScrollView.js index 260bc0fd94c..ba00259648d 100644 --- a/Libraries/Components/ScrollView/ScrollView.js +++ b/Libraries/Components/ScrollView/ScrollView.js @@ -573,6 +573,10 @@ function createScrollResponder( return scrollResponder; } +type ContextType = {||} | null; +const Context = React.createContext(null); +const standardContext: ContextType = Object.freeze({}); // not null with option value to add more info in the future + /** * Component that wraps platform ScrollView while providing * integration with touch locking "responder" system. @@ -609,6 +613,7 @@ function createScrollResponder( * supports out of the box. */ class ScrollView extends React.Component { + static Context = Context; /** * Part 1: Removing ScrollResponder.Mixin: * @@ -999,6 +1004,9 @@ class ScrollView extends React.Component { } }); } + children = ( + {children} + ); const hasStickyHeaders = Array.isArray(stickyHeaderIndices) && stickyHeaderIndices.length > 0; diff --git a/Libraries/Lists/VirtualizedList.js b/Libraries/Lists/VirtualizedList.js index d060dbf9fa6..534e10783df 100644 --- a/Libraries/Lists/VirtualizedList.js +++ b/Libraries/Lists/VirtualizedList.js @@ -968,7 +968,7 @@ class VirtualizedList extends React.PureComponent { this._hasMore = this.state.last < this.props.getItemCount(this.props.data) - 1; - const ret = React.cloneElement( + const innerRet = React.cloneElement( (this.props.renderScrollComponent || this._defaultRenderScrollComponent)( scrollProps, ), @@ -977,6 +977,27 @@ class VirtualizedList extends React.PureComponent { }, cells, ); + let ret = innerRet; + if (__DEV__) { + ret = ( + + {scrollContext => { + if ( + scrollContext != null && + !this._hasWarned.nesting && + this.context.virtualizedList == null + ) { + // TODO (T46547044): use React.warn once 16.9 is sync'd: https://github.com/facebook/react/pull/15170 + console.warn( + 'VirtualizedLists should never be nested inside a plain ScrollView - use another VirtualizedList-backed container instead.', + ); + this._hasWarned.nesting = true; + } + return innerRet; + }} + + ); + } if (this.props.debug) { return (