Authored by 于良

Merge branch 'classify' of http://git.yoho.cn/mobile/YH_RNComponent into classify

Conflicts:
	js/classify/reducers/brand/brandActions.js
... ... @@ -22,7 +22,7 @@ import AllBrandListCell from './AllBrandListCell';
import NewHotBannerListCell from './NewHotBannerListCell';
import BrandSearch from './BrandSearch';
import LoadingIndicator from '../../../common/components/LoadingIndicator';
import IndexListView from './IndexListView';
export default class Brand extends Component {
constructor(props) {
... ... @@ -68,18 +68,18 @@ export default class Brand extends Component {
return (
<View style={styles.header}>
<TouchableOpacity
<TouchableOpacity
activeOpacity={1}
onPress={() => {
this.props.onPressSearch && this.props.onPressSearch();
// this.searchBar && this.searchBar.focus();
}}
>
<YH_SearchBar
<YH_SearchBar
ref={(c) => {
this.searchBar = c;
}}
editable={false}
editable={false}
/>
</TouchableOpacity>
{banner?<BrandSwiper resource={banner} onPressSlideItem={this.props.onPressSlideItem}/>:null}
... ... @@ -90,9 +90,13 @@ export default class Brand extends Component {
}
renderSectionHeader(sectionData, sectionID) {
let title = sectionID;
if (sectionID == '0-9') {
title = '0';
}
return (
<View style={styles.sessionTitle}>
<Text style={styles.sessionText}>{sectionID}</Text>
<Text style={styles.sessionText}>{title}</Text>
</View>
);
}
... ... @@ -166,7 +170,7 @@ export default class Brand extends Component {
return (
<View style={styles.container}>
<ChannelFliter selectID={channelFliter} onChannelPressFliter={this.props.onChannelPressFliter}/>
<ListView
contentContainerStyle={contentContainerStyle}
enableEmptySections={true}
... ... @@ -177,10 +181,13 @@ export default class Brand extends Component {
/>
{showSearch ? <BrandSearch
data={search}
data={search}
onTextChange={this.props.onTextChange}
onClickCancel={this.props.onClickCancel} /> : null}
<IndexListView dataSource={list}/>
{showSearch ? <BrandSearch style={styles.search} data={search}/> : null}
<LoadingIndicator
isVisible={isFetching}
/>
... ... @@ -220,4 +227,6 @@ let styles = StyleSheet.create({
width,
backgroundColor: '#e5e5e5',
},
search: {
},
});
... ...
'use strict';
import React from 'react';
import ReactNative from 'react-native';
import {isEmptyObject} from '../../utils/Utils';
const {
View,
Image,
Text,
TouchableOpacity,
Dimensions,
StyleSheet,
} = ReactNative;
export default class IndexListView extends React.Component {
constructor(props) {
super (props);
}
render() {
let {dataSource} = this.props;
if (isEmptyObject(dataSource)) {
return null;
}
let keyData = [];
for(var k in dataSource) {
let name = k;
if (k == '0-9') {
name = '0';
}
keyData.push(<Text style={styles.text}>{name}</Text>);
}
return (
<View style={styles.container}>
{keyData.map((elem, index) => {return elem;})}
</View>
);
}
}
let {width, height} = Dimensions.get('window');
let styles = StyleSheet.create({
container: {
position: 'absolute',
width: 10,
top: 35,
bottom : 1,
right: 1,
backgroundColor: 'rgba(255,255,255,0.2)',
justifyContent: 'center',
},
text: {
justifyContent: 'center',
textAlign: 'center',
fontSize: 10,
color: 'black',
fontWeight: 'bold',
backgroundColor: 'transparent',
marginTop: 2,
}
});
... ...
... ... @@ -4,6 +4,7 @@ import ReactNative from 'react-native';
import BrandService from '../../services/BrandService';
import {Record, List, Map} from 'immutable';
import Pinyin from '../../../common/utils/pinyin';
import {isEmptyObject} from '../../utils/Utils';
const {
SET_TYPE,
... ... @@ -169,14 +170,17 @@ export function getBrandList(channel) {
}
return new BrandService(app.host).getBrandList(channel)
.then(json => {
let payload = parseListResources(json);
if (channel == 0) {
dispatch(getBrandListForBoySuccess(json));
dispatch(getBrandListForBoySuccess(payload));
}else if (channel == 1) {
dispatch(getBrandListForGirlSuccess(json));
dispatch(getBrandListForGirlSuccess(payload));
}else if (channel == 2) {
dispatch(getBrandListForKidSuccess(json));
dispatch(getBrandListForKidSuccess(payload));
}else if (channel == 3) {
dispatch(getBrandListForLifeStyleSuccess(json));
dispatch(getBrandListForLifeStyleSuccess(payload));
}
})
.catch(error => {
... ... @@ -193,6 +197,36 @@ export function getBrandList(channel) {
};
}
export function parseListResources(json) {
let all_list_old = json.all_list;
let hot_list = json.hot_list;
let new_list = json.new_list;
if (isEmptyObject(all_list_old)) {
return json;
}
let reg = /^[a-zA-Z]*$/;
let all_list = {};
let otherList = [];
for(let k in all_list_old) {
if (reg.test(k)) {
all_list[k] = all_list_old[k];
} else {
Array.prototype.push.apply(otherList, all_list_old[k]);
}
}
all_list['0-9'] = otherList;
return {
all_list,
hot_list,
new_list,
};
}
export function getBrandResourceForBoyRequest() {
return {
type: GET_BRAND_RESOURCE_FOR_BOY_REQUEST,
... ... @@ -359,7 +393,7 @@ export function searchHistory() {
});
})
.catch(error => {
});
};
}
... ... @@ -374,7 +408,7 @@ export function insertSearchHistory(keyword) {
});
})
.catch(error => {
});
};
}
... ... @@ -389,7 +423,7 @@ export function clearSearchHistory() {
});
})
.catch(error => {
});
};
}
... ... @@ -527,11 +561,6 @@ export function filteBrandForKeyword(text) {
return false;
});
// let result =
// brandList.forEach((value, key) => {
// console.log(key);
// });
};
}
\ No newline at end of file
}
... ...
... ... @@ -21,3 +21,10 @@ export function getSlicedUrl(src, width, height, mode = 1) {
}
return newSrc;
}
export function isEmptyObject(obj) {
for (var key in obj) {
return false;
}
return true;
}
... ...