forked from sidevesh/react-native-material-cards
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCardTitle.js
99 lines (97 loc) · 2.75 KB
/
CardTitle.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import React, {Component} from 'react';
import {
StyleSheet,
Text,
View,
Image
} from 'react-native';
export default class CardTitle extends Component {
render () {
const newStyle = this.props.style || {};
let titleStyle = [styles.titleText];
let subtitleStyle = [styles.subtitleText];
if((this.props.title!==undefined)&&(this.props.subtitle!==undefined)&&(this.props.avatarSource===undefined)) {
if(this.props.subtitleAbove===true) {
subtitleStyle = [...subtitleStyle, {marginBottom: 12}];
}
else {
titleStyle = [...titleStyle, {marginBottom: 12}];
}
}
if(this.props.isDark) {
subtitleStyle = [...subtitleStyle, styles.lightText];
titleStyle = [...titleStyle, styles.lightText];
}
else {
titleStyle = [...titleStyle, styles.darkText];
}
if(this.props.subtitleAbove!==true) {
return (
<View style={[styles.cardTitle, newStyle]}>
{this.props.avatarSource!==undefined &&
<Image source={this.props.avatarSource} resizeMode="stretch" style={styles.avatarStyle} />
}
<View style={styles.cardTitleTextCont}>
{this.props.title!==undefined &&
<Text style={this.props.avatarSource===undefined ? titleStyle : [titleStyle, {fontSize: 14}]}>{this.props.title}</Text>
}
{this.props.subtitle!==undefined &&
<Text style={subtitleStyle}>{this.props.subtitle}</Text>
}
</View>
</View>
);
}
else {
return (
<View style={[styles.cardTitle, newStyle]}>
{this.props.avatarSource!==undefined &&
<Image source={this.props.avatarSource} resizeMode="stretch" style={styles.avatarStyle} />
}
<View style={styles.cardTitleTextCont}>
{this.props.subtitle!==undefined &&
<Text style={subtitleStyle}>{this.props.subtitle}</Text>
}
{this.props.title!==undefined &&
<Text style={this.props.avatarSource===undefined ? titleStyle : [titleStyle, {fontSize: 14}]}>{this.props.title}</Text>
}
</View>
</View>
);
}
}
}
const styles = StyleSheet.create({
darkText: {
color: 'rgba(0 ,0 ,0 , 0.87)'
},
lightText: {
color: 'rgba(255 ,255 ,255 , 0.87)'
},
cardTitle: {
flex: 1,
flexDirection: 'row',
alignItems: 'flex-start',
paddingRight: 16,
paddingLeft: 16,
paddingBottom: 16,
paddingTop: 16
},
cardTitleTextCont: {
flex: 1,
flexDirection: 'column'
},
titleText: {
fontSize: 24
},
subtitleText: {
fontSize:14,
color: 'rgba(0 ,0 ,0 , 0.38)'
},
avatarStyle: {
width: 40,
height: 40,
borderRadius: 20,
marginRight: 16
}
});