From c3d0cc2cb45fd11bb7b610020909a17fa51e95a8 Mon Sep 17 00:00:00 2001 From: Janic Duplessis Date: Mon, 22 May 2017 17:16:48 -0400 Subject: [PATCH] FlatList - Add dev validation of the object returned by getItemLayout --- Libraries/Lists/VirtualizedList.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Libraries/Lists/VirtualizedList.js b/Libraries/Lists/VirtualizedList.js index 21ce56dc0e6163..45c67090641317 100644 --- a/Libraries/Lists/VirtualizedList.js +++ b/Libraries/Lists/VirtualizedList.js @@ -13,6 +13,7 @@ const Batchinator = require('Batchinator'); const FillRateHelper = require('FillRateHelper'); +const PropTypes = require('prop-types'); const React = require('React'); const ReactNative = require('ReactNative'); const RefreshControl = require('RefreshControl'); @@ -841,6 +842,19 @@ class VirtualizedList extends React.PureComponent { if (!frame || frame.index !== index) { if (getItemLayout) { frame = getItemLayout(data, index); + if (__DEV__) { + const frameType = PropTypes.shape({ + length: PropTypes.number.isRequired, + offset: PropTypes.number.isRequired, + index: PropTypes.number.isRequired, + }).isRequired; + PropTypes.checkPropTypes( + {frame: frameType}, + {frame}, + 'frame', + 'VirtualizedList.getItemLayout' + ); + } } } return frame;