/
Modifiers.kt
184 lines (166 loc) · 5.86 KB
/
Modifiers.kt
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
package com.github.compose_playground
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.res.imageResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.github.compose_playground.ui.theme.typography
@Preview(showBackground = true)
@Composable
fun Plain() {
Row(modifier = Modifier.fillMaxWidth()) {
Image(
modifier = Modifier.size(40.dp),
bitmap = ImageBitmap.imageResource(id = R.drawable.miku),
contentDescription = null, // decorative
)
Column(modifier = Modifier.weight(1f)) {
Text(text = name, maxLines = 1)
Text(text = desc, maxLines = 1)
}
Text("Follow", Modifier.padding(6.dp))
}
}
@Preview(showBackground = true)
@Composable
fun Decorated() {
Row(modifier = Modifier
.fillMaxWidth()
.heightIn(min = 64.dp)
.padding(8.dp)
.border(1.dp, Color.LightGray, RoundedCornerShape(4.dp))
.padding(8.dp)
) {
Avatar(modifier = Modifier
.padding(4.dp)
.align(Alignment.CenterVertically)
)
Info(Modifier
.weight(1f)
.align(Alignment.CenterVertically)
)
FollowBtn(Modifier.align(Alignment.CenterVertically)
)
}
}
@Composable
fun Info(modifier: Modifier) {
Column(modifier = modifier) {
Text(
text = name,
color = Color.Black,
maxLines = 1,
style = TextStyle(
fontWeight = FontWeight.Bold,
fontSize = 16.sp,
letterSpacing = 0.15.sp
)
)
Text(
text = desc,
color = Color.Black.copy(alpha = 0.75f),
maxLines = 1,
style = TextStyle( // here
fontWeight = FontWeight.Normal,
fontSize = 14.sp,
letterSpacing = 0.25.sp
)
)
}
}
@Composable
fun Avatar(modifier: Modifier) {
Image(
modifier = modifier
.size(50.dp)
.clip(CircleShape)
.border(
shape = CircleShape,
border = BorderStroke(
width = 2.dp,
brush = Brush.linearGradient(
colors = listOf(blue, teal200, green200, orange),
start = Offset(0f, 0f),
end = Offset(100f, 100f)
)
)
)
.border(
shape = CircleShape,
border = BorderStroke(4.dp, SolidColor(Color.White))
),
bitmap = ImageBitmap.imageResource(id = R.drawable.miku),
contentDescription = null, // decorative
)
}
@Composable
fun FollowBtn(modifier: Modifier) {
val backgroundShape: Shape = RoundedCornerShape(4.dp)
Text(
text = "Follow",
style = typography.body1.copy(color = Color.White),
textAlign = TextAlign.Center,
modifier =
modifier
.width(80.dp)
.clickable(onClick = {})
.shadow(3.dp, shape = backgroundShape)
.clip(backgroundShape)
.background(
brush = Brush.verticalGradient(
colors = listOf(
Red500,
orange700,
),
startY = 0f,
endY = 80f
)
)
.padding(6.dp)
)
}
val purple = Color(0xFF833AB4)
val purple700 = Color(0xFF512DA8)
val purple200 = Color(0xFFBB86FC)
val purple500 = Color(0xFF6200EE)
val orange200 = Color(0xFFff7961)
val orange500 = Color(0xFFf44336)
val orange700 = Color(0xFFba000d)
val green200 = Color(0xffa5d6a7)
val green500 = Color(0xff4caf50)
val green700 = Color(0xff388e3c)
val teal200 = Color(0xff80deea)
val Red500 = Color(0xFFEE1D52)
val blue = Color(0xFF5851DB)
val orange = Color(0xFFF56040)
val yellow = Color(0xFFFCAF45)
val name = "Hatsune Miku"
val desc = "World is Mine 、メルト"