-
Notifications
You must be signed in to change notification settings - Fork 23
/
FLAnimatedImage.ios.js
63 lines (54 loc) · 1.45 KB
/
FLAnimatedImage.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
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { requireNativeComponent, NativeModules, StyleSheet } from 'react-native'
import resolveAssetSource from 'react-native/Libraries/Image/resolveAssetSource'
const {
ScaleToFill,
ScaleAspectFit,
ScaleAspectFill,
} = NativeModules.RNFLAnimatedImageManager
const MODES = {
stretch: ScaleToFill,
contain: ScaleAspectFit,
cover: ScaleAspectFill,
}
class FLAnimatedImage extends Component {
static propTypes = {
// native only
contentMode: PropTypes.number,
source: PropTypes.oneOfType([
PropTypes.shape({
uri: PropTypes.string,
width: PropTypes.number,
height: PropTypes.number,
scale: PropTypes.number,
}),
PropTypes.number,
]),
src: PropTypes.string,
resizeMode: PropTypes.string,
onFrameChange: PropTypes.func,
onLoadEnd: PropTypes.func,
}
static defaultProps = {
resizeMode: 'contain',
}
render() {
const contentMode = MODES[this.props.resizeMode]
const source = resolveAssetSource(this.props.source) || {
uri: undefined,
width: undefined,
height: undefined,
}
const src = source.uri
return (
<RNFLAnimatedImage {...this.props} src={src} contentMode={contentMode} />
)
}
}
const styles = StyleSheet.create({})
const RNFLAnimatedImage = requireNativeComponent(
'RNFLAnimatedImage',
FLAnimatedImage
)
export default FLAnimatedImage