forked from alwx/react-native-photo-view
-
Notifications
You must be signed in to change notification settings - Fork 35
/
PhotoView.ios.js
104 lines (93 loc) · 2.9 KB
/
PhotoView.ios.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
import React from 'react'
import PropTypes from 'prop-types'
import { requireNativeComponent, Image, StyleSheet, View, ViewPropTypes } from 'react-native'
export default class PhotoView extends React.PureComponent {
static propTypes = {
source: PropTypes.oneOfType([
PropTypes.shape({
uri: PropTypes.string,
}),
PropTypes.number,
]).isRequired,
loadingIndicatorSource: PropTypes.oneOfType([
PropTypes.shape({
uri: PropTypes.string,
}),
PropTypes.number,
]),
fadeDuration: PropTypes.number,
minimumZoomScale: PropTypes.number,
maximumZoomScale: PropTypes.number,
resizeMode: PropTypes.string,
scale: PropTypes.number,
onLoad: PropTypes.func,
onLoadEnd: PropTypes.func,
onLoadStart: PropTypes.func,
onProgress: PropTypes.func,
onScale: PropTypes.func,
onTap: PropTypes.func,
onViewTap: PropTypes.func,
showsHorizontalScrollIndicator: PropTypes.bool,
showsVerticalScrollIndicator: PropTypes.bool,
...ViewPropTypes,
};
render () {
const {
onError,
onLoad,
onLoadEnd,
onLoadStart,
onProgress,
onScale,
onTap,
onViewTap,
source: _source,
loadingIndicatorSource: _loadingIndicatorSource,
style: _style,
...props
} = this.props
const source = Image.resolveAssetSource(_source)
const loadingIndicatorSource = Image.resolveAssetSource(_loadingIndicatorSource)
if (source && source.uri === '') {
console.warn('source.uri should not be an empty string')
}
if (props.src) {
console.warn('The <PhotoView> component requires a `source` property rather than `src`.')
}
if (source && source.uri) {
const { width, height, ...src } = source
const style = StyleSheet.flatten([{ width, height }, _style])
const nativeProps = {
onPhotoViewerError: onError,
onPhotoViewerLoad: onLoad,
onPhotoViewerLoadEnd: onLoadEnd,
onPhotoViewerLoadStart: onLoadStart,
onPhotoViewerProgress: onProgress,
onPhotoViewerScale: onScale,
onPhotoViewerTap: onTap,
onPhotoViewerViewTap: onViewTap,
...props,
style,
src,
loadingIndicatorSrc: loadingIndicatorSource && loadingIndicatorSource.uri || null,
}
return <RNPhotoView {...nativeProps} />
}
return null
}
}
const cfg = {
nativeOnly: {
onPhotoViewerError: true,
onPhotoViewerLoad: true,
onPhotoViewerLoadEnd: true,
onPhotoViewerLoadStart: true,
onPhotoViewerProgress: true,
onPhotoViewerScale: true,
onPhotoViewerTap: true,
onPhotoViewerViewTap: true,
src: true,
loadingIndicatorSrc: true,
},
}
const RNPhotoView = requireNativeComponent('RNPhotoView', PhotoView, cfg)