Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save marenovakovic/abeae9629213be02824bbcdfb2bea8e4 to your computer and use it in GitHub Desktop.

Select an option

Save marenovakovic/abeae9629213be02824bbcdfb2bea8e4 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.graphics.asImageBitmap
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import coil.ImageLoader
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import yourApp.rememberCoilTarget
import yourApp.rememberDefaultImageRequest
import yourApp.computeDominantTopSectionColor
import kotlinx.coroutines.launch
@Composable
fun ParallaxImage(
modifier: Modifier = Modifier,
url: String,
) {
val coroutineScope = rememberCoroutineScope()
val systemUiController = rememberSystemUiController()
var image by remember { mutableStateOf(ImageBitmap(1, 1)) }
val loader = ImageLoader(LocalContext.current)
val target = rememberCoilTarget { bitmap ->
image = bitmap.asImageBitmap()
coroutineScope.launch {
val (color, isLight) = bitmap
.computeDominantTopSectionColor()
systemUiController.setStatusBarColor(color, isLight)
}
}
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