Last active
May 24, 2021 12:17
-
-
Save marenovakovic/d1492125a6745fb8cb7468a63d8f53c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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