Skip to content

Commit 32e73ee

Browse files
committed
Do not rerender on focus change if mask doesn't change
1 parent 8a9c4e2 commit 32e73ee

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Libraries/Lists/VirtualizedList.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,6 @@ let _keylessItemComponentName: string = '';
315315
type State = {
316316
renderMask: CellRenderMask,
317317
cellsAroundViewport: {first: number, last: number},
318-
lastFocusedItem: ?number,
319318
};
320319

321320
/**
@@ -741,7 +740,6 @@ class VirtualizedList extends React.PureComponent<Props, State> {
741740
let initialState: State = {
742741
cellsAroundViewport: initialRenderRegion,
743742
renderMask: VirtualizedList._createRenderMask(props, initialRenderRegion),
744-
lastFocusedItem: null,
745743
};
746744

747745
if (this._isNestedWithSameOrientation()) {
@@ -974,7 +972,6 @@ class VirtualizedList extends React.PureComponent<Props, State> {
974972
return {
975973
cellsAroundViewport: prevState.cellsAroundViewport,
976974
renderMask: VirtualizedList._createRenderMask(newProps, constrainedCells),
977-
lastFocusedItem: prevState.lastFocusedItem,
978975
};
979976
}
980977

@@ -1379,6 +1376,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
13791376
_hiPriInProgress: boolean = false; // flag to prevent infinite hiPri cell limit update
13801377
_highestMeasuredFrameIndex = 0;
13811378
_indicesToKeys: Map<number, string> = new Map();
1379+
_lastFocusedItem: ?number = null;
13821380
_nestedChildLists: Map<
13831381
string,
13841382
{
@@ -1488,12 +1486,16 @@ class VirtualizedList extends React.PureComponent<Props, State> {
14881486
}
14891487

14901488
_onCellFocusCapture(itemIndex: number) {
1489+
this._lastFocusedItem = itemIndex;
14911490
const renderMask = VirtualizedList._createRenderMask(
14921491
this.props,
14931492
this.state.cellsAroundViewport,
1494-
itemIndex,
1493+
this._lastFocusedItem,
14951494
);
1496-
this.setState({...this.state, renderMask, lastFocusedItem: itemIndex});
1495+
1496+
if (!renderMask.equals(this.state.renderMask)) {
1497+
this.setState({...this.state, renderMask});
1498+
}
14971499
}
14981500

14991501
_onCellUnmount = (cellKey: string) => {
@@ -1924,7 +1926,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
19241926
const renderMask = VirtualizedList._createRenderMask(
19251927
props,
19261928
cellsAroundViewport,
1927-
state.lastFocusedItem,
1929+
this._lastFocusedItem,
19281930
);
19291931

19301932
if (

0 commit comments

Comments
 (0)