Remote Compose Storybook Русский GitHub

drawWithContent

A circle drawn before or after drawContent().

drawWithContent: 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

Draws extra decoration behind or on top of any component, without changing the component itself.

Good for

  • Highlight rings and glows
  • Overlays such as badges or scrims

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.RemoteAlignment
import androidx.compose.remote.creation.compose.layout.RemoteBox
import androidx.compose.remote.creation.compose.layout.RemoteComposable
import androidx.compose.remote.creation.compose.layout.RemoteText
import androidx.compose.remote.creation.compose.modifier.RemoteModifier
import androidx.compose.remote.creation.compose.modifier.background
import androidx.compose.remote.creation.compose.modifier.drawWithContent
import androidx.compose.remote.creation.compose.modifier.size
import androidx.compose.remote.creation.compose.state.RemotePaint
import androidx.compose.remote.creation.compose.state.rc
import androidx.compose.remote.creation.compose.state.rdp
import androidx.compose.remote.creation.compose.state.rf
import androidx.compose.remote.creation.compose.state.rs
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color

@Composable
@RemoteComposable
fun DrawWithContent(ringColor: Color, ringScale: Float, behind: Boolean) {
    RemoteBox(
        modifier =
            RemoteModifier.size(200.rdp).drawWithContent {
                val ring = RemotePaint { color = ringColor.rc }
                if (behind) {
                    drawCircle(ring, radius = width * (ringScale / 2f).rf, center = center)
                    drawContent()
                } else {
                    drawContent()
                    drawCircle(ring, radius = width * (ringScale / 2f).rf, center = center)
                }
            },
        contentAlignment = RemoteAlignment.Center,
    ) {
        RemoteBox(
            RemoteModifier.size(100.rdp).background(Color(0xFF263238).rc),
            contentAlignment = RemoteAlignment.Center,
        ) {
            RemoteText("content".rs, color = Color.White.rc)
        }
    }
}

API

creation.compose.modifier.drawWithContent

RemoteModifier drawWithContent(RemoteModifier, RemoteContentDrawScope.() -> Unit onDraw)

creation.compose.layout.RemoteContentDrawScope

class RemoteContentDrawScope extends RemoteDrawScope
  void drawContent()
  RemoteFloat height
  RemoteFloat width

Reference

More in Canvas