-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimageViewer.js
105 lines (91 loc) · 2.38 KB
/
imageViewer.js
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
'use strict';
var React = require('react-native');
var {
ScrollView,
StyleSheet,
View,
Image,
Text
} = React;
var Thumb = React.createClass({
shouldComponentUpdate: function(nextProps, nextState) {
return false;
},
getImageSize: function() {
return {
height: this.props.height,
width: this.props.width,
}
},
render: function() {
return (
<View style={styles.thumb}>
<Image style={this.getImageSize()} source={{uri:this.props.uri}} resizeMode={'contain'}></Image>
</View>
);
}
});
var ImageViewer = React.createClass({
createThumbRow: function(uri, i) {
return <Thumb key={i} uri={uri} width={this.props.width} height={this.props.height}/>;
},
getInitialState: function() {
return {
index: 1,
};
},
createPointRow: function(filled, i) {
if (filled) {
return <View key={i} style={{marginLeft: 5, width: 10, height: 10, borderRadius: 5, backgroundColor: '#FFFFFF'}}></View>;
} else {
return <View key={i} style={{marginLeft: 5, width: 10, height: 10, borderRadius: 5, backgroundColor: '#A8A8A8'}}></View>;
}
},
onScroll: function(a) {
var i = Math.round(a.nativeEvent.contentOffset.x / this.props.width) + 1;
this.setState({index: i});
},
render: function() {
var points = [];
for (var i = 1; i <= this.props.data.length; i++) {
if (i == this.state.index) {
points.push(true);
} else {
points.push(false);
}
}
return (
<View style={{backgroundColor: '#F0F0F0'}}>
<View>
<ScrollView
horizontal={true}
pagingEnabled={true}
showsHorizontalScrollIndicator={false}
onScroll={this.onScroll}
scrollEventThrottle={1}
bounces={false}>
{this.props.data.map(this.createThumbRow)}
</ScrollView>
</View>
<View style={{top: -20, backgroundColor: 'rgba(0,0,0,0)'}}>
<View style={[styles.mainImageBox]}>
{points.map(this.createPointRow)}
</View>
</View>
</View>
);
},
});
var styles = StyleSheet.create({
thumb: {
alignItems: 'center',
backgroundColor: '#F0F0F0',
},
mainImageBox: {
backgroundColor: 'rgba(0,0,0,0)',
alignSelf: 'center',
justifyContent: 'flex-end',
flexDirection: 'row',
},
});
module.exports = ImageViewer;