mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Remove horizontal from defaultProps
Summary: Changelog: [Internal][Changed] - Remove horizontal from defaultProps as part of larger effort to remove defaultProps from VirtualizedList Reviewed By: nadiia Differential Revision: D26969583 fbshipit-source-id: c21ac15a220a68a58e32b78dcc37c053756b72cf
This commit is contained in:
committed by
Facebook GitHub Bot
parent
3ff7e86b0f
commit
cbc3d90fd4
@@ -304,7 +304,6 @@ type Props = {|
|
||||
|};
|
||||
|
||||
type DefaultProps = {|
|
||||
horizontal: boolean,
|
||||
initialNumToRender: number,
|
||||
keyExtractor: (item: Item, index: number) => string,
|
||||
maxToRenderPerBatch: number,
|
||||
@@ -322,6 +321,10 @@ type State = {
|
||||
last: number,
|
||||
};
|
||||
|
||||
function horizontalOrDefault(horizontal: ?boolean) {
|
||||
return horizontal ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Base implementation for the more convenient [`<FlatList>`](https://reactnative.dev/docs/flatlist.html)
|
||||
* and [`<SectionList>`](https://reactnative.dev/docs/sectionlist.html) components, which are also better
|
||||
@@ -380,7 +383,9 @@ class VirtualizedList extends React.PureComponent<Props, State> {
|
||||
}
|
||||
|
||||
this._scrollRef.scrollTo(
|
||||
this.props.horizontal ? {x: offset, animated} : {y: offset, animated},
|
||||
horizontalOrDefault(this.props.horizontal)
|
||||
? {x: offset, animated}
|
||||
: {y: offset, animated},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -502,7 +507,9 @@ class VirtualizedList extends React.PureComponent<Props, State> {
|
||||
}
|
||||
|
||||
this._scrollRef.scrollTo(
|
||||
this.props.horizontal ? {x: offset, animated} : {y: offset, animated},
|
||||
horizontalOrDefault(this.props.horizontal)
|
||||
? {x: offset, animated}
|
||||
: {y: offset, animated},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -560,7 +567,6 @@ class VirtualizedList extends React.PureComponent<Props, State> {
|
||||
}
|
||||
|
||||
static defaultProps: DefaultProps = {
|
||||
horizontal: false,
|
||||
initialNumToRender: 10,
|
||||
keyExtractor: (item: Item, index: number) => {
|
||||
if (item.key != null) {
|
||||
@@ -594,7 +600,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
|
||||
return {
|
||||
listKey: this._getListKey(),
|
||||
cellKey: this._getCellKey(),
|
||||
horizontal: !!this.props.horizontal,
|
||||
horizontal: horizontalOrDefault(this.props.horizontal),
|
||||
parent: this.context?.debugInfo,
|
||||
};
|
||||
}
|
||||
@@ -839,7 +845,8 @@ class VirtualizedList extends React.PureComponent<Props, State> {
|
||||
_isNestedWithSameOrientation(): boolean {
|
||||
const nestedContext = this.context;
|
||||
return !!(
|
||||
nestedContext && !!nestedContext.horizontal === !!this.props.horizontal
|
||||
nestedContext &&
|
||||
!!nestedContext.horizontal === horizontalOrDefault(this.props.horizontal)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -864,7 +871,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
|
||||
const {data, horizontal} = this.props;
|
||||
const isVirtualizationDisabled = this._isVirtualizationDisabled();
|
||||
const inversionStyle = this.props.inverted
|
||||
? this.props.horizontal
|
||||
? horizontalOrDefault(this.props.horizontal)
|
||||
? styles.horizontallyInverted
|
||||
: styles.verticallyInverted
|
||||
: null;
|
||||
@@ -1070,7 +1077,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
|
||||
value={{
|
||||
cellKey: null,
|
||||
getScrollMetrics: this._getScrollMetrics,
|
||||
horizontal: this.props.horizontal,
|
||||
horizontal: horizontalOrDefault(this.props.horizontal),
|
||||
getOutermostParentListRef: this._getOutermostParentListRef,
|
||||
getNestedChildState: this._getNestedChildState,
|
||||
registerAsNestedChild: this._registerAsNestedChild,
|
||||
@@ -1096,7 +1103,8 @@ class VirtualizedList extends React.PureComponent<Props, State> {
|
||||
{scrollContext => {
|
||||
if (
|
||||
scrollContext != null &&
|
||||
!scrollContext.horizontal === !this.props.horizontal &&
|
||||
!scrollContext.horizontal ===
|
||||
!horizontalOrDefault(this.props.horizontal) &&
|
||||
!this._hasWarned.nesting &&
|
||||
this.context == null
|
||||
) {
|
||||
@@ -1452,7 +1460,9 @@ class VirtualizedList extends React.PureComponent<Props, State> {
|
||||
...
|
||||
}>,
|
||||
): number {
|
||||
return !this.props.horizontal ? metrics.height : metrics.width;
|
||||
return !horizontalOrDefault(this.props.horizontal)
|
||||
? metrics.height
|
||||
: metrics.width;
|
||||
}
|
||||
|
||||
_selectOffset(
|
||||
@@ -1462,7 +1472,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
|
||||
...
|
||||
}>,
|
||||
): number {
|
||||
return !this.props.horizontal ? metrics.y : metrics.x;
|
||||
return !horizontalOrDefault(this.props.horizontal) ? metrics.y : metrics.x;
|
||||
}
|
||||
|
||||
_maybeCallOnEndReached() {
|
||||
|
||||
@@ -28,7 +28,6 @@ exports[`FlatList renders all the bells and whistles 1`] = `
|
||||
getItem={[Function]}
|
||||
getItemCount={[Function]}
|
||||
getItemLayout={[Function]}
|
||||
horizontal={false}
|
||||
initialNumToRender={10}
|
||||
keyExtractor={[Function]}
|
||||
maxToRenderPerBatch={10}
|
||||
@@ -130,7 +129,6 @@ exports[`FlatList renders empty list 1`] = `
|
||||
data={Array []}
|
||||
getItem={[Function]}
|
||||
getItemCount={[Function]}
|
||||
horizontal={false}
|
||||
initialNumToRender={10}
|
||||
keyExtractor={[Function]}
|
||||
maxToRenderPerBatch={10}
|
||||
@@ -158,7 +156,6 @@ exports[`FlatList renders null list 1`] = `
|
||||
<RCTScrollView
|
||||
getItem={[Function]}
|
||||
getItemCount={[Function]}
|
||||
horizontal={false}
|
||||
initialNumToRender={10}
|
||||
keyExtractor={[Function]}
|
||||
maxToRenderPerBatch={10}
|
||||
@@ -199,7 +196,6 @@ exports[`FlatList renders simple list (multiple columns) 1`] = `
|
||||
}
|
||||
getItem={[Function]}
|
||||
getItemCount={[Function]}
|
||||
horizontal={false}
|
||||
initialNumToRender={10}
|
||||
keyExtractor={[Function]}
|
||||
maxToRenderPerBatch={10}
|
||||
@@ -276,7 +272,6 @@ exports[`FlatList renders simple list 1`] = `
|
||||
}
|
||||
getItem={[Function]}
|
||||
getItemCount={[Function]}
|
||||
horizontal={false}
|
||||
initialNumToRender={10}
|
||||
keyExtractor={[Function]}
|
||||
maxToRenderPerBatch={10}
|
||||
@@ -343,7 +338,6 @@ exports[`FlatList renders simple list using ListItemComponent (multiple columns)
|
||||
}
|
||||
getItem={[Function]}
|
||||
getItemCount={[Function]}
|
||||
horizontal={false}
|
||||
initialNumToRender={10}
|
||||
keyExtractor={[Function]}
|
||||
maxToRenderPerBatch={10}
|
||||
@@ -420,7 +414,6 @@ exports[`FlatList renders simple list using ListItemComponent 1`] = `
|
||||
}
|
||||
getItem={[Function]}
|
||||
getItemCount={[Function]}
|
||||
horizontal={false}
|
||||
initialNumToRender={10}
|
||||
keyExtractor={[Function]}
|
||||
maxToRenderPerBatch={10}
|
||||
|
||||
@@ -19,7 +19,6 @@ exports[`SectionList rendering empty section headers is fine 1`] = `
|
||||
}
|
||||
getItem={[Function]}
|
||||
getItemCount={[Function]}
|
||||
horizontal={false}
|
||||
initialNumToRender={10}
|
||||
keyExtractor={[Function]}
|
||||
maxToRenderPerBatch={10}
|
||||
@@ -82,7 +81,6 @@ exports[`SectionList renders a footer when there is no data 1`] = `
|
||||
}
|
||||
getItem={[Function]}
|
||||
getItemCount={[Function]}
|
||||
horizontal={false}
|
||||
initialNumToRender={10}
|
||||
keyExtractor={[Function]}
|
||||
maxToRenderPerBatch={10}
|
||||
@@ -137,7 +135,6 @@ exports[`SectionList renders a footer when there is no data and no header 1`] =
|
||||
}
|
||||
getItem={[Function]}
|
||||
getItemCount={[Function]}
|
||||
horizontal={false}
|
||||
initialNumToRender={10}
|
||||
keyExtractor={[Function]}
|
||||
maxToRenderPerBatch={10}
|
||||
@@ -223,7 +220,6 @@ exports[`SectionList renders all the bells and whistles 1`] = `
|
||||
}
|
||||
getItem={[Function]}
|
||||
getItemCount={[Function]}
|
||||
horizontal={false}
|
||||
initialNumToRender={Infinity}
|
||||
keyExtractor={[Function]}
|
||||
maxToRenderPerBatch={10}
|
||||
@@ -415,7 +411,6 @@ exports[`SectionList renders empty list 1`] = `
|
||||
data={Array []}
|
||||
getItem={[Function]}
|
||||
getItemCount={[Function]}
|
||||
horizontal={false}
|
||||
initialNumToRender={10}
|
||||
keyExtractor={[Function]}
|
||||
maxToRenderPerBatch={10}
|
||||
|
||||
@@ -43,7 +43,6 @@ exports[`VirtualizedList forwards correct stickyHeaderIndices when all in initia
|
||||
getItem={[Function]}
|
||||
getItemCount={[Function]}
|
||||
getItemLayout={[Function]}
|
||||
horizontal={false}
|
||||
initialNumToRender={10}
|
||||
keyExtractor={[Function]}
|
||||
maxToRenderPerBatch={10}
|
||||
@@ -190,7 +189,6 @@ exports[`VirtualizedList forwards correct stickyHeaderIndices when partially in
|
||||
getItem={[Function]}
|
||||
getItemCount={[Function]}
|
||||
getItemLayout={[Function]}
|
||||
horizontal={false}
|
||||
initialNumToRender={5}
|
||||
keyExtractor={[Function]}
|
||||
maxToRenderPerBatch={10}
|
||||
@@ -276,7 +274,6 @@ exports[`VirtualizedList handles nested lists 1`] = `
|
||||
}
|
||||
getItem={[Function]}
|
||||
getItemCount={[Function]}
|
||||
horizontal={false}
|
||||
initialNumToRender={10}
|
||||
keyExtractor={[Function]}
|
||||
maxToRenderPerBatch={10}
|
||||
@@ -439,7 +436,6 @@ exports[`VirtualizedList handles separators correctly 1`] = `
|
||||
}
|
||||
getItem={[Function]}
|
||||
getItemCount={[Function]}
|
||||
horizontal={false}
|
||||
initialNumToRender={10}
|
||||
keyExtractor={[Function]}
|
||||
maxToRenderPerBatch={10}
|
||||
@@ -520,7 +516,6 @@ exports[`VirtualizedList handles separators correctly 2`] = `
|
||||
}
|
||||
getItem={[Function]}
|
||||
getItemCount={[Function]}
|
||||
horizontal={false}
|
||||
initialNumToRender={10}
|
||||
keyExtractor={[Function]}
|
||||
maxToRenderPerBatch={10}
|
||||
@@ -601,7 +596,6 @@ exports[`VirtualizedList handles separators correctly 3`] = `
|
||||
}
|
||||
getItem={[Function]}
|
||||
getItemCount={[Function]}
|
||||
horizontal={false}
|
||||
initialNumToRender={10}
|
||||
keyExtractor={[Function]}
|
||||
maxToRenderPerBatch={10}
|
||||
@@ -754,7 +748,6 @@ exports[`VirtualizedList keeps sticky headers realized after scrolled out of vie
|
||||
getItem={[Function]}
|
||||
getItemCount={[Function]}
|
||||
getItemLayout={[Function]}
|
||||
horizontal={false}
|
||||
initialNumToRender={1}
|
||||
keyExtractor={[Function]}
|
||||
maxToRenderPerBatch={10}
|
||||
@@ -947,7 +940,6 @@ exports[`VirtualizedList realizes sticky headers in viewport on batched render 1
|
||||
getItem={[Function]}
|
||||
getItemCount={[Function]}
|
||||
getItemLayout={[Function]}
|
||||
horizontal={false}
|
||||
initialNumToRender={1}
|
||||
keyExtractor={[Function]}
|
||||
maxToRenderPerBatch={10}
|
||||
@@ -1047,7 +1039,6 @@ exports[`VirtualizedList renders all the bells and whistles 1`] = `
|
||||
getItem={[Function]}
|
||||
getItemCount={[Function]}
|
||||
getItemLayout={[Function]}
|
||||
horizontal={false}
|
||||
initialNumToRender={10}
|
||||
invertStickyHeaders={true}
|
||||
inverted={true}
|
||||
@@ -1230,7 +1221,6 @@ exports[`VirtualizedList renders empty list 1`] = `
|
||||
data={Array []}
|
||||
getItem={[Function]}
|
||||
getItemCount={[Function]}
|
||||
horizontal={false}
|
||||
initialNumToRender={10}
|
||||
keyExtractor={[Function]}
|
||||
maxToRenderPerBatch={10}
|
||||
@@ -1260,7 +1250,6 @@ exports[`VirtualizedList renders empty list with empty component 1`] = `
|
||||
data={Array []}
|
||||
getItem={[Function]}
|
||||
getItemCount={[Function]}
|
||||
horizontal={false}
|
||||
initialNumToRender={10}
|
||||
keyExtractor={[Function]}
|
||||
maxToRenderPerBatch={10}
|
||||
@@ -1306,7 +1295,6 @@ exports[`VirtualizedList renders list with empty component 1`] = `
|
||||
}
|
||||
getItem={[Function]}
|
||||
getItemCount={[Function]}
|
||||
horizontal={false}
|
||||
initialNumToRender={10}
|
||||
keyExtractor={[Function]}
|
||||
maxToRenderPerBatch={10}
|
||||
@@ -1341,7 +1329,6 @@ exports[`VirtualizedList renders null list 1`] = `
|
||||
<RCTScrollView
|
||||
getItem={[Function]}
|
||||
getItemCount={[Function]}
|
||||
horizontal={false}
|
||||
initialNumToRender={10}
|
||||
keyExtractor={[Function]}
|
||||
maxToRenderPerBatch={10}
|
||||
@@ -1380,7 +1367,6 @@ exports[`VirtualizedList renders simple list 1`] = `
|
||||
}
|
||||
getItem={[Function]}
|
||||
getItemCount={[Function]}
|
||||
horizontal={false}
|
||||
initialNumToRender={10}
|
||||
keyExtractor={[Function]}
|
||||
maxToRenderPerBatch={10}
|
||||
@@ -1445,7 +1431,6 @@ exports[`VirtualizedList renders simple list using ListItemComponent 1`] = `
|
||||
}
|
||||
getItem={[Function]}
|
||||
getItemCount={[Function]}
|
||||
horizontal={false}
|
||||
initialNumToRender={10}
|
||||
keyExtractor={[Function]}
|
||||
maxToRenderPerBatch={10}
|
||||
@@ -1502,7 +1487,6 @@ exports[`VirtualizedList test getItem functionality where data is not an Array 1
|
||||
}
|
||||
getItem={[Function]}
|
||||
getItemCount={[Function]}
|
||||
horizontal={false}
|
||||
initialNumToRender={10}
|
||||
keyExtractor={[Function]}
|
||||
maxToRenderPerBatch={10}
|
||||
@@ -1545,7 +1529,6 @@ exports[`VirtualizedList warns if both renderItem or ListItemComponent are speci
|
||||
}
|
||||
getItem={[Function]}
|
||||
getItemCount={[Function]}
|
||||
horizontal={false}
|
||||
initialNumToRender={10}
|
||||
keyExtractor={[Function]}
|
||||
maxToRenderPerBatch={10}
|
||||
|
||||
@@ -19,7 +19,6 @@ exports[`VirtualizedSectionList handles nested lists 1`] = `
|
||||
}
|
||||
getItem={[Function]}
|
||||
getItemCount={[Function]}
|
||||
horizontal={false}
|
||||
initialNumToRender={10}
|
||||
keyExtractor={[Function]}
|
||||
maxToRenderPerBatch={10}
|
||||
@@ -234,7 +233,6 @@ exports[`VirtualizedSectionList handles separators correctly 1`] = `
|
||||
}
|
||||
getItem={[Function]}
|
||||
getItemCount={[Function]}
|
||||
horizontal={false}
|
||||
initialNumToRender={10}
|
||||
keyExtractor={[Function]}
|
||||
maxToRenderPerBatch={10}
|
||||
@@ -373,7 +371,6 @@ exports[`VirtualizedSectionList handles separators correctly 2`] = `
|
||||
}
|
||||
getItem={[Function]}
|
||||
getItemCount={[Function]}
|
||||
horizontal={false}
|
||||
initialNumToRender={10}
|
||||
keyExtractor={[Function]}
|
||||
maxToRenderPerBatch={10}
|
||||
@@ -512,7 +509,6 @@ exports[`VirtualizedSectionList handles separators correctly 3`] = `
|
||||
}
|
||||
getItem={[Function]}
|
||||
getItemCount={[Function]}
|
||||
horizontal={false}
|
||||
initialNumToRender={10}
|
||||
keyExtractor={[Function]}
|
||||
maxToRenderPerBatch={10}
|
||||
@@ -662,7 +658,6 @@ exports[`VirtualizedSectionList renders all the bells and whistles 1`] = `
|
||||
getItem={[Function]}
|
||||
getItemCount={[Function]}
|
||||
getItemLayout={[Function]}
|
||||
horizontal={false}
|
||||
initialNumToRender={10}
|
||||
invertStickyHeaders={true}
|
||||
inverted={true}
|
||||
@@ -885,7 +880,6 @@ exports[`VirtualizedSectionList renders empty list 1`] = `
|
||||
data={Array []}
|
||||
getItem={[Function]}
|
||||
getItemCount={[Function]}
|
||||
horizontal={false}
|
||||
initialNumToRender={10}
|
||||
keyExtractor={[Function]}
|
||||
maxToRenderPerBatch={10}
|
||||
@@ -915,7 +909,6 @@ exports[`VirtualizedSectionList renders empty list with empty component 1`] = `
|
||||
data={Array []}
|
||||
getItem={[Function]}
|
||||
getItemCount={[Function]}
|
||||
horizontal={false}
|
||||
initialNumToRender={10}
|
||||
keyExtractor={[Function]}
|
||||
maxToRenderPerBatch={10}
|
||||
@@ -966,7 +959,6 @@ exports[`VirtualizedSectionList renders list with empty component 1`] = `
|
||||
}
|
||||
getItem={[Function]}
|
||||
getItemCount={[Function]}
|
||||
horizontal={false}
|
||||
initialNumToRender={10}
|
||||
keyExtractor={[Function]}
|
||||
maxToRenderPerBatch={10}
|
||||
@@ -1027,7 +1019,6 @@ exports[`VirtualizedSectionList renders simple list 1`] = `
|
||||
}
|
||||
getItem={[Function]}
|
||||
getItemCount={[Function]}
|
||||
horizontal={false}
|
||||
initialNumToRender={10}
|
||||
keyExtractor={[Function]}
|
||||
maxToRenderPerBatch={10}
|
||||
|
||||
Reference in New Issue
Block a user