Skip to content

dshatz/autosizetext-mpp-compose

Repository files navigation

License Build Multiplatform project Publish Wiki

AutoSizeText for Compose Multiplatform

Text composable that can adjust font size depending on available space.

Installation

Get the latest version from Maven Central: Maven Central

build.gradle.kts

implementation("com.dshatz.compose-mpp:autosize-text:<version>")

build.gradle

implementation 'com.dshatz.compose-mpp:autosize-text:<version>'

Usage

@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
    )
}