-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlaceHolderFastImage.js
More file actions
47 lines (42 loc) · 1.23 KB
/
PlaceHolderFastImage.js
File metadata and controls
47 lines (42 loc) · 1.23 KB
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
import React, { Component } from 'react'
import { ActivityIndicator, View, StyleSheet } from 'react-native'
import { Images, Metrics } from '../Themes'
import FastImage from 'react-native-fast-image'
export default class PlaceHolderFastImage extends Component {
constructor(props){
super(props)
this.state = {
loaded: false,
style: StyleSheet.flatten(props.style)
}
}
onLoadEnd(){
this.setState({loaded: true})
}
render() {
const top = (this.state.style.height / 2) - 15
const left = this.state.style.width == 'auto' ? (Metrics.screenWidth / 2 - 30) : (this.state.style.width / 2 - 15)
return <View style={this.props.style}>
{
!this.state.loaded &&
<View>
<FastImage
source={Images.placeholder}
style={this.props.style}
/>
<View style={{
position:'absolute',
top: top,
left: left}}>
<ActivityIndicator size="large" color="#ccc" />
</View>
</View>
}
<FastImage
source={this.props.source}
style={[this.props.style, this.state.loaded ? {} : {width: 0, height: 0}]}
onLoadEnd={this.onLoadEnd.bind(this)}
/>
</View>
}
}