RemoteFitBox

Functions summary

Unit
@RemoteComposable
@Composable
RemoteFitBox(
    modifier: RemoteModifier,
    horizontalAlignment: RemoteAlignment.Horizontal,
    verticalArrangement: RemoteArrangement.Vertical,
    content: @RemoteComposable @Composable () -> Unit
)

Layout container that renders the first child that fits within available constraints.

Functions

@RemoteComposable
@Composable
fun RemoteFitBox(
    modifier: RemoteModifier = RemoteModifier,
    horizontalAlignment: RemoteAlignment.Horizontal = RemoteAlignment.CenterHorizontally,
    verticalArrangement: RemoteArrangement.Vertical = RemoteArrangement.Center,
    content: @RemoteComposable @Composable () -> Unit = {}
): Unit

Layout container that renders the first child that fits within available constraints.

Functions as a RemoteBox and acts as an alternative-selector container during playback.

Selection behavior:

  • Measures children sequentially and renders only the first child whose width and height fit within available constraints.

  • Matches container dimensions to the measured size of the selected child.

  • Hides completely (GONE) if no child fits within the constraints.

import androidx.compose.remote.creation.compose.layout.RemoteAlignment
import androidx.compose.remote.creation.compose.layout.RemoteArrangement
import androidx.compose.remote.creation.compose.layout.RemoteBox
import androidx.compose.remote.creation.compose.layout.RemoteFitBox
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.rc
import androidx.compose.remote.creation.compose.state.rdp
import androidx.compose.ui.graphics.Color

// The parent RemoteBox constrains the available space to 40.rdp.
// RemoteFitBox will measure its children against these constraints.
// Child 1 (50.rdp) is too large to fit, so the RemoteFitBox skips it and selects
// Child 2 (30.rdp) which fits within the 40.rdp constraints.
RemoteBox(modifier = RemoteModifier.size(40.rdp).background(Color.LightGray.rc)) {
    RemoteFitBox(
        horizontalAlignment = RemoteAlignment.CenterHorizontally,
        verticalArrangement = RemoteArrangement.Center,
    ) {
        // Child 1: Too large for 40.rdp container
        RemoteBox(RemoteModifier.size(50.rdp).background(Color.Red.rc))

        // Child 2: Fits in 40.rdp container and will be rendered
        RemoteBox(RemoteModifier.size(30.rdp).background(Color.Blue.rc))
    }
}
Parameters
modifier: RemoteModifier = RemoteModifier

modifier applied to this layout

horizontalAlignment: RemoteAlignment.Horizontal = RemoteAlignment.CenterHorizontally

horizontal alignment for children

verticalArrangement: RemoteArrangement.Vertical = RemoteArrangement.Center

vertical arrangement for children

content: @RemoteComposable @Composable () -> Unit = {}

composable children to lay out inside this RemoteFitBox