forked from leecade/react-native-swiper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
151 lines (147 loc) · 3.24 KB
/
index.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
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
import React, { Component } from 'react'
import {
Text,
View,
Image,
TouchableOpacity,
TouchableWithoutFeedback,
Dimensions
} from 'react-native'
import Swiper from 'react-native-swiper'
import PhotoView from 'react-native-photo-view'
const { width, height } = Dimensions.get('window')
var styles = {
wrapper: {
backgroundColor: '#000',
top: 0,
right: 0,
bottom: 0,
left: 0
},
slide: {
flex: 1,
justifyContent: 'center',
alignItems: 'center'
},
photo: {
width,
height,
flex: 1
},
text: {
color: '#fff',
fontSize: 30,
fontWeight: 'bold'
},
thumbWrap: {
marginTop: 100,
borderWidth: 5,
borderColor: '#000',
flexDirection: 'row'
},
thumb: {
width: 50,
height: 50
}
}
const renderPagination = (index, total, context) => {
return (
<View
style={{
position: 'absolute',
justifyContent: 'center',
alignItems: 'center',
top: 25,
left: 0,
right: 0
}}
>
<View
style={{
borderRadius: 7,
backgroundColor: 'rgba(255,255,255,.15)',
padding: 3,
paddingHorizontal: 7
}}
>
<Text
style={{
color: '#fff',
fontSize: 14
}}
>
{index + 1} / {total}
</Text>
</View>
</View>
)
}
const Viewer = props => (
<Swiper
index={props.index}
style={styles.wrapper}
renderPagination={renderPagination}
>
{props.imgList.map((item, i) => (
<View key={i} style={styles.slide}>
<TouchableWithoutFeedback onPress={e => props.pressHandle()}>
<PhotoView
source={{ uri: item }}
resizeMode="contain"
minimumZoomScale={0.5}
maximumZoomScale={3}
androidScaleType="center"
style={styles.photo}
/>
</TouchableWithoutFeedback>
</View>
))}
</Swiper>
)
export default class extends Component {
constructor(props) {
super(props)
this.state = {
imgList: [
'https://avatars3.githubusercontent.com/u/533360?v=3&s=466',
'https://assets-cdn.github.com/images/modules/site/business-hero.jpg',
'https://placeholdit.imgix.net/~text?txtsize=29&txt=350%C3%971150&w=350&h=1150'
],
showViewer: true,
showIndex: 0
}
this.viewerPressHandle = this.viewerPressHandle.bind(this)
this.thumbPressHandle = this.thumbPressHandle.bind(this)
}
viewerPressHandle() {
this.setState({
showViewer: false
})
}
thumbPressHandle(i) {
this.setState({
showIndex: i,
showViewer: true
})
}
render() {
return (
<View style={{ position: 'relative' }}>
{this.state.showViewer && (
<Viewer
index={this.state.showIndex}
pressHandle={this.viewerPressHandle}
imgList={this.state.imgList}
/>
)}
<View style={styles.thumbWrap}>
{this.state.imgList.map((item, i) => (
<TouchableOpacity key={i} onPress={e => this.thumbPressHandle(i)}>
<Image style={styles.thumb} source={{ uri: item }} />
</TouchableOpacity>
))}
</View>
</View>
)
}
}