Skip to content

Commit 8cdaa82

Browse files
committed
Do not rerender on focus change if mask doesn't change
1 parent 64f3868 commit 8cdaa82

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
/**
@@ -739,7 +738,6 @@ class VirtualizedList extends React.PureComponent<Props, State> {
739738
let initialState: State = {
740739
cellsAroundViewport: initialRenderRegion,
741740
renderMask: VirtualizedList._createRenderMask(props, initialRenderRegion),
742-
lastFocusedItem: null,
743741
};
744742

745743
if (this._isNestedWithSameOrientation()) {
@@ -972,7 +970,6 @@ class VirtualizedList extends React.PureComponent<Props, State> {
972970
return {
973971
cellsAroundViewport: prevState.cellsAroundViewport,
974972
renderMask: VirtualizedList._createRenderMask(newProps, constrainedCells),
975-
lastFocusedItem: prevState.lastFocusedItem,
976973
};
977974
}
978975

@@ -1377,6 +1374,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
13771374
_hiPriInProgress: boolean = false; // flag to prevent infinite hiPri cell limit update
13781375
_highestMeasuredFrameIndex = 0;
13791376
_indicesToKeys: Map<number, string> = new Map();
1377+
_lastFocusedItem: ?number = null;
13801378
_nestedChildLists: Map<
13811379
string,
13821380
{
@@ -1486,12 +1484,16 @@ class VirtualizedList extends React.PureComponent<Props, State> {
14861484
}
14871485

14881486
_onCellFocusCapture(itemIndex: number) {
1487+
this._lastFocusedItem = itemIndex;
14891488
const renderMask = VirtualizedList._createRenderMask(
14901489
this.props,
14911490
this.state.cellsAroundViewport,
1492-
itemIndex,
1491+
this._lastFocusedItem,
14931492
);
1494-
this.setState({...this.state, renderMask, lastFocusedItem: itemIndex});
1493+
1494+
if (!renderMask.equals(this.state.renderMask)) {
1495+
this.setState({...this.state, renderMask});
1496+
}
14951497
}
14961498

14971499
_onCellUnmount = (cellKey: string) => {
@@ -1922,7 +1924,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
19221924
const renderMask = VirtualizedList._createRenderMask(
19231925
props,
19241926
cellsAroundViewport,
1925-
state.lastFocusedItem,
1927+
this._lastFocusedItem,
19261928
);
19271929

19281930
if (

0 commit comments

Comments
 (0)