RemoteBox · Without content
RemoteBox(modifier) with no content lambda: a sized, painted rectangle.
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.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.height
import androidx.compose.remote.creation.compose.modifier.size
import androidx.compose.remote.creation.compose.modifier.width
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 EmptyBox(width: Int, height: Int, color: Color) {
// The content-less overload: a box that only draws its modifiers.
RemoteBox(RemoteModifier.size(width.rdp, height.rdp).background(color.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 TopStartcreation.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