Remote Compose Storybook Русский GitHub

RemoteBox · Layering

Later children draw on top of earlier ones.

RemoteBox · Layering: 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

A container that stacks things on top of each other, like layers in a design tool, and pins them to a corner, an edge or the centre.

Good for

  • A badge over an avatar
  • Text centred on a coloured card
  • A background shape behind content

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.modifier.RemoteModifier
import androidx.compose.remote.creation.compose.modifier.background
import androidx.compose.remote.creation.compose.modifier.padding
import androidx.compose.remote.creation.compose.modifier.size
import androidx.compose.remote.creation.compose.state.rc
import androidx.compose.remote.creation.compose.state.rdp
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color

@Composable
@RemoteComposable
fun BoxLayering(offsetStep: Int) {
    RemoteBox(
        modifier = RemoteModifier.size(220.rdp),
        contentAlignment = RemoteAlignment.TopStart,
    ) {
        RemoteBox(RemoteModifier.size(140.rdp).background(Color(0xFFEF5350).rc))
        RemoteBox(
            RemoteModifier.padding(start = offsetStep.rdp, top = offsetStep.rdp)
                .size(140.rdp)
                .background(Color(0xCC42A5F5).rc),
        )
        RemoteBox(
            RemoteModifier.padding(start = (offsetStep * 2).rdp, top = (offsetStep * 2).rdp)
                .size(140.rdp)
                .background(Color(0xAA66BB6A).rc),
        )
    }
}

API

creation.compose.layout.RemoteBox

void RemoteBox(optional RemoteModifier modifier)
void RemoteBox(optional RemoteModifier modifier, optional RemoteAlignment contentAlignment, () -> Unit content)

creation.compose.layout.RemoteAlignment

interface RemoteAlignment
  RemoteAlignment.Companion Companion
  RemoteAlignment.Vertical Bottom
  RemoteAlignment BottomCenter
  RemoteAlignment BottomEnd
  RemoteAlignment BottomStart
  RemoteAlignment Center
  RemoteAlignment CenterEnd
  RemoteAlignment.Horizontal CenterHorizontally
  RemoteAlignment CenterStart
  RemoteAlignment.Vertical CenterVertically
  RemoteAlignment.Horizontal End
  RemoteAlignment.Horizontal Start
  RemoteAlignment.Vertical Top
  RemoteAlignment TopCenter
  RemoteAlignment TopEnd
  RemoteAlignment TopStart

creation.compose.layout.RemoteAbsoluteAlignment

class RemoteAbsoluteAlignment
  RemoteAlignment BottomLeft
  RemoteAlignment BottomRight
  RemoteAlignment CenterLeft
  RemoteAlignment CenterRight
  RemoteAlignment.Horizontal Left
  RemoteAlignment.Horizontal Right
  RemoteAlignment TopLeft
  RemoteAlignment TopRight
  RemoteAbsoluteAlignment INSTANCE

Reference

Other stories of this component

More in Layout