-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathindex.js
77 lines (64 loc) · 2.42 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
'use strict'
import PropTypes from 'prop-types'
import React from 'react'
import { requireNativeComponent, View } from 'react-native'
const resolveAssetSource = require('react-native/Libraries/Image/resolveAssetSource')
const URISourcePropType = PropTypes.shape({
uri: PropTypes.string
})
const SourcePropType = PropTypes.oneOfType([URISourcePropType, PropTypes.number])
class WebImage extends React.Component {
static propTypes = {
...View.propTypes,
source: SourcePropType.isRequired,
/**
* Determines how to resize the image when the frame doesn't match the raw
* image dimensions.
*
* 'cover': Scale the image uniformly (maintain the image's aspect ratio)
* so that both dimensions (width and height) of the image will be equal
* to or larger than the corresponding dimension of the view (minus padding).
*
* 'contain': Scale the image uniformly (maintain the image's aspect ratio)
* so that both dimensions (width and height) of the image will be equal to
* or less than the corresponding dimension of the view (minus padding).
*
* 'stretch': Scale width and height independently, This may change the
* aspect ratio of the src.
*
* 'center': Scale the image down so that it is completely visible,
* if bigger than the area of the view.
* The image will not be scaled up.
*/
resizeMode: PropTypes.oneOf(['cover', 'contain', 'stretch', 'center']),
/**
* Callback called on error. With event.nativeEvent object with props:
* error - error message
* uri - URL that result this error
*/
onError: PropTypes.func,
/**
* Callback called on success. With event.nativeEvent object with props:
* uri - URL that result this success
*/
onSuccess : PropTypes.func
}
render () {
const { source, ...props } = this.props
const resolvedSource = resolveAssetSource(source)
return <WebImageView {...props} source={resolvedSource} onWebImageError={this._onError} onWebImageSuccess={this._onSuccess} />
}
_onSuccess = (e) => {
this.props.onSuccess && this.props.onSuccess(e.nativeEvent)
}
_onError = (e) => {
this.props.onError && this.props.onError(e.nativeEvent)
}
}
WebImage.defaultProps = {
resizeMode: 'contain'
}
var WebImageView = requireNativeComponent('WebImageView', WebImage, {
nativeOnly: {onWebImageError: true, onWebImageSuccess : true}
})
export default WebImage