Skip to content

Commit 833bb61

Browse files
authored
Fix youtube (#105)
* fix YoutubeListItem layout * fix contentColor for YoutubeChip * wrap YoutubeContent with surface to align topBar and content color * tweak selected background color for light theme in YoutubeChip * tweak color for YoutubeChip * tweak padding for Youtube chip and home * tweak elevation for appbar according to theme * tweak content elevation to align it with appBar
1 parent 968d486 commit 833bb61

File tree

3 files changed

+38
-19
lines changed

3 files changed

+38
-19
lines changed

demos/youtube/src/main/java/com/guru/composecookbook/youtube/components/YoutubeChip.kt

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,23 @@ import androidx.compose.ui.unit.dp
1616
fun YoutubeChip(selected: Boolean, text: String, modifier: Modifier = Modifier) {
1717
Surface(
1818
color = when {
19-
selected -> MaterialTheme.colors.onSurface
20-
else -> Color.Transparent
19+
selected -> MaterialTheme.colors.onSurface.copy(
20+
alpha = if (MaterialTheme.colors.isLight) 0.7f else 1f
21+
)
22+
else -> MaterialTheme.colors.onSurface.copy(
23+
alpha = if (MaterialTheme.colors.isLight) 0.04f else 0.07f
24+
)
2125
},
2226
contentColor = when {
23-
selected -> MaterialTheme.colors.onPrimary
24-
else -> Color.LightGray
27+
selected -> MaterialTheme.colors.surface
28+
else -> MaterialTheme.colors.onSurface
2529
},
2630
shape = CircleShape,
2731
border = BorderStroke(
2832
width = 1.dp,
2933
color = when {
30-
selected -> MaterialTheme.colors.primary
31-
else -> Color.LightGray
34+
selected -> MaterialTheme.colors.surface
35+
else -> if (MaterialTheme.colors.isLight) Color.LightGray else Color.DarkGray
3236
}
3337
),
3438
modifier = modifier
@@ -37,8 +41,10 @@ fun YoutubeChip(selected: Boolean, text: String, modifier: Modifier = Modifier)
3741
text = text,
3842
textAlign = TextAlign.Center,
3943
style = MaterialTheme.typography.body2,
40-
modifier = Modifier.padding(8.dp)
44+
modifier = Modifier.padding(
45+
vertical = 8.dp,
46+
horizontal = 12.dp,
47+
)
4148
)
42-
4349
}
4450
}

demos/youtube/src/main/java/com/guru/composecookbook/youtube/components/YoutubeHome.kt

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.guru.composecookbook.youtube.components
22

33
import androidx.compose.foundation.Image
44
import androidx.compose.foundation.layout.Column
5+
import androidx.compose.foundation.layout.PaddingValues
56
import androidx.compose.foundation.layout.padding
67
import androidx.compose.foundation.layout.size
78
import androidx.compose.foundation.lazy.LazyColumn
@@ -30,7 +31,7 @@ fun YoutubeHome() {
3031
title = { Text(text = "Youtube") },
3132
backgroundColor = MaterialTheme.colors.surface,
3233
contentColor = MaterialTheme.colors.onSurface,
33-
elevation = 8.dp,
34+
elevation = if (MaterialTheme.colors.isLight) 0.dp else 8.dp,
3435
navigationIcon = {
3536
Icon(
3637
painter = painterResource(id = R.drawable.ic_youtube),
@@ -62,7 +63,11 @@ fun YoutubeHome() {
6263
)
6364
},
6465
content = {
65-
YoutubeContent()
66+
Surface(
67+
elevation = if (MaterialTheme.colors.isLight) 0.dp else 8.dp,
68+
) {
69+
YoutubeContent()
70+
}
6671
}
6772
)
6873
}
@@ -73,23 +78,29 @@ fun YoutubeContent() {
7378
// There is performance issue when using LazyRowFor and LazyColumnFor inside scrollableColumn
7479
// So using column for now.
7580
Column {
81+
Divider()
7682
LazyRow(
77-
modifier = Modifier.padding(vertical = 8.dp)
83+
modifier = Modifier.padding(vertical = 8.dp),
84+
contentPadding = PaddingValues(horizontal = 12.dp),
7885
) {
7986
items(
8087
items = tweets,
8188
itemContent = {
8289
YoutubeChip(
8390
selected = it.id == 2,
8491
text = it.author,
85-
modifier = Modifier.padding(8.dp)
92+
modifier = Modifier.padding(
93+
horizontal = 4.dp,
94+
)
8695
)
87-
})
96+
}
97+
)
8898
}
8999
LazyColumn {
90100
items(
91101
items = tweets,
92-
itemContent = { item -> YoutubeListItem(item) })
102+
itemContent = { item -> YoutubeListItem(item) }
103+
)
93104
}
94105
}
95106
}

demos/youtube/src/main/java/com/guru/composecookbook/youtube/components/YoutubeListItem.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import androidx.compose.ui.draw.clip
1919
import androidx.compose.ui.graphics.Color
2020
import androidx.compose.ui.layout.ContentScale
2121
import androidx.compose.ui.res.painterResource
22+
import androidx.compose.ui.text.style.TextOverflow
2223
import androidx.compose.ui.tooling.preview.Preview
2324
import androidx.compose.ui.unit.dp
2425
import androidx.compose.ui.unit.sp
25-
import androidx.constraintlayout.compose.ChainStyle
2626
import androidx.constraintlayout.compose.ConstraintLayout
2727
import androidx.constraintlayout.compose.Dimension
2828
import com.guru.composecookbook.data.DemoDataProvider
@@ -37,7 +37,7 @@ fun YoutubeListItem(item: Tweet) {
3737
.clickable { }
3838
) {
3939
val (image, authorImage, title, subtitle, button) = createRefs()
40-
createVerticalChain(title, subtitle, chainStyle = ChainStyle.Packed)
40+
4141
Image(
4242
painter = painterResource(id = item.tweetImageId),
4343
contentDescription = null,
@@ -67,6 +67,8 @@ fun YoutubeListItem(item: Tweet) {
6767
Text(
6868
text = item.text,
6969
style = MaterialTheme.typography.h6.copy(fontSize = 14.sp),
70+
maxLines = 2,
71+
overflow = TextOverflow.Ellipsis,
7072
modifier = Modifier.constrainAs(title) {
7173
linkTo(
7274
start = authorImage.end,
@@ -75,8 +77,7 @@ fun YoutubeListItem(item: Tweet) {
7577
endMargin = 16.dp
7678
)
7779
linkTo(
78-
top = image.bottom,
79-
topMargin = 8.dp,
80+
top = authorImage.top,
8081
bottom = subtitle.top
8182
)
8283
width = Dimension.fillToConstraints
@@ -87,10 +88,11 @@ fun YoutubeListItem(item: Tweet) {
8788
style = MaterialTheme.typography.subtitle2,
8889
modifier = Modifier
8990
.constrainAs(subtitle) {
91+
bottom.linkTo(parent.bottom)
9092
start.linkTo(title.start)
9193
width = Dimension.fillToConstraints
9294
}
93-
.padding(bottom = 16.dp)
95+
.padding(bottom = 24.dp)
9496
)
9597
IconButton(
9698
onClick = { },

0 commit comments

Comments
 (0)