Authored by 孙凯

添加 index ListView UI review by zhanglixia

@@ -22,7 +22,7 @@ import AllBrandListCell from './AllBrandListCell'; @@ -22,7 +22,7 @@ import AllBrandListCell from './AllBrandListCell';
22 import NewHotBannerListCell from './NewHotBannerListCell'; 22 import NewHotBannerListCell from './NewHotBannerListCell';
23 import BrandSearch from './BrandSearch'; 23 import BrandSearch from './BrandSearch';
24 import LoadingIndicator from '../../../common/components/LoadingIndicator'; 24 import LoadingIndicator from '../../../common/components/LoadingIndicator';
25 - 25 +import IndexListView from './IndexListView';
26 26
27 export default class Brand extends Component { 27 export default class Brand extends Component {
28 constructor(props) { 28 constructor(props) {
@@ -68,18 +68,18 @@ export default class Brand extends Component { @@ -68,18 +68,18 @@ export default class Brand extends Component {
68 68
69 return ( 69 return (
70 <View style={styles.header}> 70 <View style={styles.header}>
71 - <TouchableOpacity 71 + <TouchableOpacity
72 activeOpacity={1} 72 activeOpacity={1}
73 onPress={() => { 73 onPress={() => {
74 this.props.onPressSearch && this.props.onPressSearch(); 74 this.props.onPressSearch && this.props.onPressSearch();
75 // this.searchBar && this.searchBar.focus(); 75 // this.searchBar && this.searchBar.focus();
76 }} 76 }}
77 > 77 >
78 - <YH_SearchBar 78 + <YH_SearchBar
79 ref={(c) => { 79 ref={(c) => {
80 this.searchBar = c; 80 this.searchBar = c;
81 }} 81 }}
82 - editable={false} 82 + editable={false}
83 /> 83 />
84 </TouchableOpacity> 84 </TouchableOpacity>
85 {banner?<BrandSwiper resource={banner} onPressSlideItem={this.props.onPressSlideItem}/>:null} 85 {banner?<BrandSwiper resource={banner} onPressSlideItem={this.props.onPressSlideItem}/>:null}
@@ -90,9 +90,13 @@ export default class Brand extends Component { @@ -90,9 +90,13 @@ export default class Brand extends Component {
90 } 90 }
91 91
92 renderSectionHeader(sectionData, sectionID) { 92 renderSectionHeader(sectionData, sectionID) {
  93 + let title = sectionID;
  94 + if (sectionID == '0-9') {
  95 + title = '0';
  96 + }
93 return ( 97 return (
94 <View style={styles.sessionTitle}> 98 <View style={styles.sessionTitle}>
95 - <Text style={styles.sessionText}>{sectionID}</Text> 99 + <Text style={styles.sessionText}>{title}</Text>
96 </View> 100 </View>
97 ); 101 );
98 } 102 }
@@ -166,7 +170,7 @@ export default class Brand extends Component { @@ -166,7 +170,7 @@ export default class Brand extends Component {
166 return ( 170 return (
167 <View style={styles.container}> 171 <View style={styles.container}>
168 <ChannelFliter selectID={channelFliter} onChannelPressFliter={this.props.onChannelPressFliter}/> 172 <ChannelFliter selectID={channelFliter} onChannelPressFliter={this.props.onChannelPressFliter}/>
169 - 173 +
170 <ListView 174 <ListView
171 contentContainerStyle={contentContainerStyle} 175 contentContainerStyle={contentContainerStyle}
172 enableEmptySections={true} 176 enableEmptySections={true}
@@ -177,10 +181,13 @@ export default class Brand extends Component { @@ -177,10 +181,13 @@ export default class Brand extends Component {
177 /> 181 />
178 182
179 {showSearch ? <BrandSearch 183 {showSearch ? <BrandSearch
180 - data={search} 184 + data={search}
181 onTextChange={this.props.onTextChange} 185 onTextChange={this.props.onTextChange}
182 onClickCancel={this.props.onClickCancel} /> : null} 186 onClickCancel={this.props.onClickCancel} /> : null}
183 187
  188 + <IndexListView dataSource={list}/>
  189 + {showSearch ? <BrandSearch style={styles.search} data={search}/> : null}
  190 +
184 <LoadingIndicator 191 <LoadingIndicator
185 isVisible={isFetching} 192 isVisible={isFetching}
186 /> 193 />
@@ -220,4 +227,6 @@ let styles = StyleSheet.create({ @@ -220,4 +227,6 @@ let styles = StyleSheet.create({
220 width, 227 width,
221 backgroundColor: '#e5e5e5', 228 backgroundColor: '#e5e5e5',
222 }, 229 },
  230 + search: {
  231 + },
223 }); 232 });
  1 +'use strict';
  2 +
  3 +import React from 'react';
  4 +import ReactNative from 'react-native';
  5 +import {isEmptyObject} from '../../utils/Utils';
  6 +
  7 +const {
  8 + View,
  9 + Image,
  10 + Text,
  11 + TouchableOpacity,
  12 + Dimensions,
  13 + StyleSheet,
  14 +} = ReactNative;
  15 +
  16 +export default class IndexListView extends React.Component {
  17 +
  18 + constructor(props) {
  19 + super (props);
  20 + }
  21 +
  22 + render() {
  23 +
  24 + let {dataSource} = this.props;
  25 +
  26 + if (isEmptyObject(dataSource)) {
  27 + return null;
  28 + }
  29 +
  30 + let keyData = [];
  31 + for(var k in dataSource) {
  32 + let name = k;
  33 + if (k == '0-9') {
  34 + name = '0';
  35 + }
  36 + keyData.push(<Text style={styles.text}>{name}</Text>);
  37 + }
  38 +
  39 + return (
  40 + <View style={styles.container}>
  41 + {keyData.map((elem, index) => {return elem;})}
  42 + </View>
  43 + );
  44 + }
  45 +}
  46 +
  47 +let {width, height} = Dimensions.get('window');
  48 +let styles = StyleSheet.create({
  49 + container: {
  50 + position: 'absolute',
  51 + width: 10,
  52 + top: 35,
  53 + bottom : 1,
  54 + right: 1,
  55 + backgroundColor: 'rgba(255,255,255,0.2)',
  56 + justifyContent: 'center',
  57 + },
  58 + text: {
  59 + justifyContent: 'center',
  60 + textAlign: 'center',
  61 + fontSize: 10,
  62 + color: 'black',
  63 + fontWeight: 'bold',
  64 + backgroundColor: 'transparent',
  65 + marginTop: 2,
  66 + }
  67 +});
@@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
2 2
3 import ReactNative from 'react-native'; 3 import ReactNative from 'react-native';
4 import BrandService from '../../services/BrandService'; 4 import BrandService from '../../services/BrandService';
  5 +import {isEmptyObject} from '../../utils/Utils';
5 6
6 const { 7 const {
7 SET_TYPE, 8 SET_TYPE,
@@ -167,14 +168,17 @@ export function getBrandList(channel) { @@ -167,14 +168,17 @@ export function getBrandList(channel) {
167 } 168 }
168 return new BrandService(app.host).getBrandList(channel) 169 return new BrandService(app.host).getBrandList(channel)
169 .then(json => { 170 .then(json => {
  171 +
  172 + let payload = parseListResources(json);
  173 +
170 if (channel == 0) { 174 if (channel == 0) {
171 - dispatch(getBrandListForBoySuccess(json)); 175 + dispatch(getBrandListForBoySuccess(payload));
172 }else if (channel == 1) { 176 }else if (channel == 1) {
173 - dispatch(getBrandListForGirlSuccess(json)); 177 + dispatch(getBrandListForGirlSuccess(payload));
174 }else if (channel == 2) { 178 }else if (channel == 2) {
175 - dispatch(getBrandListForKidSuccess(json)); 179 + dispatch(getBrandListForKidSuccess(payload));
176 }else if (channel == 3) { 180 }else if (channel == 3) {
177 - dispatch(getBrandListForLifeStyleSuccess(json)); 181 + dispatch(getBrandListForLifeStyleSuccess(payload));
178 } 182 }
179 }) 183 })
180 .catch(error => { 184 .catch(error => {
@@ -191,6 +195,36 @@ export function getBrandList(channel) { @@ -191,6 +195,36 @@ export function getBrandList(channel) {
191 }; 195 };
192 } 196 }
193 197
  198 +export function parseListResources(json) {
  199 + let all_list_old = json.all_list;
  200 + let hot_list = json.hot_list;
  201 + let new_list = json.new_list;
  202 +
  203 + if (isEmptyObject(all_list_old)) {
  204 + return json;
  205 + }
  206 +
  207 + let reg = /^[a-zA-Z]*$/;
  208 + let all_list = {};
  209 + let otherList = [];
  210 +
  211 + for(let k in all_list_old) {
  212 +
  213 + if (reg.test(k)) {
  214 + all_list[k] = all_list_old[k];
  215 + } else {
  216 + Array.prototype.push.apply(otherList, all_list_old[k]);
  217 + }
  218 + }
  219 + all_list['0-9'] = otherList;
  220 +
  221 + return {
  222 + all_list,
  223 + hot_list,
  224 + new_list,
  225 + };
  226 +}
  227 +
194 export function getBrandResourceForBoyRequest() { 228 export function getBrandResourceForBoyRequest() {
195 return { 229 return {
196 type: GET_BRAND_RESOURCE_FOR_BOY_REQUEST, 230 type: GET_BRAND_RESOURCE_FOR_BOY_REQUEST,
@@ -357,7 +391,7 @@ export function searchHistory() { @@ -357,7 +391,7 @@ export function searchHistory() {
357 }); 391 });
358 }) 392 })
359 .catch(error => { 393 .catch(error => {
360 - 394 +
361 }); 395 });
362 }; 396 };
363 } 397 }
@@ -372,7 +406,7 @@ export function insertSearchHistory(keyword) { @@ -372,7 +406,7 @@ export function insertSearchHistory(keyword) {
372 }); 406 });
373 }) 407 })
374 .catch(error => { 408 .catch(error => {
375 - 409 +
376 }); 410 });
377 }; 411 };
378 } 412 }
@@ -387,7 +421,7 @@ export function clearSearchHistory() { @@ -387,7 +421,7 @@ export function clearSearchHistory() {
387 }); 421 });
388 }) 422 })
389 .catch(error => { 423 .catch(error => {
390 - 424 +
391 }); 425 });
392 }; 426 };
393 } 427 }
@@ -478,7 +512,7 @@ export function filteBrandForKeyword(text) { @@ -478,7 +512,7 @@ export function filteBrandForKeyword(text) {
478 let {app, brand} = getState(); 512 let {app, brand} = getState();
479 let {search} = brand; 513 let {search} = brand;
480 514
481 - 515 +
482 516
483 }; 517 };
484 -}  
  518 +}
@@ -21,3 +21,10 @@ export function getSlicedUrl(src, width, height, mode = 1) { @@ -21,3 +21,10 @@ export function getSlicedUrl(src, width, height, mode = 1) {
21 } 21 }
22 return newSrc; 22 return newSrc;
23 } 23 }
  24 +
  25 +export function isEmptyObject(obj) {
  26 + for (var key in obj) {
  27 + return false;
  28 + }
  29 + return true;
  30 +}