mirror of
https://github.com/zhigang1992/react-native-super-grid.git
synced 2026-04-29 21:05:25 +08:00
Add onLayout callback prop
This commit is contained in:
9
index.js
9
index.js
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user