-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (43 loc) · 1.46 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
/**
* Created by Stanislav Doskalenko on 22.06.17.
* © 2017-present, doskalenko.s@gmail.com
*/
'use strict';
import React from 'react';
import { Animated, Image } from 'react-native';
export default class FadeImage extends React.PureComponent {
constructor (props) {
super(props);
if (this.props.source.uri) {
Image.prefetch(this.props.source.uri);
}
}
imageOpacity = new Animated.Value(0);
onLoadImage () {
if (this.props.onLoad) {
this.props.onLoad();
}
Animated.timing(this.imageOpacity, {
toValue: 1,
duration: this.props.duration || 500,
useNativeDriver: true
}).start();
}
render () {
return (
<Animated.Image style={[this.props.style, {opacity: this.imageOpacity}]}
source={this.props.source}
ref={this.props.ref}
resizeMode={this.props.resizeMode || 'cover'}
onLoadStart={this.props.onLoadStart}
onProgress={this.props.onProgress}
onLoad={()=>{this.onLoadImage()}}
onError={this.props.onError}
onLoadEnd={this.props.onLoadEnd}
defaultSource={this.props.defaultSource}
>
{this.props.children}
</Animated.Image>
);
}
}