forked from merryjs/photo-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
119 lines (119 loc) · 3.21 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
import * as React from "react";
import {
requireNativeComponent,
processColor,
Platform,
View
} from "react-native";
import * as PropTypes from "prop-types";
import resolveAssetSource from "react-native/Libraries/Image/resolveAssetSource";
import ImageSourcePropType from "react-native/Libraries/DeprecatedPropTypes/DeprecatedImageSourcePropType";
class MerryPhotoView extends React.Component {
constructor() {
super(...arguments);
/**
* Handle UIColor conversions
* @param data Photo[]
*/
this.processor = data => {
if (data && data.length) {
return data.map(o => {
const d = { ...o };
if (typeof o.summaryColor === "string") {
d.summaryColor = processColor(o.summaryColor);
}
if (typeof o.titleColor === "string") {
d.titleColor = processColor(o.titleColor);
}
// resolve assets
d.source = resolveAssetSource(o.source);
return d;
});
}
return data;
};
this.onChange = event => {
const { onChange } = this.props;
if (onChange) {
const { target, ...rest } = event.nativeEvent;
onChange(rest);
}
};
}
render() {
// nothing
if (this.props.visible === false) {
return null;
}
const { visible, data, initial, ...props } = this.props;
const dataCopy = [...data];
const transformData = this.processor(dataCopy);
// initial
let startPosition = initial;
if (initial < 0) {
startPosition = 0;
}
if (initial > dataCopy.length) {
startPosition = dataCopy.length;
}
return (
<RNMerryPhotoView
{...props}
initial={startPosition}
data={transformData}
onChange={this.onChange}
/>
);
}
}
MerryPhotoView.propTypes = {
data: PropTypes.arrayOf(
PropTypes.shape({
source:
Platform.OS === "ios"
? ImageSourcePropType
: PropTypes.oneOfType([
PropTypes.shape({
uri: PropTypes.string,
headers: PropTypes.objectOf(PropTypes.string)
}),
// Opaque type returned by require('./image.jpg')
PropTypes.number,
// Multiple sources
PropTypes.arrayOf(
PropTypes.shape({
uri: PropTypes.string,
width: PropTypes.number,
height: PropTypes.number
})
)
]),
title: PropTypes.string,
summary: PropTypes.string,
titleColor: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
summaryColor: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
})
).isRequired,
visible: PropTypes.bool,
initial: PropTypes.number.isRequired,
hideStatusBar: PropTypes.bool,
hideCloseButton: PropTypes.bool,
hideShareButton: PropTypes.bool,
onDismiss: PropTypes.func.isRequired,
onChange: PropTypes.func,
shareText: PropTypes.string,
...View.propTypes
};
MerryPhotoView.defaultProps = {
visible: false
};
var RNMerryPhotoView = requireNativeComponent(
"MerryPhotoView",
MerryPhotoView,
{
nativeOnly: {
onChange: true
}
}
);
export default MerryPhotoView;