AutoSizeText for Compose Multiplatform
Text composable that can adjust font size depending on available space.
Get the latest version from Maven Central:
implementation("com.dshatz.compose-mpp:autosize-text:<version>")
implementation 'com.dshatz.compose-mpp:autosize-text:<version>'
@Composable
fun AutoSizeText(
text: String,
modifier: Modifier = Modifier,
suggestedFontSizes: ImmutableWrapper<List<TextUnit>> = emptyList<TextUnit>().toImmutableWrapper(),
minTextSize: TextUnit = TextUnit.Unspecified,
maxTextSize: TextUnit = TextUnit.Unspecified,
stepGranularityTextSize: TextUnit = TextUnit.Unspecified,
alignment: Alignment = Alignment.TopStart,
color: Color = Color.Unspecified,
fontStyle: FontStyle? = null,
fontWeight: FontWeight? = null,
fontFamily: FontFamily? = null,
letterSpacing: TextUnit = TextUnit.Unspecified,
textDecoration: TextDecoration? = null,
lineSpacingRatio: Float = 0.1F,
maxLines: Int = Int.MAX_VALUE,
onTextLayout: (TextLayoutResult) -> Unit = {},
style: TextStyle = LocalTextStyle.current
) { }
Box {
AutoSizeText(
text = "Hello world!",
minTextSize = 10.sp,
maxTextSize = 20.sp
)
}