Repository navigation
Expand file tree
/
Copy pathImageViewer.js
More file actions
81 lines (71 loc) · 1.7 KB
/
Copy pathImageViewer.js
File metadata and controls
81 lines (71 loc) · 1.7 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
/*
Copyright © SuperMap. All rights reserved.
Author: Yang Shanglong
E-mail: yangshanglong@supermap.com
*/
import * as React from 'react'
import { Modal } from 'react-native'
import ImageViewer from 'react-native-image-zoom-viewer'
export default class MyImageViewer extends React.Component {
props: {
imageUrls: Array,
enableImageZoom?: boolean,
index?: number,
onChange?: () => {},
onClick?: () => {},
}
static defaultProps = {
imageUrls: [],
enableImageZoom: true,
}
state = {
visible: false,
index: -1,
}
shouldComponentUpdate(nextProps, nextState) {
return (
JSON.stringify(this.props) !== JSON.stringify(nextProps) ||
JSON.stringify(this.state) !== JSON.stringify(nextState)
)
}
setVisible = (visible = !this.state.visible, index = 0) => {
if (visible !== this.state.visible) {
this.setState({
visible,
index,
})
}
}
_onChange = index => {
if (this.props.onChange && typeof this.props.onChange === 'function') {
this.props.onChange(index)
}
index !== this.state.index &&
this.setState({
index,
})
}
_onClick = index => {
if (this.props.onClick && typeof this.props.onClick === 'function') {
this.props.onClick(index)
}
this.setVisible(false)
}
// setImageIndex = index => {
// index !== this.state.index && this.setState({
// index,
// })
// }
render() {
return (
<Modal visible={this.state.visible} transparent={true}>
<ImageViewer
index={this.state.index}
{...this.props}
onChange={this._onChange}
onClick={this._onClick}
/>
</Modal>
)
}
}