Remote Compose Storybook Русский GitHub

alignByBaseline

Two texts sharing one baseline.

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

Lines up texts of different sizes on the same baseline, the way typographers align them.

Good for

  • A large price next to a small currency label

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.RemoteRow
import androidx.compose.remote.creation.compose.layout.RemoteText
import androidx.compose.remote.creation.compose.modifier.RemoteModifier
import androidx.compose.remote.creation.compose.modifier.alignByBaseline
import androidx.compose.remote.creation.compose.modifier.background
import androidx.compose.remote.creation.compose.modifier.padding
import androidx.compose.remote.creation.compose.state.rc
import androidx.compose.remote.creation.compose.state.rdp
import androidx.compose.remote.creation.compose.state.rs
import androidx.compose.remote.creation.compose.state.rsp
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color

@Composable
@RemoteComposable
fun AlignByBaseline(smallSize: Int, largeSize: Int) {
    RemoteRow(RemoteModifier.background(Color(0xFFF1F3F4).rc).padding(8.rdp)) {
        // Children aligned by their first text baseline rather than by their top.
        RemoteText(
            "Small".rs,
            fontSize = smallSize.rsp,
            modifier = RemoteModifier.alignByBaseline(),
        )
        RemoteText(
            "Large".rs,
            fontSize = largeSize.rsp,
            modifier = RemoteModifier.alignByBaseline(),
        )
    }
}

API

creation.compose.modifier.alignByBaseline

RemoteModifier alignByBaseline(RemoteModifier)

Reference

More in Modifiers