RemoteBasicText
RemoteBasicText with a size, colour and style.
Open the live, interactive demo →
Change its controls, read the remote document it produces and the diff after every change.
What it is
The simplest piece of text, with no built-in styling: the building block that richer text is made from.
Good for
- Fully custom text styles
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.state.rc
import androidx.compose.remote.creation.compose.state.rs
import androidx.compose.remote.creation.compose.state.rsp
import androidx.compose.remote.creation.compose.text.RemoteFontStyle
import androidx.compose.remote.foundation.text.RemoteBasicText
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
@Composable
@RemoteComposable
fun BasicText(text: String, fontSize: Int, color: Color, italic: Boolean) {
// RemoteBasicText (foundation) is the unstyled text primitive the higher-level texts build on.
RemoteBasicText(
text = text.rs,
color = color.rc,
fontSize = fontSize.rsp,
fontStyle = if (italic) RemoteFontStyle.Italic else RemoteFontStyle.Normal,
)
}
API
foundation.text.RemoteBasicText
void RemoteBasicText(RemoteString text, optional RemoteModifier modifier, optional RemoteColor? color, optional RemoteTextUnit? fontSize, optional RemoteFontStyle? fontStyle, optional RemoteFontWeight? fontWeight, optional RemoteFontFamily? fontFamily, optional RemoteTextAlign? textAlign, optional RemoteTextOverflow overflow, optional int maxLines, optional RemoteFontVariation.Settings? fontVariationSettings, optional RemoteTextStyle style)