-
Notifications
You must be signed in to change notification settings - Fork 434
/
PhotoView.ios.js
90 lines (80 loc) · 3.03 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
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { requireNativeComponent, View } from 'react-native';
import ViewPropTypes from 'react-native/Libraries/Components/View/ViewPropTypes';
const resolveAssetSource = require('react-native/Libraries/Image/resolveAssetSource');
export default class PhotoView extends Component {
static propTypes = {
source: PropTypes.oneOfType([
PropTypes.shape({
uri: PropTypes.string
}),
// Opaque type returned by require('./image.jpg')
PropTypes.number
]),
loadingIndicatorSource: PropTypes.oneOfType([
PropTypes.shape({
uri: PropTypes.string
}),
// Opaque type returned by require('./image.jpg')
PropTypes.number
]),
fadeDuration: PropTypes.number,
minimumZoomScale: PropTypes.number,
maximumZoomScale: PropTypes.number,
scale: PropTypes.number,
onLoadStart: PropTypes.func,
onLoad: PropTypes.func,
onLoadEnd: PropTypes.func,
onProgress: PropTypes.func,
onTap: PropTypes.func,
onViewTap: PropTypes.func,
onScale: PropTypes.func,
showsHorizontalScrollIndicator: PropTypes.bool,
showsVerticalScrollIndicator: PropTypes.bool,
...ViewPropTypes
};
render() {
const source = resolveAssetSource(this.props.source);
var loadingIndicatorSource = resolveAssetSource(this.props.loadingIndicatorSource);
if (source && source.uri === '') {
console.warn('source.uri should not be an empty string');
}
if (this.props.src) {
console.warn('The <PhotoView> component requires a `source` property rather than `src`.');
}
if (source && source.uri) {
var {onLoadStart, onLoad, onLoadEnd, onProgress, onTap, onViewTap, onScale, onError, ...props} = this.props;
var nativeProps = {
onPhotoViewerError: onError,
onPhotoViewerLoadStart: onLoadStart,
onPhotoViewerLoad: onLoad,
onPhotoViewerLoadEnd: onLoadEnd,
onPhotoViewerProgress: onProgress,
onPhotoViewerTap: onTap,
onPhotoViewerViewTap: onViewTap,
onPhotoViewerScale: onScale,
...props,
src: source,
loadingIndicatorSrc: loadingIndicatorSource ? loadingIndicatorSource.uri : null,
};
return <RNPhotoView {...nativeProps} />
}
return null
}
}
var cfg = {
nativeOnly: {
onPhotoViewerError: true,
onPhotoViewerLoadStart: true,
onPhotoViewerLoad: true,
onPhotoViewerLoadEnd: true,
onPhotoViewerProgress: true,
onPhotoViewerTap: true,
onPhotoViewerViewTap: true,
onPhotoViewerScale: true,
src: true,
loadingIndicatorSrc: true
}
};
const RNPhotoView = requireNativeComponent('RNPhotoView', PhotoView, cfg);