-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCardComponent.js
139 lines (129 loc) · 4.9 KB
/
CardComponent.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
ATTENZIONE: NON DEVI MODIFICARE QUESTO FILE
*/
import React, {Component} from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { ProgressBar, ActivityIndicator, Button } from 'react-native-paper';
class CardComponent extends Component{
constructor(props){
super(props);
}
render(){
return (
<View style={[styles.card, {
height: this.props.size.height,
width: this.props.size.width
}]}>
<Text style={styles.title}>{this.props.title || "Card title"}</Text>
<View style={{flex: 7}}>
{
// Shows the card content when its status is ready
this.props.status === "ready" && this.props.children
}
{
// Shows the card loading when its status is loading
this.props.status === "loading" && (
<View style={styles.statusView}>
<ActivityIndicator size="large" color="#fff"></ActivityIndicator>
<Text style={styles.descriptionLable}>{this.props.statusText}</Text>
</View>
)
}
{
// Shows the card progress when its status is progress
this.props.status === "progress" && (
<View style={styles.statusView}>
<ProgressBar color="#fff" style={{width: 300, height: 8}} progress={this.props.progress}></ProgressBar>
<Text style={styles.descriptionLable}>{this.props.statusText}</Text>
</View>
)
}
{
// Shows the card error when its status is error
this.props.status === "error" && (
<View style={styles.statusView}>
<Text style={styles.errorLabel}>Ops!</Text>
<Text style={styles.descriptionLable}>{this.props.statusText}</Text>
<Button style={[styles.button, {backgroundColor: "#b71c1c"}]}
labelStyle={styles.textButton} mode="contained" onPress={() => {
this.setStatus();
if(typeof this.props.reloadCard === "function")
this.props.reloadCard();
}}>
Ricarica
</Button>
</View>
)
}
{
// Shows the card done when its status is done
this.props.status === "done" && (
<View style={styles.statusView}>
<Text style={styles.errorLabel}>Operazione completata!</Text>
<Text style={styles.descriptionLable}>{this.props.statusText}</Text>
<Button style={[styles.button]}
labelStyle={styles.textButton} mode="contained" onPress={() => {
this.setStatus();
if(typeof this.props.reloadCard === "function")
this.props.reloadCard();
}}>
Ricarica
</Button>
</View>
)
}
</View>
</View>
);
}
}
const styles = new StyleSheet.create({
card: {
backgroundColor: "green",
width: 500,
borderRadius: 8,
padding: 32,
shadowColor: "#000000",
shadowOffset: {
width: 0,
height: 4
},
shadowRadius: 8,
shadowOpacity: 0.3,
minWidth: 400,
minHeight: 500
},
title: {
color: "#ffffff",
fontWeight: "bold",
fontSize: 32,
flex: 1
},
descriptionLable: {
width: "100%",
textAlign: "center",
marginTop: 16,
color: "#fff"
},
errorLabel: {
color: "#fff",
fontSize: 48,
fontWeight: "bold",
textAlign: "center"
},
button: {
marginTop: 32,
backgroundColor: "#311b92"
},
textButton: {
color: "#fff"
},
statusView: {
height: "100%",
width: "100%",
alignContent: "center",
alignItems: "center",
justifyContent: "center"
}
});
export default CardComponent;