Add onLayout callback prop

This commit is contained in:
Antoine Taillefer
2018-07-05 12:23:32 +02:00
parent da38fd206a
commit d2c225224b
4 changed files with 22 additions and 4 deletions

View File

@@ -23,7 +23,7 @@ class SuperGrid extends Component {
}
onLayout(e) {
const { staticDimension, horizontal } = this.props;
const { staticDimension, horizontal, onLayout } = this.props;
if (!staticDimension) {
const { width, height } = e.nativeEvent.layout || {};
@@ -31,6 +31,10 @@ class SuperGrid extends Component {
...this.getDimensions(horizontal ? height : width),
});
}
// run onLayout callback if provided
if (onLayout) {
onLayout(e);
}
}
getDimensions(lvDimension, itemDim) {
@@ -142,7 +146,7 @@ class SuperGrid extends Component {
render() {
const { items, style, spacing, fixed, itemDimension, renderItem,
horizontal, ...props } = this.props;
horizontal, onLayout, ...props } = this.props;
const { itemsPerRow } = this.state;
const chunked = chunkArray(items, itemsPerRow); //Splitting the data into rows
@@ -182,6 +186,7 @@ SuperGrid.propTypes = {
style: ViewPropTypes.style,
staticDimension: PropTypes.number,
horizontal: PropTypes.bool,
onLayout: PropTypes.func,
};
SuperGrid.defaultProps = {