11package com.prography.android.test.hyunjung.ui.component
22
3+ import androidx.compose.foundation.background
34import androidx.compose.foundation.clickable
4- import androidx.compose.foundation.layout.Column
5+ import androidx.compose.foundation.layout.Box
56import androidx.compose.foundation.layout.fillMaxWidth
67import androidx.compose.foundation.layout.height
78import androidx.compose.foundation.layout.padding
89import androidx.compose.foundation.shape.RoundedCornerShape
910import androidx.compose.material3.Card
11+ import androidx.compose.material3.Text
1012import androidx.compose.runtime.Composable
13+ import androidx.compose.ui.Alignment
1114import androidx.compose.ui.Modifier
1215import androidx.compose.ui.draw.clip
16+ import androidx.compose.ui.geometry.Offset
17+ import androidx.compose.ui.graphics.Brush
18+ import androidx.compose.ui.graphics.Color.Companion.Transparent
19+ import androidx.compose.ui.graphics.Shadow
1320import androidx.compose.ui.layout.ContentScale
14- import androidx.compose.ui.tooling.preview.Preview
21+ import androidx.compose.ui.text.font.FontWeight
22+ import androidx.compose.ui.text.style.TextOverflow
1523import androidx.compose.ui.unit.dp
24+ import androidx.compose.ui.unit.sp
1625import coil3.compose.AsyncImage
1726import com.prography.android.test.hyunjung.data.model.Photo
27+ import com.prography.android.test.hyunjung.ui.theme.Black
28+ import com.prography.android.test.hyunjung.ui.theme.Typography
29+ import com.prography.android.test.hyunjung.ui.theme.White
1830
1931@Composable
20- fun ImageItem (photo : Photo , onClick : () -> Unit ) {
32+ fun ImageItem (
33+ photo : Photo ,
34+ onClick : () -> Unit ,
35+ showOverlay : Boolean = false
36+ ) {
2137 Card (
2238 modifier = Modifier
2339 .padding(5 .dp)
2440 .fillMaxWidth()
2541 .clickable { onClick() },
2642 shape = RoundedCornerShape (10 .dp),
2743 ) {
28- Column {
29- AsyncImage (
30- model = photo.urls.regular,
31- contentDescription = null ,
32- modifier = Modifier
33- .height(150 .dp)
34- .fillMaxWidth()
35- .clip(RoundedCornerShape (10 .dp)),
36- contentScale = ContentScale .Crop
37- )
44+ Box {
45+ if (showOverlay) {
46+ AsyncImage (
47+ model = photo.urls.regular,
48+ contentDescription = null ,
49+ modifier = Modifier
50+ .clip(RoundedCornerShape (10 .dp)),
51+ contentScale = ContentScale .Crop
52+ )
53+
54+ Box (
55+ modifier = Modifier
56+ .fillMaxWidth()
57+ .align(Alignment .BottomStart )
58+ .background(
59+ Brush .verticalGradient(
60+ colors = listOf (Transparent , Black .copy(alpha = 0.3f )),
61+ startY = 100f
62+ )
63+ )
64+ ) {
65+ Text (
66+ text = " titletitletitle\n " +
67+ " 타이틀은최대2줄까지" ,
68+ modifier = Modifier
69+ .align(Alignment .BottomStart )
70+ .padding(top = 12 .dp, bottom = 8 .dp, start = 8 .dp, end = 8 .dp),
71+ style = Typography .labelSmall.copy(
72+ shadow = Shadow (
73+ color = Black .copy(alpha = 0.25f ),
74+ offset = Offset (0f , 2f ),
75+ blurRadius = 4f
76+ )
77+ ),
78+ maxLines = 2 ,
79+ color = White ,
80+ fontSize = 13 .sp,
81+ fontWeight = FontWeight .Bold ,
82+ overflow = TextOverflow .Ellipsis
83+ )
84+ }
85+ } else {
86+ AsyncImage (
87+ model = photo.urls.regular,
88+ contentDescription = null ,
89+ modifier = Modifier
90+ .height(128 .dp)
91+ .clip(RoundedCornerShape (10 .dp)),
92+ contentScale = ContentScale .Crop
93+ )
94+ }
3895 }
3996 }
40- }
41-
42- @Preview
43- @Composable
44- private fun ImageItemPreview () {
4597}
0 commit comments