Allow dynamic update of itemDimension

This commit is contained in:
Saleel S
2018-01-11 18:16:11 +04:00
parent 1e178ea848
commit f71df1b295

View File

@@ -12,6 +12,14 @@ class SuperGrid extends Component {
this.state = this.getDimensions();
}
componentWillReceiveProps(nextProps) {
if (nextProps.itemDimension !== this.props.itemDimension) {
this.setState({
...this.getDimensions(this.state.totalDimension, nextProps.itemDimension),
});
}
}
onLayout(e) {
const { staticDimension, horizontal } = this.props;
if (!staticDimension) {
@@ -23,9 +31,9 @@ class SuperGrid extends Component {
}
}
getDimensions(lvDimension) {
getDimensions(lvDimension, itemDim) {
const { itemWidth, spacing, fixed, staticDimension, horizontal } = this.props;
let itemDimension = this.props.itemDimension;
let itemDimension = itemDim || this.props.itemDimension;
if (itemWidth) {
itemDimension = itemWidth;
console.warn('React Native Super Grid - property "itemWidth" is depreciated. Use "itemDimension" instead.');
@@ -38,7 +46,9 @@ class SuperGrid extends Component {
const itemsPerRow = Math.floor(availableDimension / itemTotalDimension);
const containerDimension = availableDimension / itemsPerRow;
return {
totalDimension,
itemDimension,
spacing,
itemsPerRow,