Authored by 张丽霞

红人店铺lauout计算高度缓存,review by Redding

... ... @@ -50,6 +50,7 @@ export default class RedBrand extends Component {
this._calculateSectionRealHeight = this._calculateSectionRealHeight.bind(this);
this.containerHeight = 0;
this.sectionData = [];
this.layoutLenghtOffesetForIndex = {};
}
_onPressLaunchProfile(value){
... ... @@ -66,10 +67,6 @@ export default class RedBrand extends Component {
} else {
this.refs.redBrandList && this.refs.redBrandList.scrollToLocation({itemIndex: 0,sectionIndex: 2, viewPosition: 0, animated: false});
}
this.props.onPressProductFilter && this.props.onPressProductFilter(value);
}
... ... @@ -85,6 +82,7 @@ export default class RedBrand extends Component {
launchProfile,
productListForNew,
shopsdecorator,
fliter,
} = this.props;
let result ={
length: 0,
... ... @@ -92,11 +90,13 @@ export default class RedBrand extends Component {
}
let realContainerHeight = 0;
let countNumb = 0;
dataSource.map((item, index) => {
for (var i = 0; i < dataSource.length; i++) {
let item = dataSource[i];
if (item.key == 'ShopBanner') {
if (!shopsdecorator || shopsdecorator.template_type != '1') {
result.length = Math.ceil((234/750)*width); //header
if (countNumb == layoutIndex) {
this.layoutLenghtOffesetForIndex['fliter' + fliter + 'row' + countNumb] = result;
return result;
}
realContainerHeight += Math.ceil((234/750)*width); //header
... ... @@ -104,13 +104,20 @@ export default class RedBrand extends Component {
}else if(item.key == 'brandReource') {
realContainerHeight += 44; //height of RedBrandStoreFilter
countNumb++;
if (countNumb == layoutIndex) {
result.offset = realContainerHeight - 44;
result.length = 44;
this.layoutLenghtOffesetForIndex['fliter' + fliter + 'row' + countNumb] = result;
return result;
}
let sectionDataSource = item.data;
if (sectionDataSource.length == 0) {
result.offset = realContainerHeight;
result.length = 0;
return result;
}
sectionDataSource.map((shopsdecoratorItem, index) => {
for (var i = 0; i < sectionDataSource.length; i++) {
let shopsdecoratorItem = sectionDataSource[i];
let validFloorData = false;
result.offset = realContainerHeight;
if (shopsdecoratorItem.get('module_type') == 'coupon') {
... ... @@ -242,17 +249,21 @@ export default class RedBrand extends Component {
countNumb++;
}
if (validFloorData && countNumb == layoutIndex) {
this.layoutLenghtOffesetForIndex['fliter' + fliter + 'row' + countNumb] = result;
return result;
}
});
}
}else if (item.key == 'productList') {
let brandFilterContainerHeight = this.props.fliter == '2' ? 84 : 40;
countNumb++; // filter
if (countNumb == layoutIndex) {
return {
result = {
length: brandFilterContainerHeight,
offset: realContainerHeight
}
};
this.layoutLenghtOffesetForIndex['fliter' + fliter + 'row' + countNumb] = result;
return result;
}else if (layoutIndex > countNumb) {
let rowHeight = Math.ceil(254 * width / 320);
let rowMarginTop = Math.ceil(10 * DEVICE_WIDTH_RATIO);
... ... @@ -260,10 +271,11 @@ export default class RedBrand extends Component {
realContainerHeight += brandFilterContainerHeight;
result.length = rowHeight + rowMarginTop + rowMarginBottom;
result.offset = realContainerHeight + (layoutIndex - countNumb) * result.length;
this.layoutLenghtOffesetForIndex['fliter' + fliter + 'row' + layoutIndex] = result;
return result;
}
}
});
}
return {
length: 0,
offset: realContainerHeight,
... ... @@ -272,8 +284,18 @@ export default class RedBrand extends Component {
getItemLayout(data, index){
let sectionInfo = this._calculateSectionRealHeight(this.sectionData, index);
return {length: sectionInfo.length, offset: sectionInfo.offset, index}
let {fliter} = this.props;
let key = key = 'fliter' + fliter + 'row' + index;
let sectionInfo = {
length: 0,
offset: 0,
};
if (this.layoutLenghtOffesetForIndex[key]) {
sectionInfo = this.layoutLenghtOffesetForIndex[key];
} else {
sectionInfo = this._calculateSectionRealHeight(this.sectionData, index);
}
return {length: sectionInfo.length, offset: sectionInfo.offset, index};
}
renderSectionHeader(section) {
... ...