add 逛详情 商品列表 新样式 review by hongmo
Showing
1 changed file
with
105 additions
and
30 deletions
@@ -3,6 +3,7 @@ | @@ -3,6 +3,7 @@ | ||
3 | import React from 'react'; | 3 | import React from 'react'; |
4 | import ReactNative from 'react-native'; | 4 | import ReactNative from 'react-native'; |
5 | import Immutable, {Map} from 'immutable'; | 5 | import Immutable, {Map} from 'immutable'; |
6 | +import BrandProductListCell from '../../../common/components/ListCell/ProductListCell'; | ||
6 | 7 | ||
7 | const { | 8 | const { |
8 | AppRegistry, | 9 | AppRegistry, |
@@ -14,6 +15,7 @@ const { | @@ -14,6 +15,7 @@ const { | ||
14 | TouchableOpacity, | 15 | TouchableOpacity, |
15 | Platform, | 16 | Platform, |
16 | NativeModules, | 17 | NativeModules, |
18 | + ListView, | ||
17 | } = ReactNative; | 19 | } = ReactNative; |
18 | 20 | ||
19 | 21 | ||
@@ -23,6 +25,14 @@ export default class GoodsCell extends React.Component { | @@ -23,6 +25,14 @@ export default class GoodsCell extends React.Component { | ||
23 | this.state = { | 25 | this.state = { |
24 | moreProduct: true, | 26 | moreProduct: true, |
25 | }; | 27 | }; |
28 | + | ||
29 | + this.dataSource = new ListView.DataSource({ | ||
30 | + rowHasChanged: (r1, r2) => !Immutable.is(r1, r2), | ||
31 | + }); | ||
32 | + this.renderRow = this.renderRow.bind(this); | ||
33 | + this._renderCellType1 = this._renderCellType1.bind(this); | ||
34 | + this._renderCellType2 = this._renderCellType2.bind(this); | ||
35 | + | ||
26 | } | 36 | } |
27 | 37 | ||
28 | shouldComponentUpdate(nextProps,nextState){ | 38 | shouldComponentUpdate(nextProps,nextState){ |
@@ -33,23 +43,46 @@ export default class GoodsCell extends React.Component { | @@ -33,23 +43,46 @@ export default class GoodsCell extends React.Component { | ||
33 | } | 43 | } |
34 | } | 44 | } |
35 | 45 | ||
36 | - render() { | ||
37 | - let {resource, articleId} = this.props; | ||
38 | - let originList = resource.get('productList'); | ||
39 | - let listSize = originList?originList.size:0; | ||
40 | - if (!originList || listSize == 0) { | ||
41 | - return (<View style={{height:1,width:width,backgroundColor:'white'}}/>); | ||
42 | - } | ||
43 | - let list = originList; | ||
44 | - if (this.state.moreProduct && listSize > 2) { | ||
45 | - list = originList.slice(0,2); | ||
46 | - } | ||
47 | - let surplusSize = listSize-2; | ||
48 | - let moreStr = '展开剩余'+ surplusSize + '个商品'; | 46 | + renderRow(rowData, sectionID, rowID, highlightRow) { |
47 | + let paddingLeft = rowID % 2 == 1 ? rowMarginHorizontal / 2 : rowMarginHorizontal; | ||
48 | + let customStyle = rowID == 0 || rowID == 1 ? {paddingLeft} : {paddingLeft}; | ||
49 | + return ( | ||
50 | + <BrandProductListCell | ||
51 | + style={[styles.listContainer, customStyle]} | ||
52 | + key={'row' + rowID} | ||
53 | + rowID={rowID} | ||
54 | + data={rowData} | ||
55 | + onPressProduct={this.props.onPressProduct} | ||
56 | + /> | ||
57 | + ); | ||
58 | + } | ||
59 | + | ||
60 | + //两列多行的样式 | ||
61 | + _renderCellType2(list) { | ||
49 | let backgroundWidth = width; | 62 | let backgroundWidth = width; |
50 | - let showMoreViewHeigth = (this.state.moreProduct && listSize > 2)?60:0; | ||
51 | - let backgroundHeight = Math.ceil(list.size) * (rowHeight+1) + showMoreViewHeigth; | ||
52 | - return( | 63 | + let backgroundHeight = Math.ceil(list.size / 2) * (cellHeight+rowMarginHorizontal) + 20; |
64 | + return( | ||
65 | + <View style={{width: backgroundWidth, height:backgroundHeight, backgroundColor:'white'}}> | ||
66 | + <ListView | ||
67 | + contentContainerStyle={styles.contentContainer} | ||
68 | + initialListSize={Math.ceil(list.size)} | ||
69 | + dataSource={this.dataSource.cloneWithRows(list.toArray())} | ||
70 | + enableEmptySections={true} | ||
71 | + renderRow={this.renderRow} | ||
72 | + scrollEnabled={false} | ||
73 | + scrollsToTop={false} | ||
74 | + /> | ||
75 | + </View> | ||
76 | + ); | ||
77 | + } | ||
78 | + | ||
79 | + //单列多行的样式 | ||
80 | + _renderCellType1(list) { | ||
81 | + | ||
82 | + let backgroundWidth = width; | ||
83 | + let backgroundHeight = Math.ceil(list.size) * (rowHeight+1); | ||
84 | + | ||
85 | + return( | ||
53 | <View style={{width: backgroundWidth, height:backgroundHeight, backgroundColor:'white'}}> | 86 | <View style={{width: backgroundWidth, height:backgroundHeight, backgroundColor:'white'}}> |
54 | {list.map((value, i) => { | 87 | {list.map((value, i) => { |
55 | let product = value?value.toJS():null; | 88 | let product = value?value.toJS():null; |
@@ -101,21 +134,53 @@ export default class GoodsCell extends React.Component { | @@ -101,21 +134,53 @@ export default class GoodsCell extends React.Component { | ||
101 | </TouchableOpacity> | 134 | </TouchableOpacity> |
102 | ); | 135 | ); |
103 | })} | 136 | })} |
104 | - {(this.state.moreProduct && listSize > 2) ? <TouchableOpacity style={styles.more} activeOpacity={0.5} onPress={() => { | ||
105 | - let params = { | ||
106 | - ID: articleId + '' , | ||
107 | - }; | ||
108 | - NativeModules.YH_CommonHelper.logEvent('YB_STROLL_DETAIL_MORE_GODS_C', params); | ||
109 | - | ||
110 | - this.setState({moreProduct: !this.state.moreProduct}); | ||
111 | - }}> | ||
112 | - <View style={styles.more}> | ||
113 | - <Text style={styles.moreText} numberOfLines={1}>{moreStr}</Text> | ||
114 | - <View style={styles.arrowView}> | ||
115 | - <Image source={require('../../image/arrow_ic.png')} style={styles.arrow_icon} resizeMode={'contain'}></Image> | 137 | + </View> |
138 | + ); | ||
139 | + } | ||
140 | + | ||
141 | + render() { | ||
142 | + let {resource, articleId} = this.props; | ||
143 | + let originList = resource.get('productList'); | ||
144 | + let display_template = resource.get('display_template')?resource.get('display_template'):1; | ||
145 | + let listSize = originList?originList.size:0; | ||
146 | + if (!originList || listSize == 0) { | ||
147 | + return (<View style={{height:1,width:width,backgroundColor:'white'}}/>); | ||
148 | + } | ||
149 | + let prudoctLimitRow = 2; | ||
150 | + if (display_template == 2) { | ||
151 | + prudoctLimitRow = 4; | ||
152 | + } | ||
153 | + | ||
154 | + let list = originList; | ||
155 | + if (this.state.moreProduct && listSize > prudoctLimitRow) { | ||
156 | + list = originList.slice(0,prudoctLimitRow); | ||
157 | + } | ||
158 | + let surplusSize = listSize-prudoctLimitRow; | ||
159 | + let moreStr = '展开剩余'+ surplusSize + '个商品'; | ||
160 | + let backgroundWidth = width; | ||
161 | + let showMoreViewHeigth = (this.state.moreProduct && listSize > prudoctLimitRow)?60:0; | ||
162 | + let backgroundHeight = Math.ceil(list.size) * (rowHeight+1) + showMoreViewHeigth; | ||
163 | + | ||
164 | + if (display_template == 2) { | ||
165 | + backgroundHeight = Math.ceil(list.size / 2) * (cellHeight+rowMarginHorizontal) + 20 + showMoreViewHeigth; | ||
166 | + } | ||
167 | + | ||
168 | + return( | ||
169 | + <View style={{width: backgroundWidth, height:backgroundHeight, backgroundColor:'white'}}> | ||
170 | + {display_template == 1 ? this._renderCellType1(list) : this._renderCellType2(list)} | ||
171 | + {(this.state.moreProduct && listSize > 2) ? | ||
172 | + <TouchableOpacity style={styles.more} activeOpacity={0.5} onPress={() => { | ||
173 | + let params = {ID: articleId + ''}; | ||
174 | + NativeModules.YH_CommonHelper.logEvent('YB_STROLL_DETAIL_MORE_GODS_C', params); | ||
175 | + this.setState({moreProduct: !this.state.moreProduct}); | ||
176 | + }}> | ||
177 | + <View style={styles.more}> | ||
178 | + <Text style={styles.moreText} numberOfLines={1}>{moreStr}</Text> | ||
179 | + <View style={styles.arrowView}> | ||
180 | + <Image source={require('../../image/arrow_ic.png')} style={styles.arrow_icon} resizeMode={'contain'}></Image> | ||
181 | + </View> | ||
116 | </View> | 182 | </View> |
117 | - </View> | ||
118 | - </TouchableOpacity>:null} | 183 | + </TouchableOpacity>:null} |
119 | </View> | 184 | </View> |
120 | ); | 185 | ); |
121 | } | 186 | } |
@@ -125,6 +190,9 @@ let {width, height} = Dimensions.get('window'); | @@ -125,6 +190,9 @@ let {width, height} = Dimensions.get('window'); | ||
125 | const DEVICE_WIDTH_RATIO = width / 750; | 190 | const DEVICE_WIDTH_RATIO = width / 750; |
126 | let rowHeight = Math.ceil(254 * DEVICE_WIDTH_RATIO); | 191 | let rowHeight = Math.ceil(254 * DEVICE_WIDTH_RATIO); |
127 | let imageWidth = Math.ceil((rowHeight - 20) * (235/314)); | 192 | let imageWidth = Math.ceil((rowHeight - 20) * (235/314)); |
193 | +let rowWidth = Math.ceil(137.5 * width / 320); | ||
194 | +let rowMarginHorizontal = (width - rowWidth * 2) / 3; | ||
195 | +let cellHeight = Math.ceil(254 * (width / 320)); | ||
128 | 196 | ||
129 | let styles = StyleSheet.create({ | 197 | let styles = StyleSheet.create({ |
130 | content_View: { | 198 | content_View: { |
@@ -132,6 +200,13 @@ let styles = StyleSheet.create({ | @@ -132,6 +200,13 @@ let styles = StyleSheet.create({ | ||
132 | width:width, | 200 | width:width, |
133 | backgroundColor: 'white', | 201 | backgroundColor: 'white', |
134 | }, | 202 | }, |
203 | + contentContainer:{ | ||
204 | + flexDirection: 'row', | ||
205 | + flexWrap: 'wrap', | ||
206 | + }, | ||
207 | + listContainer: { | ||
208 | + width: width / 2, | ||
209 | + }, | ||
135 | single_View: { | 210 | single_View: { |
136 | height: rowHeight, | 211 | height: rowHeight, |
137 | width:width, | 212 | width:width, |
-
Please register or login to post a comment