Remote Compose Storybook English GitHub

RemoteBasicImage

RemoteBasicImage with a content scale.

RemoteBasicImage: документ, нарисованный плеером Remote Compose
Открыть живое интерактивное демо →

Меняйте параметры, смотрите удалённый документ, который получается, и разницу после каждого изменения.

Что это

Самый простой элемент-картинка без дополнительного поведения.

Подходит для

  • Декоративные изображения

Код

Исходник примера с импортами androidx.compose.remote. CI компилирует каждый фрагмент кода на сайте против 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)

Справочник

Ещё в разделе «Контент»