forked from nihgwu/react-native-flanimatedimage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FLAnimatedImage.ios.js
72 lines (63 loc) · 1.75 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
64
65
66
67
68
69
70
71
72
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { requireNativeComponent, NativeModules, StyleSheet,Image,View } 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
var isPNG = (src.split('?')[0].search('.png') != -1);
// return (
// <RNFLAnimatedImage {...this.props} src={src} contentMode={contentMode} />
// )
return (<View>
{ isPNG ?
<Image source={this.props.source} style={this.props.style} />
:
<RNFLAnimatedImage {...this.props} src={src} contentMode={contentMode} />
}
</View>
)
}
}
const styles = StyleSheet.create({})
const RNFLAnimatedImage = requireNativeComponent(
'RNFLAnimatedImage',
FLAnimatedImage
)
export default FLAnimatedImage