forked from alwx/react-native-photo-view
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PhotoView.android.js
90 lines (80 loc) · 3.16 KB
/
PhotoView.android.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,
androidZoomTransitionDuration: PropTypes.number,
androidScaleType: PropTypes.oneOf(["center", "centerCrop", "centerInside", "fitCenter", "fitStart", "fitEnd", "fitXY", "matrix"]),
onLoadStart: PropTypes.func,
onError: PropTypes.func,
onLoad: PropTypes.func,
onLoadEnd: PropTypes.func,
onTap: PropTypes.func,
onViewTap: PropTypes.func,
onScale: PropTypes.func,
...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, onTap, onViewTap, onScale, onError, ...props} = this.props;
var nativeProps = {
onPhotoViewerError: onError,
onPhotoViewerLoadStart: onLoadStart,
onPhotoViewerLoad: onLoad,
onPhotoViewerLoadEnd: onLoadEnd,
onPhotoViewerTap: onTap,
onPhotoViewerViewTap: onViewTap,
onPhotoViewerScale: onScale,
...props,
shouldNotifyLoadEvents: !!(onLoadStart || onLoad || onLoadEnd || onError),
src: source,
loadingIndicatorSrc: loadingIndicatorSource ? loadingIndicatorSource.uri : null,
};
return <PhotoViewAndroid {...nativeProps} />
}
return null
}
}
var cfg = {
nativeOnly: {
onPhotoViewerError: true,
onPhotoViewerLoadStart: true,
onPhotoViewerLoad: true,
onPhotoViewerLoadEnd: true,
onPhotoViewerTap: true,
onPhotoViewerViewTap: true,
onPhotoViewerScale: true,
shouldNotifyLoadEvents: true,
src: true,
loadingIndicatorSrc: true
}
};
const PhotoViewAndroid = requireNativeComponent('PhotoViewAndroid', PhotoView, cfg);