Announcement.js
4.29 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
'use strict';
import React from 'react';
import ReactNative from 'react-native';
import YH_Image from '../../../common/components/YH_Image';
import Immutable, {Map} from 'immutable';
import YH_Swiper from '../../../common/components/YH_Swiper';
const {
View,
Text,
Image,
TouchableOpacity,
StyleSheet,
Dimensions,
Platform,
} = ReactNative;
export default class Announcement extends React.Component {
constructor(props) {
super (props);
}
shouldComponentUpdate(nextProps){
if (Immutable.is(nextProps.headerImage, this.props.headerImage)
&& Immutable.is(nextProps.data, this.props.data)
&& nextProps.duration == this.props.duration) {
return false;
} else {
return true;
}
}
render() {
let {headerImage, data, duration} = this.props;
duration = parseInt(duration);
duration = duration ? duration : 3;
let url = YH_Image.getSlicedUrl(headerImage, headImageWidth, headImageHeight, 2);
data = data.toArray();
return (
<View style={styles.container}>
{headerImage ? <YH_Image style={styles.header} url={url} /> : null}
{headerImage ? <View style={styles.vLine} /> : null}
<Image style={styles.icon} source={require('../../images/announcement_speaker_icon.png')} />
<YH_Swiper
style={styles.banner}
horizontal={false}
showsButtons={false}
loop={true}
autoplay={true}
autoplayTimeout={duration}
showsPagination={false}
height={containerHeight}
scrollEnabled={false}
>
{data.map((item, i) => {
let yh_exposureData = item.get('yh_exposureData')?item.get('yh_exposureData').toJS():null;
return (
<TouchableOpacity
key={i}
yh_exposureData={yh_exposureData}
activeOpacity={1}
onPress={() => {
this.props.onPressAnnounceItem && this.props.onPressAnnounceItem(item.get('url'), '', i);
}}
style={{height: containerHeight, justifyContent: 'center', }}
>
<Text style={styles.text} numberOfLines={1}>{item.get('title')}</Text>
</TouchableOpacity>
);
})}
</YH_Swiper>
</View>
);
}
}
let {width, height} = Dimensions.get('window');
const DEVICE_WIDTH_RATIO = width / 320;
let containerHeight = Math.ceil(35 * DEVICE_WIDTH_RATIO);
let headImageMarginLeft = 15;
let headImageWidth = Math.ceil(63 * DEVICE_WIDTH_RATIO);
let headImageHeight = Math.ceil(13 * DEVICE_WIDTH_RATIO);
let lineViewMarginLeft = 15;
let lineViewMarginRight = 10;
let iconImageMarginRight = 7;
let textFieldMarginRight = 15;
let textFontSize = 12;
// iPhone 6P
if (height == 736) {
headImageMarginLeft = 22.5;
lineViewMarginLeft = 22.5;
lineViewMarginRight = 15;
iconImageMarginRight = 10;
textFieldMarginRight = 22.5;
textFontSize = 13;
}
let textFieldWidth = width - headImageWidth - headImageMarginLeft
- lineViewMarginLeft - 12 - lineViewMarginRight - iconImageMarginRight - 5;
let styles = StyleSheet.create({
container: {
flexDirection: 'row',
alignItems: 'center',
backgroundColor: 'white',
height: containerHeight,
},
header: {
width: headImageWidth,
height: headImageHeight,
marginLeft: headImageMarginLeft,
},
vLine: {
width: 1,
height: 20,
marginLeft: lineViewMarginLeft,
backgroundColor: '#e5e5e5',
},
icon: {
width: 12,
height: 12,
marginLeft: lineViewMarginRight,
marginRight: iconImageMarginRight,
},
banner: {
},
text: {
fontFamily: 'STHeitiSC-Medium',
fontSize: textFontSize,
color: '#444444',
width: textFieldWidth,
},
});