Remote Compose Storybook Русский GitHub

RemoteBasicImage

RemoteBasicImage with a content scale.

RemoteBasicImage: the document drawn by the Remote Compose player
Open the live, interactive demo →

Change its controls, read the remote document it produces and the diff after every change.

What it is

The simplest picture element, without extra behaviour.

Good for

  • Decorative images

Code

The story's source with androidx.compose.remote imports. CI compiles every snippet on this site against AndroidX.

import androidx.compose.remote.creation.compose.layout.RemoteComposable
import androidx.compose.remote.creation.compose.layout.RemoteContentScale
import androidx.compose.remote.creation.compose.modifier.RemoteModifier
import androidx.compose.remote.creation.compose.modifier.background
import androidx.compose.remote.creation.compose.modifier.size
import androidx.compose.remote.creation.compose.state.RemoteImageBitmap
import androidx.compose.remote.creation.compose.state.rc
import androidx.compose.remote.creation.compose.state.rdp
import androidx.compose.remote.creation.compose.state.rs
import androidx.compose.remote.foundation.image.RemoteBasicImage
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Canvas
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.Paint

@Composable
@RemoteComposable
fun BasicImage(contentScale: RemoteContentScale, size: Int) {
    val bitmap = remember {
        val image = ImageBitmap(120, 60)
        Canvas(image).apply {
            drawRect(0f, 0f, 120f, 60f, Paint().apply { color = Color(0xFF8E24AA) })
            drawCircle(Offset(60f, 30f), 20f, Paint().apply { color = Color(0xFFFFFFFF) })
        }
        RemoteImageBitmap(image)
    }
    RemoteBasicImage(
        bitmap = bitmap,
        contentDescription = "Foundation image".rs,
        modifier = RemoteModifier.size(size.rdp).background(Color(0xFFF1F3F4).rc),
        contentScale = contentScale,
    )
}

API

foundation.image.RemoteBasicImage

void RemoteBasicImage(RemoteImageBitmap bitmap, RemoteString? contentDescription, optional RemoteModifier modifier, optional RemoteContentScale contentScale, optional RemoteFloat alpha)

Reference

More in Content