Authored by 孙凯

整理代码 review by zhanglixia

@@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
2 2
3 import React from 'react'; 3 import React from 'react';
4 import ReactNative from 'react-native'; 4 import ReactNative from 'react-native';
  5 +import {getSlicedUrl} from '../../utils/Utils';
5 6
6 const { 7 const {
7 AppRegistry, 8 AppRegistry,
@@ -23,31 +24,13 @@ export default class BannerReourceList extends React.Component { @@ -23,31 +24,13 @@ export default class BannerReourceList extends React.Component {
23 }); 24 });
24 } 25 }
25 26
26 - static getSlicedUrl(src, width, height, mode = 1) {  
27 - if (!src) {  
28 - return '';  
29 - }  
30 -  
31 - width = PixelRatio.getPixelSizeForLayoutSize(width);  
32 - height = PixelRatio.getPixelSizeForLayoutSize(height);  
33 - let newSrc = src;  
34 - if (src.indexOf('imageView') === -1 && src.indexOf('imageMogr') === -1) {  
35 - newSrc = src + '?imageView2/' + mode + '/w/' + width + '/h/' + height;  
36 - } else {  
37 - newSrc = src.replace('{mode}', mode)  
38 - .replace('{width}', width)  
39 - .replace('{height}', height);  
40 - }  
41 - return newSrc;  
42 - }  
43 -  
44 _pressRow(rowData){ 27 _pressRow(rowData){
45 this.props.onPressBrandItem(rowData.url) 28 this.props.onPressBrandItem(rowData.url)
46 } 29 }
47 30
48 renderRow(rowData,sectionID,rowID,highlightRow) { 31 renderRow(rowData,sectionID,rowID,highlightRow) {
49 32
50 - let newSrc = BannerReourceList.getSlicedUrl(rowData.src, itemWidth, itemWidth, 1); 33 + let newSrc = getSlicedUrl(rowData.src, itemWidth, itemWidth, 1);
51 return ( 34 return (
52 <TouchableOpacity activeOpacity={0.5} onPress={() => { 35 <TouchableOpacity activeOpacity={0.5} onPress={() => {
53 this.props.onPressBrandItem && this.props.onPressBrandItem(rowData.url); 36 this.props.onPressBrandItem && this.props.onPressBrandItem(rowData.url);
@@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
2 2
3 import React from 'react'; 3 import React from 'react';
4 import ReactNative from 'react-native'; 4 import ReactNative from 'react-native';
  5 +import {getSlicedUrl} from '../../utils/Utils';
5 6
6 const { 7 const {
7 StyleSheet, 8 StyleSheet,
@@ -18,27 +19,9 @@ export default class NewHotBannerListCell extends React.Component { @@ -18,27 +19,9 @@ export default class NewHotBannerListCell extends React.Component {
18 super(props); 19 super(props);
19 } 20 }
20 21
21 - static getSlicedUrl(src, width, height, mode = 1) {  
22 - if (!src) {  
23 - return '';  
24 - }  
25 -  
26 - width = PixelRatio.getPixelSizeForLayoutSize(width);  
27 - height = PixelRatio.getPixelSizeForLayoutSize(height);  
28 - let newSrc = src;  
29 - if (src.indexOf('imageView') === -1 && src.indexOf('imageMogr') === -1) {  
30 - newSrc = src + '?imageView2/' + mode + '/w/' + width + '/h/' + height;  
31 - } else {  
32 - newSrc = src.replace('{mode}', mode)  
33 - .replace('{width}', width)  
34 - .replace('{height}', height);  
35 - }  
36 - return newSrc;  
37 - }  
38 -  
39 render() { 22 render() {
40 let rowData = this.props.rowData; 23 let rowData = this.props.rowData;
41 - let newSrc = NewHotBannerListCell.getSlicedUrl(rowData.brand_ico, width, height, 1); 24 + let newSrc = getSlicedUrl(rowData.brand_ico, width, height, 1);
42 return ( 25 return (
43 <TouchableOpacity activeOpacity={0.5} onPress={() => { 26 <TouchableOpacity activeOpacity={0.5} onPress={() => {
44 // this.props.onPressRecommendItem && this.props.onPressRecommendItem(rowData.get('url')); 27 // this.props.onPressRecommendItem && this.props.onPressRecommendItem(rowData.get('url'));
  1 +'use strict';
  2 +import ReactNative from 'react-native';
  3 +const {
  4 + PixelRatio,
  5 +} = ReactNative;
  6 +
  7 +export function getSlicedUrl(src, width, height, mode = 1) {
  8 + if (!src) {
  9 + return '';
  10 + }
  11 +
  12 + width = PixelRatio.getPixelSizeForLayoutSize(width);
  13 + height = PixelRatio.getPixelSizeForLayoutSize(height);
  14 + let newSrc = src;
  15 + if (src.indexOf('imageView') === -1 && src.indexOf('imageMogr') === -1) {
  16 + newSrc = src + '?imageView2/' + mode + '/w/' + width + '/h/' + height;
  17 + } else {
  18 + newSrc = src.replace('{mode}', mode)
  19 + .replace('{width}', width)
  20 + .replace('{height}', height);
  21 + }
  22 + return newSrc;
  23 +}