package com.suno.android.omniplayer import androidx.compose.animation.AnimatedVisibility import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.BoxScope import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.alpha import androidx.compose.ui.draw.drawWithCache import androidx.compose.ui.graphics.BlendMode import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.res.painterResource import com.suno.android.common_ui.R @Composable fun BoxScope.GradientCover( dominantColor: Color?, ) { // Top Gradient Box( modifier = Modifier .fillMaxWidth() .fillMaxHeight(0.20f) .align(Alignment.TopCenter) .background( Brush.verticalGradient( listOf( Color(0x77000000), Color(0x00000000), ), ), ), ) // Add the bottom gradient overlay if we have a valid dominant color val bottomDominantColorGradient = dominantColor?.let { nonNullColor -> Brush.verticalGradient( colors = listOf( Color.Transparent, nonNullColor.copy(alpha = 0.99f), nonNullColor, ), ) } ?: Brush.verticalGradient( // to help with rendering the preview listOf( Color.Transparent, Color.Transparent, ), ) AnimatedVisibility( modifier = Modifier .fillMaxWidth() .fillMaxHeight(0.50f) // Cover bottom .background(bottomDominantColorGradient) .align(Alignment.BottomCenter), visible = dominantColor != null, ) { Box( modifier = Modifier .alpha(0.8f) .fillMaxWidth() .fillMaxHeight(0.7f) // Cover bottom .background(bottomDominantColorGradient) .align(Alignment.BottomCenter), ) { Image( modifier = Modifier .fillMaxWidth() .fillMaxHeight() .align(Alignment.BottomCenter) .drawWithCache { // theoretically this should apply the gradient to the image itself val gradient = Brush.verticalGradient( colors = listOf( Color.White.copy(alpha = 0.25f), Color.White, ), startY = 0f, endY = size.height, ) onDrawWithContent { drawContent() drawRect(brush = gradient, blendMode = BlendMode.DstIn) } }, alignment = Alignment.BottomCenter, painter = painterResource( id = R.drawable.noise_texture_png, ), contentDescription = null, contentScale = ContentScale.Crop, ) } } }