Authored by 张丽霞

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

@@ -50,6 +50,7 @@ export default class RedBrand extends Component { @@ -50,6 +50,7 @@ export default class RedBrand extends Component {
50 this._calculateSectionRealHeight = this._calculateSectionRealHeight.bind(this); 50 this._calculateSectionRealHeight = this._calculateSectionRealHeight.bind(this);
51 this.containerHeight = 0; 51 this.containerHeight = 0;
52 this.sectionData = []; 52 this.sectionData = [];
  53 + this.layoutLenghtOffesetForIndex = {};
53 } 54 }
54 55
55 _onPressLaunchProfile(value){ 56 _onPressLaunchProfile(value){
@@ -66,10 +67,6 @@ export default class RedBrand extends Component { @@ -66,10 +67,6 @@ export default class RedBrand extends Component {
66 } else { 67 } else {
67 this.refs.redBrandList && this.refs.redBrandList.scrollToLocation({itemIndex: 0,sectionIndex: 2, viewPosition: 0, animated: false}); 68 this.refs.redBrandList && this.refs.redBrandList.scrollToLocation({itemIndex: 0,sectionIndex: 2, viewPosition: 0, animated: false});
68 } 69 }
69 -  
70 -  
71 -  
72 -  
73 this.props.onPressProductFilter && this.props.onPressProductFilter(value); 70 this.props.onPressProductFilter && this.props.onPressProductFilter(value);
74 } 71 }
75 72
@@ -85,6 +82,7 @@ export default class RedBrand extends Component { @@ -85,6 +82,7 @@ export default class RedBrand extends Component {
85 launchProfile, 82 launchProfile,
86 productListForNew, 83 productListForNew,
87 shopsdecorator, 84 shopsdecorator,
  85 + fliter,
88 } = this.props; 86 } = this.props;
89 let result ={ 87 let result ={
90 length: 0, 88 length: 0,
@@ -92,11 +90,13 @@ export default class RedBrand extends Component { @@ -92,11 +90,13 @@ export default class RedBrand extends Component {
92 } 90 }
93 let realContainerHeight = 0; 91 let realContainerHeight = 0;
94 let countNumb = 0; 92 let countNumb = 0;
95 - dataSource.map((item, index) => { 93 + for (var i = 0; i < dataSource.length; i++) {
  94 + let item = dataSource[i];
96 if (item.key == 'ShopBanner') { 95 if (item.key == 'ShopBanner') {
97 if (!shopsdecorator || shopsdecorator.template_type != '1') { 96 if (!shopsdecorator || shopsdecorator.template_type != '1') {
98 result.length = Math.ceil((234/750)*width); //header 97 result.length = Math.ceil((234/750)*width); //header
99 if (countNumb == layoutIndex) { 98 if (countNumb == layoutIndex) {
  99 + this.layoutLenghtOffesetForIndex['fliter' + fliter + 'row' + countNumb] = result;
100 return result; 100 return result;
101 } 101 }
102 realContainerHeight += Math.ceil((234/750)*width); //header 102 realContainerHeight += Math.ceil((234/750)*width); //header
@@ -104,13 +104,20 @@ export default class RedBrand extends Component { @@ -104,13 +104,20 @@ export default class RedBrand extends Component {
104 }else if(item.key == 'brandReource') { 104 }else if(item.key == 'brandReource') {
105 realContainerHeight += 44; //height of RedBrandStoreFilter 105 realContainerHeight += 44; //height of RedBrandStoreFilter
106 countNumb++; 106 countNumb++;
  107 + if (countNumb == layoutIndex) {
  108 + result.offset = realContainerHeight - 44;
  109 + result.length = 44;
  110 + this.layoutLenghtOffesetForIndex['fliter' + fliter + 'row' + countNumb] = result;
  111 + return result;
  112 + }
107 let sectionDataSource = item.data; 113 let sectionDataSource = item.data;
108 if (sectionDataSource.length == 0) { 114 if (sectionDataSource.length == 0) {
109 result.offset = realContainerHeight; 115 result.offset = realContainerHeight;
110 result.length = 0; 116 result.length = 0;
111 return result; 117 return result;
112 } 118 }
113 - sectionDataSource.map((shopsdecoratorItem, index) => { 119 + for (var i = 0; i < sectionDataSource.length; i++) {
  120 + let shopsdecoratorItem = sectionDataSource[i];
114 let validFloorData = false; 121 let validFloorData = false;
115 result.offset = realContainerHeight; 122 result.offset = realContainerHeight;
116 if (shopsdecoratorItem.get('module_type') == 'coupon') { 123 if (shopsdecoratorItem.get('module_type') == 'coupon') {
@@ -242,17 +249,21 @@ export default class RedBrand extends Component { @@ -242,17 +249,21 @@ export default class RedBrand extends Component {
242 countNumb++; 249 countNumb++;
243 } 250 }
244 if (validFloorData && countNumb == layoutIndex) { 251 if (validFloorData && countNumb == layoutIndex) {
  252 + this.layoutLenghtOffesetForIndex['fliter' + fliter + 'row' + countNumb] = result;
245 return result; 253 return result;
246 } 254 }
247 - }); 255 + }
  256 +
248 }else if (item.key == 'productList') { 257 }else if (item.key == 'productList') {
249 let brandFilterContainerHeight = this.props.fliter == '2' ? 84 : 40; 258 let brandFilterContainerHeight = this.props.fliter == '2' ? 84 : 40;
250 countNumb++; // filter 259 countNumb++; // filter
251 if (countNumb == layoutIndex) { 260 if (countNumb == layoutIndex) {
252 - return { 261 + result = {
253 length: brandFilterContainerHeight, 262 length: brandFilterContainerHeight,
254 offset: realContainerHeight 263 offset: realContainerHeight
255 - } 264 + };
  265 + this.layoutLenghtOffesetForIndex['fliter' + fliter + 'row' + countNumb] = result;
  266 + return result;
256 }else if (layoutIndex > countNumb) { 267 }else if (layoutIndex > countNumb) {
257 let rowHeight = Math.ceil(254 * width / 320); 268 let rowHeight = Math.ceil(254 * width / 320);
258 let rowMarginTop = Math.ceil(10 * DEVICE_WIDTH_RATIO); 269 let rowMarginTop = Math.ceil(10 * DEVICE_WIDTH_RATIO);
@@ -260,10 +271,11 @@ export default class RedBrand extends Component { @@ -260,10 +271,11 @@ export default class RedBrand extends Component {
260 realContainerHeight += brandFilterContainerHeight; 271 realContainerHeight += brandFilterContainerHeight;
261 result.length = rowHeight + rowMarginTop + rowMarginBottom; 272 result.length = rowHeight + rowMarginTop + rowMarginBottom;
262 result.offset = realContainerHeight + (layoutIndex - countNumb) * result.length; 273 result.offset = realContainerHeight + (layoutIndex - countNumb) * result.length;
  274 + this.layoutLenghtOffesetForIndex['fliter' + fliter + 'row' + layoutIndex] = result;
263 return result; 275 return result;
264 } 276 }
265 } 277 }
266 - }); 278 + }
267 return { 279 return {
268 length: 0, 280 length: 0,
269 offset: realContainerHeight, 281 offset: realContainerHeight,
@@ -272,8 +284,18 @@ export default class RedBrand extends Component { @@ -272,8 +284,18 @@ export default class RedBrand extends Component {
272 284
273 285
274 getItemLayout(data, index){ 286 getItemLayout(data, index){
275 - let sectionInfo = this._calculateSectionRealHeight(this.sectionData, index);  
276 - return {length: sectionInfo.length, offset: sectionInfo.offset, index} 287 + let {fliter} = this.props;
  288 + let key = key = 'fliter' + fliter + 'row' + index;
  289 + let sectionInfo = {
  290 + length: 0,
  291 + offset: 0,
  292 + };
  293 + if (this.layoutLenghtOffesetForIndex[key]) {
  294 + sectionInfo = this.layoutLenghtOffesetForIndex[key];
  295 + } else {
  296 + sectionInfo = this._calculateSectionRealHeight(this.sectionData, index);
  297 + }
  298 + return {length: sectionInfo.length, offset: sectionInfo.offset, index};
277 } 299 }
278 300
279 renderSectionHeader(section) { 301 renderSectionHeader(section) {