-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathCardImage.js
56 lines (54 loc) · 1.41 KB
/
CardImage.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
import React, { Component } from 'react';
import {
StyleSheet,
Text,
View,
ImageBackground,
} from 'react-native';
export default class CardImage extends Component {
constructor(props) {
super(props);
this.state = {
calc_height: 0,
};
}
render() {
const newStyle = this.props.style || {};
return (
<View style={[styles.cardImage, newStyle]} onLayout={(e) => { this.setState({ calc_height: e.nativeEvent.layout.width * 9 / 16 }); }}>
{
this.props.source &&
<ImageBackground source={this.props.source} resizeMode={this.props.resizeMode || 'cover'} resizeMethod={this.props.resizeMethod || 'resize'} style={[styles.imageContainer, { height: this.state.calc_height }]}>
{this.props.title !== undefined &&
<Text style={styles.imageTitleText}>{this.props.title}</Text>
}
</ImageBackground>
}
</View>
);
}
}
const styles = StyleSheet.create({
cardImage: {
flex: 1,
flexDirection: 'row',
backgroundColor: 'grey',
alignSelf: 'stretch',
marginBottom: 16,
justifyContent: 'center',
alignItems: 'stretch',
},
imageContainer: {
flex: 1,
flexDirection: 'column',
paddingRight: 16,
paddingLeft: 16,
paddingBottom: 16,
paddingTop: 16,
justifyContent: 'flex-end',
},
imageTitleText: {
fontSize: 24,
color: 'rgba(255 ,255 ,255 , 0.87)',
}
});