Remote Compose Storybook Русский GitHub

rememberNamedRemote* · Mutable image

A mutable bitmap declared by the document.

rememberNamedRemote* · Mutable image: 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

Values with a name, such as a title or a colour, that the app showing the screen can change later without the server sending a new design.

Good for

  • Live scores and prices
  • Personalised greetings
  • Theme colours chosen by the app

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.RemoteImage
import androidx.compose.remote.creation.compose.modifier.RemoteModifier
import androidx.compose.remote.creation.compose.modifier.size
import androidx.compose.remote.creation.compose.state.MutableRemoteImageBitmap
import androidx.compose.remote.creation.compose.state.rdp
import androidx.compose.remote.creation.compose.state.rememberMutableRemoteImageBitmap
import androidx.compose.remote.creation.compose.state.rs
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Canvas
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.Paint

fun solidBitmap(color: Color): ImageBitmap {
    val bitmap = ImageBitmap(32, 32)
    Canvas(bitmap).drawRect(0f, 0f, 32f, 32f, Paint().apply { this.color = color })
    return bitmap
}

@Composable
@RemoteComposable
fun MutableImage(swap: Boolean) {
    // A mutable bitmap: the document declares an image that can be replaced while it plays.
    val image: MutableRemoteImageBitmap =
        rememberMutableRemoteImageBitmap(
            solidBitmap(if (swap) Color(0xFFE53935) else Color(0xFF1E88E5)),
        )
    RemoteImage(image, "current".rs, RemoteModifier.size(100.rdp))
}

API

creation.compose.state.rememberNamedRemoteString

RemoteString rememberNamedRemoteString(String name, String defaultValue, optional RemoteState.Domain domain)

creation.compose.state.rememberNamedRemoteFloat

RemoteFloat rememberNamedRemoteFloat(String name, RemoteFloat defaultValue, optional RemoteState.Domain domain)

creation.compose.state.rememberNamedRemoteColor

RemoteColor rememberNamedRemoteColor(String name, RemoteColor defaultValue, optional RemoteState.Domain domain)

creation.compose.state.rememberNamedRemoteBoolean

RemoteBoolean rememberNamedRemoteBoolean(String name, boolean initialValue, optional RemoteState.Domain domain)

creation.compose.state.rememberNamedRemoteInt

RemoteInt rememberNamedRemoteInt(String name, int defaultValue, optional RemoteState.Domain domain)

creation.compose.state.rememberNamedRemoteEnum

inline <reified T extends java.lang.Enum<T>> RemoteEnum<T> rememberNamedRemoteEnum(String name, T initialValue, optional RemoteState.Domain domain)
<T extends java.lang.Enum<T>> RemoteEnum<T> rememberNamedRemoteEnum(String name, T initialValue, enums.EnumEntries<T> enumEntries, optional RemoteState.Domain domain)

Reference

Other stories of this component

More in State & expressions