Skip to content

Instantly share code, notes, and snippets.

@bleszerd
Created September 27, 2021 22:28
Show Gist options
  • Save bleszerd/e11468371cd1bee2d29d6cd6bf76ed2a to your computer and use it in GitHub Desktop.
Save bleszerd/e11468371cd1bee2d29d6cd6bf76ed2a to your computer and use it in GitHub Desktop.
PokemonListScreen
@ExperimentalCoilApi
@Composable
fun PokedexEntry(
entry: PokedexListEntry,
navController: NavController,
modifier: Modifier = Modifier,
viewModel: PokemonListViewModel = hiltViewModel()
) {
val defaultDominantColor = MaterialTheme.colors.surface.toArgb()
var dominantColor by rememberSaveable {
mutableStateOf(defaultDominantColor)
}
Box(
contentAlignment = Center,
modifier = modifier
.shadow(5.dp, RoundedCornerShape(10.dp))
.clip(RoundedCornerShape(10.dp))
.aspectRatio(1f)
.background(
Brush.verticalGradient(
listOf(
Color(dominantColor),
Color(defaultDominantColor),
)
)
)
.clickable {
navController.navigate(
"pokemon_detail_screen/${dominantColor}/${entry.pokemonName}"
)
}
) {
Column {
Image(
painter = rememberImagePainter(
data = entry.imageUrl,
builder = {
crossfade(true)
transformations(
object : Transformation {
override fun key(): String {
return entry.imageUrl
}
override suspend fun transform(
pool: BitmapPool,
input: Bitmap,
size: coil.size.Size
): Bitmap {
viewModel.calcDominantColor(input) { color ->
dominantColor = color.toArgb()
}
return input
}
}
)
}
),
contentDescription = entry.pokemonName,
modifier = Modifier
.size(120.dp)
.align(CenterHorizontally),
)
Text(
text = entry.pokemonName,
fontFamily = RobotoCondensed,
fontSize = 20.sp,
textAlign = TextAlign.Center,
modifier = Modifier
.fillMaxWidth()
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment