Make VList in ScrollView warning consider horizontal prop

Summary: It's ok to put VLists in ScrollViews with different scroll directions.

Reviewed By: yungsters

Differential Revision: D16217209

fbshipit-source-id: 7b1c3e93c19867da7414ccda4cda8cc89d25d522
This commit is contained in:
Spencer Ahrens 2019-07-15 13:27:56 -07:00 коммит произвёл Facebook Github Bot
Родитель 15f11f3e59
Коммит 7d096803d1
2 изменённых файлов: 16 добавлений и 4 удалений

Просмотреть файл

@ -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
@ -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 =

Просмотреть файл

@ -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;
}