Authored by 孙凯

add OneRowTwoColImages review by 红魔

... ... @@ -25,164 +25,110 @@ import BrandStoreHeaderView from '../brandStore/brandStoreSubView/SessionHeader/
import CouponCell from '../brandStore/brandStoreSubView/Cells/CouponCell';
import BrandListCell from '../brandStore/brandStoreSubView/Cells/BrandListCell';
import BrandSwiper from '../brandStore/brandStoreSubView/Cells/BrandSwiper';
import OneRowTwoColImages from '../brandStore/brandStoreSubView/Cells/OneRowTwoColImages';
export default class BrandStore extends Component {
constructor(props) {
super(props);
let getSectionData = (dataBlob, sectionID) => {
return dataBlob[sectionID];
};
let getRowData = (dataBlob, sectionID, rowID) => {
return dataBlob[sectionID + ':' + rowID];
};
this.state = {
dataSource: new ListView.DataSource({
getSectionData: getSectionData, // 获取组中数据
getRowData: getRowData, // 获取行中的数据
rowHasChanged: (r1, r2) => r1 != r2,
sectionHeaderHasChanged: (s1, s2) => s1 !== s2
})
};
this.loadDataFromJason();
this.dataSource = new ListView.DataSource({
rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
});
}
componentDidMount() {
// this.props.actions.getShopsIntro();
}
componentWillUnmount() {
}
loadDataFromJason() {
let jsonData = require('../../image/Car.json');
let dataBlob = {},
sectionIDs = [],
rowIDs = [],
cars = [];
let datas = jsonData.data;
for (let i in datas) {
//step 1、把组数据放入sectionIDs数组中
sectionIDs.push(i);
//step 2、把组中内容放dataBlob对象中
dataBlob[i] = datas[i].title;
//step 3、取出该组中所有的车
cars = datas[i].cars;
//step 4记录每一行中的数据
rowIDs[i] = [];
//step 5、获取行中每一组数据
for (let j in cars) {
//把行号放入rowIDs中
rowIDs[i].push(j);
//把每一行中的内容放dataBlob对象中
dataBlob[i + ':' + j] = cars[j];
}
}
this.state = {
dataSource: this.state.dataSource.cloneWithRowsAndSections(dataBlob, sectionIDs, rowIDs)
};
}
render() {
let src = this.props.src.toArray();
return (
<ListView
dataSource={this.state.dataSource}
dataSource={this.dataSource.cloneWithRows(src)}
renderRow={this.renderRow.bind(this)}
renderSectionHeader={this.renderSectionHeader.bind(this)}
renderHeader = {this.renderHeader.bind(this)}
// renderSectionHeader={this.renderSectionHeader.bind(this)}
// renderHeader = {this.renderHeader.bind(this)}
contentContainerStyle={styles.listViewStyle}//设置cell的样式
enableEmptySections = {true}
/>
);
}
// 每一行的数据
renderRow(rowData,sectionID,rowID,highlightRow) {
if (sectionID === '0') {
switch (rowID) {
case '0':
{
return (
<CouponCell
src={'aa'}
onPressCoupon={this._onPressCoupon}
/>
);
}
break;
case '1':
{
return (
<BrandListCell
src={'aa'}
onPressBrandItem={this._onPressBrandItem}
/>
);
}
break;
default:
{
return (
<BrandSwiper
src={'aa'}
onPressBrandItem={this._onPressBrandItem}
/>
);
}
break;
}
}else {
return (
<TouchableOpacity activeOpacity={0.5}>
<View style={styles.row}>
<Text style={styles.text}>
{rowData.name}
</Text>
</View>
</TouchableOpacity>
);
}
}
// 每一组中的数据
renderSectionHeader(sectionData, sectionID) {
//根据数据显示不同的header
switch (sectionData) {
case 'A':
{
return (
<View style={styles.headerViewStyle}>
<Text style={{marginLeft: 5, color: 'white'}}>{sectionData}</Text>
</View>
if (rowData.get('resource_name') == 'shopTopBanner_APP') {
return(
<BrandStoreHeaderView
src={rowData.get('resource_data')}
onPressCollection={this._onPressCollection}
/>
);
}
break;
default:
{
return (
<View style={styles.headerViewStyle}>
<Text style={{marginLeft: 5, color: 'white'}}>{sectionData}</Text>
</View>
}else if (rowData.get('resource_name') == 'largeSlideImg_APP') {
return <BrandSwiper
src={rowData.get('resource_data')}
onPressBrandItem={this._onPressBrandItem}
/>;
}else if (rowData.get('resource_name') == 'oneRowTwoColImages_APP') {
return(
<OneRowTwoColImages
src={rowData.get('resource_data')}
onPressOneRowTwoColImages={this._onPressOneRowTwoColImages}
/>
);
}
break;
}
}
}
return null;
renderHeader(){
return(
<BrandStoreHeaderView
src={'aa'}
onPressCollection={this._onPressCollection}
/>
);
// <CouponCell
// src={'aa'}
// onPressCoupon={this._onPressCoupon}
// />
// <BrandListCell
// src={'aa'}
// onPressBrandItem={this._onPressBrandItem}
// />
}
// 每一组中的数据
// renderSectionHeader(sectionData, sectionID) {
//
// //根据数据显示不同的header
// switch (sectionData) {
// case 'A':
// {
// return (
// <View style={styles.headerViewStyle}>
// <Text style={{marginLeft: 5, color: 'white'}}>{sectionData}</Text>
// </View>
// );
// }
// break;
// default:
// {
// return (
// <View style={styles.headerViewStyle}>
// <Text style={{marginLeft: 5, color: 'white'}}>{sectionData}</Text>
// </View>
// );
// }
// break;
// }
// }
// renderHeader(){
// return(
// <BrandStoreHeaderView
// src={'aa'}
// onPressCollection={this._onPressCollection}
// />
// );
// }
}
let styles = StyleSheet.create({
... ...
... ... @@ -19,10 +19,9 @@ export default class BrandSwiper extends React.Component {
super (props);
this.state = {
data:['1', '2' ,'3' ,'4', '5'],
duration: 1,
width: Dimensions.get('window').width,
height: 200,
height: Math.ceil((310 / 640) * Dimensions.get('window').width),
// onPress: React.PropTypes.func,
};
... ... @@ -55,10 +54,9 @@ export default class BrandSwiper extends React.Component {
render() {
let width = this.state.width;
let height = this.state.height;
let data = this.state.data;
let data = JSON.parse(this.props.src);
if (data.length == 1) {
// let item = data[0];
return (
<TouchableOpacity
activeOpacity={1}
... ... @@ -67,7 +65,7 @@ export default class BrandSwiper extends React.Component {
}}
>
<Image
source={require('../../../../image/1.png')}
source={{uri: data[i].src}}
style={{ width: width, height: height}}
resizeMode={'cover'}
></Image>
... ... @@ -88,6 +86,7 @@ export default class BrandSwiper extends React.Component {
height={height}
>
{data.map((item, i) => {
let ary = item.data;
return (
<TouchableOpacity
key={i}
... ... @@ -96,11 +95,11 @@ export default class BrandSwiper extends React.Component {
}}
>
<Image
source={require('../../../../image/1.png')}
style={{ width: width, height: height - 20}}
resizeMode={'cover'}
></Image>
<Image
source={{uri:ary[0].src}}
style={{ width: width, height: height - 20}}
resizeMode={'cover'}
></Image>
</TouchableOpacity>
);
... ...
'use strict';
import React from 'react';
import ReactNative from 'react-native';
const {
Image,
View,
StyleSheet,
Dimensions,
TouchableOpacity,
} = ReactNative;
export default class OneRowTwoColImages extends React.Component {
constructor(props) {
super (props);
this.state = {
backgroundWidth: Dimensions.get('window').width,
backgroundHeight: Math.ceil((310 / 640) * Dimensions.get('window').width),
}
}
componentDidMount() {
}
render() {
let data = JSON.parse(this.props.src);
let data1 = data[0].data;
let imageSrc1 = data1[0].src;
let url1 = data1[0].url;
let data2 = data[1].data;
let imageSrc2 = data2[0].src;
let url2 = data1[0].url;
return (
<View style={styles.viewStyle}>
<TouchableOpacity onPress={() => {this.props.onPress && this.props.onPressOneRowTwoColImages(url1)}} >
<Image
source={{uri: imageSrc1}}
style={styles.thumbnail}
resizeMode={'cover'}
></Image>
</TouchableOpacity>
<TouchableOpacity onPress={() => {this.props.onPress && this.props.onPressOneRowTwoColImages(url2)}} >
<Image
source={{uri: imageSrc2}}
style={styles.thumbnail}
resizeMode={'cover'}
></Image>
</TouchableOpacity>
</View>
);
}
};
const styles = StyleSheet.create({
thumbnail: {
width: 160,
height: 90,
borderRadius: 10,
},
viewStyle:{
padding: 10,
flexDirection: 'row',
alignItems: 'center',
alignSelf: 'flex-start',
justifyContent: 'space-around',
width: Dimensions.get('window').width,
height:130,
backgroundColor:'#f0f0f0',
},
});
... ...
... ... @@ -28,10 +28,13 @@ export default class BrandStoreHeaderView extends React.Component {
}
render() {
let data = JSON.parse(this.props.src);
let shopSrc = data[0].shopSrc;
return (
<Image
source={require('../../../../image/4.png')}
// source={{uri: this.props.src}}
source={{uri: shopSrc}}
style={{width: this.state.backgroundWidth, height: this.state.backgroundHeight }}
resizeMode={'cover'}>
<TouchableOpacity onPress={this.props.onPressCollection} >
... ...
... ... @@ -44,10 +44,11 @@ class BrandStoreContainer extends Component {
this._onPressCollection = this._onPressCollection.bind(this);
this._onPressCoupon = this._onPressCoupon.bind(this);
this._onPressBrandItem= this._onPressBrandItem.bind(this);
this._onPressOneRowTwoColImages= this._onPressOneRowTwoColImages.bind(this);
}
componentDidMount() {
// this.props.actions.getShopsIntro();
this.props.actions.getShopsResources();
}
componentWillUnmount() {
... ... @@ -63,13 +64,18 @@ class BrandStoreContainer extends Component {
_onPressBrandItem(){
this.props.actions.onPressBrandItem();
}
_onPressOneRowTwoColImages(url){
this.props.actions.onPressOneRowTwoColImages(url);
}
render() {
return (
<BrandStore
src = {this.props.brandStore.shopResource}
onPressCoupon={this._onPressCoupon}
onPressBrandItem={this._onPressBrandItem}
onPressBrandItem={this._onPressBrandItem}
onPressOneRowTwoColImages={this._onPressOneRowTwoColImages}
/>
);
}
... ...
{
"data": [
{
"cars": [
{
"icon": "m_180_100",
"name": "AC Schnitzer"
},
{
"icon": "m_92_100",
"name": "阿尔法·罗密欧"
},
{
"icon": "m_9_100",
"name": "奥迪"
},
],
"title": "A"
},
{
"cars": [
{
"icon": "m_172_100",
"name": "巴博斯"
},
{
"icon": "m_157_100",
"name": "宝骏"
},
{
"icon": "m_3_100",
"name": "宝马"
},
{
"icon": "m_82_100",
"name": "保时捷"
},
{
"icon": "m_163_100",
"name": "北京汽车"
},
{
"icon": "m_211_100",
"name": "北汽幻速"
},
{
"icon": "m_168_100",
"name": "北汽威旺"
},
{
"icon": "m_14_100",
"name": "北汽制造"
},
{
"icon": "m_2_100",
"name": "奔驰"
},
{
"icon": "m_59_100",
"name": "奔腾"
},
{
"icon": "m_26_100",
"name": "本田"
},
{
"icon": "m_5_100",
"name": "标致"
},
{
"icon": "m_127_100",
"name": "别克"
},
{
"icon": "m_85_100",
"name": "宾利"
},
{
"icon": "m_15_100",
"name": "比亚迪"
},
{
"icon": "m_135_100",
"name": "布加迪"
}
],
"title": "B"
},
{
"cars": [
{
"icon": "m_129_100",
"name": "昌河"
}
],
"title": "C"
},
{
"cars": [
{
"icon": "m_113_100",
"name": "道奇"
},
{
"icon": "m_165_100",
"name": "大通"
},
{
"icon": "m_8_100",
"name": "大众"
},
{
"icon": "m_27_100",
"name": "东风"
},
{
"icon": "m_197_100",
"name": "东风风度"
},
{
"icon": "m_141_100",
"name": "东风风神"
},
{
"icon": "m_115_100",
"name": "东风风行"
},
{
"icon": "m_205_100",
"name": "东风小康"
},
{
"icon": "m_29_100",
"name": "东南"
},
{
"icon": "m_179_100",
"name": "DS"
}
],
"title": "D"
},
{
"cars": [
{
"icon": "m_91_100",
"name": "法拉利"
},
{
"icon": "m_199_100",
"name": "飞驰商务车"
},
{
"icon": "m_164_100",
"name": "菲斯克"
},
{
"icon": "m_40_100",
"name": "菲亚特"
},
{
"icon": "m_7_100",
"name": "丰田"
},
{
"icon": "m_67_100",
"name": "福迪"
},
{
"icon": "m_190_100",
"name": "弗那萨利"
},
{
"icon": "m_208_100",
"name": "福汽启腾"
},
{
"icon": "m_17_100",
"name": "福特"
},
{
"icon": "m_128_100",
"name": "福田"
}
],
"title": "F"
},
{
"cars": [
{
"icon": "m_109_100",
"name": "GMC"
},
{
"icon": "m_110_100",
"name": "光冈"
},
{
"icon": "m_147_100",
"name": "广汽"
},
{
"icon": "m_63_100",
"name": "广汽吉奥"
},
{
"icon": "m_133_100",
"name": "广汽日野"
},
{
"icon": "m_182_100",
"name": "观致汽车"
}
],
"title": "G"
},
{
"cars": [
{
"icon": "m_31_100",
"name": "哈飞"
},
{
"icon": "m_196_100",
"name": "哈弗"
},
{
"icon": "m_170_100",
"name": "海格"
},
{
"icon": "m_32_100",
"name": "海马"
},
{
"icon": "m_149_100",
"name": "海马商用车"
},
{
"icon": "m_181_100",
"name": "恒天汽车"
},
{
"icon": "m_58_100",
"name": "红旗"
},
{
"icon": "m_52_100",
"name": "黄海"
},
{
"icon": "m_112_100",
"name": "华泰"
},
{
"icon": "m_45_100",
"name": "汇众"
}
],
"title": "H"
},
{
"cars": [
{
"icon": "m_35_100",
"name": "江淮"
},
{
"icon": "m_37_100",
"name": "江铃"
},
{
"icon": "m_38_100",
"name": "江南"
},
{
"icon": "m_98_100",
"name": "捷豹"
},
{
"icon": "m_143_100",
"name": "吉利帝豪"
},
{
"icon": "m_144_100",
"name": "吉利全球鹰"
},
{
"icon": "m_148_100",
"name": "吉利英伦"
},
{
"icon": "m_39_100",
"name": "金杯"
},
{
"icon": "m_57_100",
"name": "金龙联合"
},
{
"icon": "m_161_100",
"name": "金旅客车"
},
{
"icon": "m_152_100",
"name": "九龙"
},
{
"icon": "m_4_100",
"name": "Jeep"
}
],
"title": "J"
},
{
"cars": [
{
"icon": "m_188_100",
"name": "卡尔森"
},
{
"icon": "m_107_100",
"name": "凯迪拉克"
},
{
"icon": "m_150_100",
"name": "开瑞"
},
{
"icon": "m_51_100",
"name": "克莱斯勒"
},
{
"icon": "m_145_100",
"name": "科尼塞克"
},
{
"icon": "m_212_100",
"name": "KTM"
}
],
"title": "K"
},
{
"cars": [
{
"icon": "m_86_100",
"name": "兰博基尼"
},
{
"icon": "m_200_100",
"name": "蓝海房车"
},
{
"icon": "m_80_100",
"name": "劳斯莱斯"
},
{
"icon": "m_94_100",
"name": "雷克萨斯"
},
{
"icon": "m_99_100",
"name": "雷诺"
},
{
"icon": "m_146_100",
"name": "莲花"
},
{
"icon": "m_153_100",
"name": "猎豹汽车"
},
{
"icon": "m_76_100",
"name": "力帆"
},
{
"icon": "m_16_100",
"name": "铃木"
},
{
"icon": "m_166_100",
"name": "理念"
},
{
"icon": "m_95_100",
"name": "林肯"
},
{
"icon": "m_36_100",
"name": "陆风"
},
{
"icon": "m_96_100",
"name": "路虎"
},
{
"icon": "m_83_100",
"name": "路特斯"
}
],
"title": "L"
},
{
"cars": [
{
"icon": "m_183_100",
"name": "迈凯伦"
},
{
"icon": "m_93_100",
"name": "玛莎拉蒂"
},
{
"icon": "m_18_100",
"name": "马自达"
},
{
"icon": "m_79_100",
"name": "MG"
},
{
"icon": "m_81_100",
"name": "MINI"
},
{
"icon": "m_201_100",
"name": "摩根"
}
],
"title": "M"
},
{
"cars": [
{
"icon": "m_155_100",
"name": "纳智捷"
}
],
"title": "N"
},
{
"cars": [
{
"icon": "m_104_100",
"name": "欧宝"
},
{
"icon": "m_84_100",
"name": "讴歌"
},
{
"icon": "m_171_100",
"name": "欧朗"
}
],
"title": "O"
},
{
"cars": [
{
"icon": "m_156_100",
"name": "启辰"
},
{
"icon": "m_43_100",
"name": "庆铃"
},
{
"icon": "m_42_100",
"name": "奇瑞"
},
{
"icon": "m_28_100",
"name": "起亚"
}
],
"title": "Q"
},
{
"cars": [
{
"icon": "m_30_100",
"name": "日产"
},
{
"icon": "m_78_100",
"name": "荣威"
},
{
"icon": "m_142_100",
"name": "瑞麒"
}
],
"title": "R"
},
{
"cars": [
{
"icon": "m_25_100",
"name": "三菱"
},
{
"icon": "m_209_100",
"name": "山姆"
},
{
"icon": "m_195_100",
"name": "绅宝"
},
{
"icon": "m_50_100",
"name": "双环"
},
{
"icon": "m_102_100",
"name": "双龙"
},
{
"icon": "m_111_100",
"name": "斯巴鲁"
},
{
"icon": "m_10_100",
"name": "斯柯达"
},
{
"icon": "m_89_100",
"name": "smart"
}
],
"title": "S"
},
{
"cars": [
{
"icon": "m_202_100",
"name": "泰卡特"
},
{
"icon": "m_189_100",
"name": "特斯拉"
}
],
"title": "T"
},
{
"cars": [
{
"icon": "m_140_100",
"name": "威麟"
},
{
"icon": "m_186_100",
"name": "威兹曼"
},
{
"icon": "m_19_100",
"name": "沃尔沃"
},
{
"icon": "m_48_100",
"name": "五菱"
}
],
"title": "W"
},
{
"cars": [
{
"icon": "m_13_100",
"name": "现代"
},
{
"icon": "m_174_100",
"name": "星客特"
},
{
"icon": "m_71_100",
"name": "新凯"
},
{
"icon": "m_87_100",
"name": "西雅特"
},
{
"icon": "m_49_100",
"name": "雪佛兰"
},
{
"icon": "m_6_100",
"name": "雪铁龙"
}
],
"title": "X"
},
{
"cars": [
{
"icon": "m_194_100",
"name": "扬州亚星客车"
},
{
"icon": "m_138_100",
"name": "野马汽车"
},
{
"icon": "m_100_100",
"name": "英菲尼迪"
},
{
"icon": "m_53_100",
"name": "一汽"
},
{
"icon": "m_41_100",
"name": "依维柯"
},
{
"icon": "m_75_100",
"name": "永源"
}
],
"title": "Y"
},
{
"cars": [
{
"icon": "m_136_100",
"name": "长安轿车"
},
{
"icon": "m_159_100",
"name": "长安商用"
},
{
"icon": "m_21_100",
"name": "长城"
},
{
"icon": "m_203_100",
"name": "之诺"
},
{
"icon": "m_60_100",
"name": "中华"
},
{
"icon": "m_167_100",
"name": "中欧"
},
{
"icon": "m_77_100",
"name": "众泰"
},
{
"icon": "m_204_100",
"name": "中通客车"
},
{
"icon": "m_33_100",
"name": "中兴"
}
],
"title": "Z"
}
]
}
... ... @@ -4,6 +4,7 @@ import ReactNative from 'react-native';
import BrandStoreService from '../../services/BrandStoreService';
const {
ONEROWTWOCOLIMAGE,
SET_COLLECTION,
JUMP_WITH_URL,
SET_SCANTYPE,
... ... @@ -39,6 +40,12 @@ export function onPressCollection() {
payload: true
};
}
export function onPressOneRowTwoColImages(url) {
return {
type: ONEROWTWOCOLIMAGE,
payload: true
};
}
export function shopResourceRequest() {
return {
... ...
... ... @@ -4,6 +4,7 @@ import InitialState from './brandStoreInitialState';
import Immutable, {Map} from 'immutable';
const {
ONEROWTWOCOLIMAGE,
SET_COLLECTION,
JUMP_WITH_URL,
SET_SCANTYPE,
... ... @@ -67,7 +68,9 @@ export default function brandStoreReducer(state=initialState, action) {
case SHOP_RESOURCE_FAILURE:{
return state.set('shopResource', Immutable.fromJS(action.payload))
}
case ONEROWTWOCOLIMAGE:{
// return state.set('isCollection',action.payload);
}
break;
}
... ...