Header.js
5.21 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
'use strict';
import React from 'react';
import ReactNative from 'react-native';
import Immutable, {Map} from 'immutable';
import DeviceInfo from 'react-native-device-info';
import {getSlicedUrl} from '../../../classify/utils/Utils';
import {removeHTMLTag} from '../../utils/Helper';
import YH_Image from '../../../common/components/YH_Image';
const {
View,
Image,
Text,
TouchableOpacity,
Dimensions,
StyleSheet,
Platform,
} = ReactNative;
const BODY_TAG_PATTERN = /\<\/ *body\>/;
var script = `
;(function() {
var wrapper = document.createElement("div");
wrapper.id = "height-wrapper";
while (document.body.firstChild) {
wrapper.appendChild(document.body.firstChild);
}
document.body.appendChild(wrapper);
var i = 0;
function updateHeight() {
document.title = wrapper.clientHeight;
window.location.hash = ++i;
}
updateHeight();
window.addEventListener("load", function() {
updateHeight();
setTimeout(updateHeight, 1000);
});
window.addEventListener("resize", updateHeight);
}());
`;
const style = `
<style>
body, html, #height-wrapper {
margin: 0;
padding: 0;
}
#height-wrapper {
position: absolute;
top: 0;
left: 0;
right: 0;
}
</style>
<script>
${script}
</script>
`;
const codeInject = (html) => html.replace(BODY_TAG_PATTERN, style + "</body>");
export default class Header extends React.Component {
constructor(props) {
super (props);
}
shouldComponentUpdate(nextProps,nextState){
if (Immutable.is(nextProps.resource, this.props.resource) && nextProps.launchProfile==this.props.launchProfile) {
return false;
} else {
return true;
}
}
render() {
let {resource,launchProfile} = this.props;
if (!resource) {
return (<View style={{height:0,width:width,backgroundColor:'white'}}/>);
}
let data = resource.toJS();
let brandName = data.is_show_shop_name?data.shop_name:'';
let num = data.favoriteCount?data.favoriteCount:0;
let numberOfFav = '粉丝: '+ num;
let backgroundImage = data.shopBanner?data.shopBanner.module_data.data[0].pic:'null';
let brandIcon = getSlicedUrl(data.shop_logo, 60, 60, 2);
let isFav = data.is_addFav;
let favImage = isFav?require('../../image/btn_gz_h.png'):require('../../image/btn_gz_n.png');
//获取字体
let fontFamilyStyle = {};
if (Platform.OS === 'ios') {
let systemVersion = DeviceInfo.getSystemVersion();
systemVersion = parseFloat(systemVersion);
if (systemVersion >= 9.0) {
fontFamilyStyle = {fontFamily: 'PingFang SC'};
}
}
return (
<View style={{width: width, height: imageHeigth,backgroundColor: 'white'}}>
<YH_Image
url={backgroundImage}
style={{width, height: imageHeigth }}
/>
<View style={styles.maskView}/>
<View style={styles.header}>
<Text style={styles.number} numberOfLines={1}>{numberOfFav}</Text>
<TouchableOpacity activeOpacity={0.5} onPress={() => {
this.props.onPressCollection && this.props.onPressCollection(isFav);
}}>
<Image source={favImage} style={styles.favImage}/>
</TouchableOpacity>
</View>
<YH_Image
url={brandIcon}
style={styles.brandIcon}
/>
<Text style={styles.name} numberOfLines={1}>{brandName}</Text>
</View>
);
}
}
let {width, height} = Dimensions.get('window');
let imageHeigth = Math.ceil((234/750)*width);
let styles = StyleSheet.create({
container: {
backgroundColor:'white',
},
brandIcon: {
width: 50,
height: 50,
position: 'absolute',
left: 10,
borderWidth: 1,
bottom: 10,
borderColor: '#e0e0e0',
},
maskView: {
width: width,
height: imageHeigth,
position: 'absolute',
top: 0,
backgroundColor: 'rgba(0,0,0,.25)'
},
header: {
justifyContent: 'flex-end',
flexDirection: 'row',
width: width,
height: 25,
position: 'absolute',
bottom: 10,
backgroundColor: 'transparent',
},
name: {
marginLeft: 10 + 50 + 10,
marginTop: -14 -10,
backgroundColor: 'transparent',
width: 150,
color: '#ffffff',
fontWeight: 'bold',
fontSize: 14,
},
number: {
color: '#ffffff',
fontSize: 12,
marginRight: 10,
marginTop: 8,
backgroundColor: 'transparent',
},
favImage: {
width: 64,
height: 25,
backgroundColor: 'transparent',
marginRight: 10,
},
text: {
marginLeft: 20,
width: width-40,
height: 40,
backgroundColor: 'white',
lineHeight: 18,
fontSize: 14,
color: '#444444',
},
fliter: {
width: width,
height: 30,
backgroundColor: 'white',
alignItems: 'center',
justifyContent: 'center',
},
pullDown: {
width: 15,
height: 8,
},
});