Skip to content

Commit

Permalink
Make VList in ScrollView warning consider horizontal prop
Browse files Browse the repository at this point in the history
Summary: It's ok to put VLists in ScrollViews with different scroll directions.

Reviewed By: yungsters

Differential Revision: D16217209

fbshipit-source-id: 7b1c3e93c19867da7414ccda4cda8cc89d25d522
  • Loading branch information
sahrens authored and facebook-github-bot committed Jul 15, 2019
1 parent 15f11f3 commit 7d09680
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
16 changes: 13 additions & 3 deletions Libraries/Components/ScrollView/ScrollView.js
Original file line number Diff line number Diff line change
Expand Up @@ -585,9 +585,12 @@ function createScrollResponder(
return scrollResponder;
}

type ContextType = {||} | null;
type ContextType = {|horizontal: boolean|} | null;
const Context = React.createContext<ContextType>(null);
const standardContext: ContextType = Object.freeze({}); // not null with option value to add more info in the future
const standardHorizontalContext: ContextType = Object.freeze({
horizontal: true,
});
const standardVerticalContext: ContextType = Object.freeze({horizontal: false});

/**
* Component that wraps platform ScrollView while providing
Expand Down Expand Up @@ -1022,7 +1025,14 @@ class ScrollView extends React.Component<Props, State> {
});
}
children = (
<Context.Provider value={standardContext}>{children}</Context.Provider>
<Context.Provider
value={
this.props.horizontal === true
? standardHorizontalContext
: standardVerticalContext
}>
{children}
</Context.Provider>
);

const hasStickyHeaders =
Expand Down
4 changes: 3 additions & 1 deletion Libraries/Lists/VirtualizedList.js
Original file line number Diff line number Diff line change
Expand Up @@ -984,12 +984,14 @@ class VirtualizedList extends React.PureComponent<Props, State> {
{scrollContext => {
if (
scrollContext != null &&
!scrollContext.horizontal === !this.props.horizontal &&
!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.',
'VirtualizedLists should never be nested inside plain ScrollViews with the same ' +
'orientation - use another VirtualizedList-backed container instead.',
);
this._hasWarned.nesting = true;
}
Expand Down

0 comments on commit 7d09680

Please sign in to comment.