Skip to content

Commit

Permalink
Re-add patch to fix VirtualizedList memoization
Browse files Browse the repository at this point in the history
  • Loading branch information
brunolemos committed Oct 23, 2019
1 parent ec9bb0f commit e86c7dd
Show file tree
Hide file tree
Showing 2 changed files with 243 additions and 0 deletions.
131 changes: 131 additions & 0 deletions patches/react-native+0.61.2.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
diff --git a/node_modules/react-native/Libraries/Components/ScrollView/ScrollViewStickyHeader.js b/node_modules/react-native/Libraries/Components/ScrollView/ScrollViewStickyHeader.js
index c9a967f..bb5c547 100644
--- a/node_modules/react-native/Libraries/Components/ScrollView/ScrollViewStickyHeader.js
+++ b/node_modules/react-native/Libraries/Components/ScrollView/ScrollViewStickyHeader.js
@@ -59,7 +59,7 @@ class ScrollViewStickyHeader extends React.Component<Props, State> {
this.props.onLayout(event);
const child = React.Children.only(this.props.children);
if (child.props.onLayout) {
- child.props.onLayout(event);
+ child.props.onLayout(event, child.props.cellKey, child.props.index);
}
};

diff --git a/node_modules/react-native/Libraries/Lists/VirtualizedList.js b/node_modules/react-native/Libraries/Lists/VirtualizedList.js
index 7dffc17..ebc0fc6 100644
--- a/node_modules/react-native/Libraries/Lists/VirtualizedList.js
+++ b/node_modules/react-native/Libraries/Lists/VirtualizedList.js
@@ -746,11 +746,16 @@ class VirtualizedList extends React.PureComponent<Props, State> {
const {
CellRendererComponent,
ItemSeparatorComponent,
+ ListItemComponent,
data,
+ debug,
+ extraData,
getItem,
getItemCount,
+ getItemLayout,
horizontal,
keyExtractor,
+ renderItem,
} = this.props;
const stickyOffset = this.props.ListHeaderComponent ? 1 : 0;
const end = getItemCount(data) - 1;
@@ -776,9 +781,13 @@ class VirtualizedList extends React.PureComponent<Props, State> {
key={key}
prevCellKey={prevCellKey}
onUpdateSeparators={this._onUpdateSeparators}
- onLayout={e => this._onCellLayout(e, key, ii)}
+ onLayout={this._onCellLayout}
onUnmount={this._onCellUnmount}
- parentProps={this.props}
+ getItemLayout={getItemLayout}
+ renderItem={renderItem}
+ ListItemComponent={ListItemComponent}
+ extraData={extraData}
+ debug={debug}
ref={ref => {
this._cellRefs[key] = ref;
}}
@@ -1184,7 +1193,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
}
};

- _onCellLayout(e, cellKey, index) {
+ _onCellLayout = (e, cellKey, index): void => {
const layout = e.nativeEvent.layout;
const next = {
offset: this._selectOffset(layout),
@@ -1225,7 +1234,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {

this._computeBlankness();
this._updateViewableItems(this.props.data);
- }
+ };

_onCellUnmount = (cellKey: string) => {
const curr = this._frames[cellKey];
@@ -1760,14 +1769,13 @@ type CellRendererProps = {
index: number,
inversionStyle: ViewStyleProp,
item: Item,
- onLayout: (event: Object) => void, // This is extracted by ScrollViewStickyHeader
+ onLayout: (event: Object, key: string, index: number) => void, // This is extracted by ScrollViewStickyHeader
onUnmount: (cellKey: string) => void,
onUpdateSeparators: (cellKeys: Array<?string>, props: Object) => void,
- parentProps: {
- getItemLayout?: ?Function,
- renderItem?: ?RenderItemType<Item>,
- ListItemComponent?: ?(React.ComponentType<any> | React.Element<any>),
- },
+ getItemLayout?: ?Function,
+ renderItem: $PropertyType<OptionalProps, 'renderItem'>,
+ ListItemComponent?: ?(React.ComponentType<any> | React.Element<any>),
+ debug: ?boolean,
prevCellKey: ?string,
};

@@ -1849,6 +1857,10 @@ class CellRenderer extends React.Component<
this.props.onUnmount(this.props.cellKey);
}

+ _onLayout = (e): void =>
+ this.props.onLayout &&
+ this.props.onLayout(e, this.props.cellKey, this.props.index);
+
_renderElement(renderItem, ListItemComponent, item, index) {
if (renderItem && ListItemComponent) {
console.warn(
@@ -1883,14 +1895,16 @@ class CellRenderer extends React.Component<
const {
CellRendererComponent,
ItemSeparatorComponent,
+ ListItemComponent,
+ debug,
fillRateHelper,
+ getItemLayout,
horizontal,
- item,
index,
inversionStyle,
- parentProps,
+ item,
+ renderItem,
} = this.props;
- const {renderItem, getItemLayout, ListItemComponent} = parentProps;
const element = this._renderElement(
renderItem,
ListItemComponent,
@@ -1902,9 +1916,9 @@ class CellRenderer extends React.Component<
/* $FlowFixMe(>=0.68.0 site=react_native_fb) This comment suppresses an
* error found when Flow v0.68 was deployed. To see the error delete this
* comment and run Flow. */
- getItemLayout && !parentProps.debug && !fillRateHelper.enabled()
+ getItemLayout && !debug && !fillRateHelper.enabled()
? undefined
- : this.props.onLayout;
+ : this._onLayout;
// NOTE: that when this is a sticky header, `onLayout` will get automatically extracted and
// called explicitly by `ScrollViewStickyHeader`.
const itemSeparator = ItemSeparatorComponent && (
112 changes: 112 additions & 0 deletions patches/react-native-web+0.11.7.patch
Original file line number Diff line number Diff line change
Expand Up @@ -924,3 +924,115 @@ index c08437e..4bc0ae2 100644
});
export default VirtualizedList;
\ No newline at end of file
diff --git a/node_modules/react-native-web/src/vendor/react-native/VirtualizedList/index.js b/node_modules/react-native-web/src/vendor/react-native/VirtualizedList/index.js
index 7a2b1d0..1dc38c1 100644
--- a/node_modules/react-native-web/src/vendor/react-native/VirtualizedList/index.js
+++ b/node_modules/react-native-web/src/vendor/react-native/VirtualizedList/index.js
@@ -642,11 +642,16 @@ class VirtualizedList extends React.PureComponent<Props, State> {
const {
CellRendererComponent,
ItemSeparatorComponent,
+ ListItemComponent,
data,
+ debug,
+ extraData,
getItem,
getItemCount,
+ getItemLayout,
horizontal,
keyExtractor,
+ renderItem,
} = this.props;
const stickyOffset = this.props.ListHeaderComponent ? 1 : 0;
const end = getItemCount(data) - 1;
@@ -672,9 +677,11 @@ class VirtualizedList extends React.PureComponent<Props, State> {
key={key}
prevCellKey={prevCellKey}
onUpdateSeparators={this._onUpdateSeparators}
- onLayout={e => this._onCellLayout(e, key, ii)}
+ onLayout={this._onCellLayout}
onUnmount={this._onCellUnmount}
- parentProps={this.props}
+ ListItemComponent={ListItemComponent}
+ extraData={extraData}
+ debug={debug}
ref={ref => {
this._cellRefs[key] = ref;
}}
@@ -1018,7 +1025,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
}
};

- _onCellLayout(e, cellKey, index) {
+ _onCellLayout = (e, cellKey, index): void => {
const layout = e.nativeEvent.layout;
const next = {
offset: this._selectOffset(layout),
@@ -1047,7 +1054,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
this._frames[cellKey].inLayout = true;
}
this._computeBlankness();
- }
+ };

_onCellUnmount = (cellKey: string) => {
const curr = this._frames[cellKey];
@@ -1554,13 +1561,13 @@ class CellRenderer extends React.Component<
index: number,
inversionStyle: ?DangerouslyImpreciseStyleProp,
item: Item,
- onLayout: (event: Object) => void, // This is extracted by ScrollViewStickyHeader
+ onLayout: (event: Object, key: string, index: number) => void, // This is extracted by ScrollViewStickyHeader
onUnmount: (cellKey: string) => void,
onUpdateSeparators: (cellKeys: Array<?string>, props: Object) => void,
- parentProps: {
- getItemLayout?: ?Function,
- renderItem: renderItemType,
- },
+ getItemLayout?: ?Function,
+ renderItem: $PropertyType<OptionalProps, 'renderItem'>,
+ ListItemComponent?: ?(React.ComponentType<any> | React.Element<any>),
+ debug: ?boolean,
prevCellKey: ?string
},
$FlowFixMeState,
@@ -1620,18 +1627,24 @@ class CellRenderer extends React.Component<
this.props.onUnmount(this.props.cellKey);
}

+ _onLayout = (e): void =>
+ this.props.onLayout &&
+ this.props.onLayout(e, this.props.cellKey, this.props.index);
+
render() {
const {
CellRendererComponent,
ItemSeparatorComponent,
+ ListItemComponent,
+ debug,
fillRateHelper,
+ getItemLayout,
horizontal,
- item,
index,
inversionStyle,
- parentProps,
+ item,
+ renderItem,
} = this.props;
- const {renderItem, getItemLayout} = parentProps;
invariant(renderItem, 'no renderItem!');
const element = renderItem({
item,
@@ -1639,9 +1652,9 @@ class CellRenderer extends React.Component<
separators: this._separators,
});
const onLayout =
- getItemLayout && !parentProps.debug && !fillRateHelper.enabled()
+ getItemLayout && !debug && !fillRateHelper.enabled()
? undefined
- : this.props.onLayout;
+ : this._onLayout;
// NOTE: that when this is a sticky header, `onLayout` will get automatically extracted and
// called explicitly by `ScrollViewStickyHeader`.
const itemSeparator = ItemSeparatorComponent && (

0 comments on commit e86c7dd

Please sign in to comment.