ShopRecommend.js
2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
'use strict';
import React, {Component} from 'react';
import ReactNative, {
View,
Text,
ListView,
TouchableOpacity,
StyleSheet,
Dimensions,
} from 'react-native';
import Immutable, {Map} from 'immutable';
import HeadTitleCell from '../cell/HeadTitleCell';
import YH_GoodsStore from '../../../common/components/YH_GoodsStore';
/**
* 好店推荐楼层,
* 这个楼层是滚动的3D大图
**/
export default class ShopRecommend extends Component{
constructor(props) {
super(props);
this.onClick = this.onClick.bind(this);
}
shouldComponentUpdate(nextProps){
if (Immutable.is(nextProps.data, this.props.data)
&& Immutable.is(nextProps.favoriteState, this.props.favoriteState)) {
return false;
} else {
return true;
}
}
onClick(event: Event) {
let type = event.nativeEvent.type;
let index = event.nativeEvent.index;
if (type == 'favorite') {
let shopId = event.nativeEvent.shopId;
this.props.onPressShopFavorite && this.props.onPressShopFavorite(shopId, index);
} else {
let url = event.nativeEvent.url;;
this.props.onPressShopRecommendItem && this.props.onPressShopRecommendItem(url, index);
}
}
render(){
let {title, list} = this.props.data.toJS();
let state = this.props.favoriteState.toJS();
return (
<View style={styles.container}>
<HeadTitleCell title={title.name} moreUrl={title.more_url} onPressTitleMore={this.props.onPressTitleMore} />
<YH_GoodsStore style={styles.store} dataSource={list} favoriteState={state} onClick={this.onClick}/>
</View>
);
}
};
let {width} = Dimensions.get('window');
const DEVICE_WIDTH_RATIO = width / 375;
let storeHeight = Math.ceil(239 * DEVICE_WIDTH_RATIO + 10);
let containerHeight = 40 + storeHeight;
let styles = StyleSheet.create({
container: {
width,
height: containerHeight,
backgroundColor: '#f0f0f0',
},
store: {
width: width,
height: storeHeight,
},
});