Skip to content

Commit a2b0ee0

Browse files
janicduplessisfacebook-github-bot
authored andcommitted
FlatList - Add dev validation of the object returned by getItemLayout
Summary: Returning an object that doesn't have all the required properties from `getItemLayout` doesn't cause a flow error (maybe because we are using `createAnimatedComponent`) and caused ALL items to be rendered which caused perf issues that were hard to debug (typo lenght -> length -_-). This adds a simple warning in DEV mode using checkPropTypes. **Test plan** Tested in RNTester by passing a bad `getItemLayout` function. ![image](https://cloud.githubusercontent.com/assets/2677334/26329030/5b32ba90-3f13-11e7-9190-08f05a5c0682.png) Closes #14111 Differential Revision: D5283942 Pulled By: sahrens fbshipit-source-id: 8909532dfddd8628b7fb3380c198f0dfa88f240a
1 parent 407ec00 commit a2b0ee0

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

Libraries/Lists/VirtualizedList.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,19 @@ class VirtualizedList extends React.PureComponent<OptionalProps, Props, State> {
10971097
if (!frame || frame.index !== index) {
10981098
if (getItemLayout) {
10991099
frame = getItemLayout(data, index);
1100+
if (__DEV__) {
1101+
const frameType = PropTypes.shape({
1102+
length: PropTypes.number.isRequired,
1103+
offset: PropTypes.number.isRequired,
1104+
index: PropTypes.number.isRequired,
1105+
}).isRequired;
1106+
PropTypes.checkPropTypes(
1107+
{frame: frameType},
1108+
{frame},
1109+
'frame',
1110+
'VirtualizedList.getItemLayout'
1111+
);
1112+
}
11001113
}
11011114
}
11021115
return frame;

0 commit comments

Comments
 (0)