Thread
#compose
    t

    trickybits

    1 year ago
    This is the only way I could figure out how to tile a background image loaded by Coil. 🤔 Any thoughts on making this better/more correct?
    var tiledBackgroundImageShader by remember { mutableStateOf<ShaderBrush?>(null) }
        val imageLoader = LocalImageLoader.current
        val localContext = LocalContext.current
        LaunchedEffect(backgroundImageSrc) {
            val builder = ImageRequest.Builder(localContext).data(backgroundImageSrc)
            val result = imageLoader.execute(builder.build()).drawable?.toBitmap()
            if (result != null) {
                val shader = ImageShader(result.asImageBitmap(), tileModeX = TileMode.Repeated, tileModeY = TileMode.Repeated)
                tiledBackgroundImageShader = ShaderBrush(shader)
            }
        }
    and for the content:
    Box(
            modifier = Modifier
                .drawWithCache {
                    onDrawBehind {
                        drawRect(backgroundColor)
                        tiledBackgroundImageShader?.let { drawRect(it) }
                    }
                }
        ) {
    Colton Idle

    Colton Idle

    1 year ago
    I'd ask on the coil github page under the "discussions" tab. The maintainer has always responded to me there!
    t

    trickybits

    1 year ago
    Thanks I’ll try that