Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save marenovakovic/d1492125a6745fb8cb7468a63d8f53c6 to your computer and use it in GitHub Desktop.
Save marenovakovic/d1492125a6745fb8cb7468a63d8f53c6 to your computer and use it in GitHub Desktop.
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import coil.ImageLoader
import yourApp.rememberCoilTarget
import yourApp.rememberDefaultImageRequest
import yourApp.computeDominantTopSectionColor
@Composable
fun ParallaxImage(
modifier: Modifier = Modifier,
url: String,
) {
var image by remember { mutableStateOf(ImageBitmap(1, 1)) }
val loader = ImageLoader(LocalContext.current)
val target = rememberCoilTarget { bitmap -> image = bitmap.asImageBitmap() }
val request = rememberDefaultImageRequest(url = url, target = target)
LaunchedEffect(url) {
loader.execute(request)
}
Image(
modifier = modifier
.height(250.dp)
.fillMaxWidth(),
bitmap = image,
contentScale = ContentScale.FillWidth,
contentDescription = null,
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment