Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Game Item composable
@Composable
fun GameItem(game: GameResultsEntity) {
Card(
elevation = 20.dp,
backgroundColor = Color.Black,
modifier =
Modifier.padding(16.dp)
.clip(RoundedCornerShape(10.dp))
.height(250.dp)
.fillMaxWidth()
) {
ConstraintLayout {
val (image, title, rating) = createRefs()
Image(
contentScale = ContentScale.Crop,
painter =
rememberImagePainter(
data = game.backgroundImage,
builder = {
placeholder(
R.drawable
.ic_esports_placeholder
)
crossfade(true)
}
),
contentDescription = "Image",
modifier =
Modifier.constrainAs(image) {
top.linkTo(parent.top)
start.linkTo(parent.start)
end.linkTo(parent.end)
}
.height(150.dp)
.fillMaxWidth()
)
Text(
text = game.name,
color = Color(0xFFF50057),
maxLines = 2,
fontSize = 20.sp,
fontWeight = FontWeight.Bold,
modifier =
Modifier.constrainAs(title) {
top.linkTo(image.bottom)
start.linkTo(parent.start)
end.linkTo(parent.end)
}
.fillMaxWidth()
.padding(8.dp)
)
Row(
modifier =
Modifier.fillMaxWidth().constrainAs(
rating
) {
bottom.linkTo(parent.bottom)
start.linkTo(parent.start)
end.linkTo(parent.end)
}
) {
Text(
text = game.rating.toString(),
color = Color(0xFFFFC400),
modifier = Modifier.padding(8.dp),
fontSize = 18.sp
)
Image(
contentScale = ContentScale.Crop,
painter =
painterResource(
id = R.drawable.ic_star
),
contentDescription = "Star",
modifier = Modifier.padding(top = 10.dp)
)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment