TextMotion

  • Common/All
  • Android/JVM

Defines ways to render and place glyphs to provide readability and smooth animations for text.

import androidx.compose.animation.core.RepeatMode
import androidx.compose.animation.core.animateFloat
import androidx.compose.animation.core.infiniteRepeatable
import androidx.compose.animation.core.rememberInfiniteTransition
import androidx.compose.animation.core.tween
import androidx.compose.material.LocalTextStyle
import androidx.compose.material.Text
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.TransformOrigin
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.text.style.TextMotion

val infiniteTransition = rememberInfiniteTransition()
val scale by
    infiniteTransition.animateFloat(
        initialValue = 1f,
        targetValue = 8f,
        animationSpec = infiniteRepeatable(tween(1000), RepeatMode.Reverse)
    )

Text(
    text = "Hello",
    modifier =
        Modifier.graphicsLayer {
            scaleX = scale
            scaleY = scale
            transformOrigin = TransformOrigin.Center
        },
    // Text composable does not take TextMotion as a parameter.
    // Provide it via style argument but make sure that we are copying from current theme
    style = LocalTextStyle.current.copy(textMotion = TextMotion.Animated)
)

Summary

Public companion properties

TextMotion

Text is rendered for maximum linearity which provides smooth animations for text.

Cmn
android
TextMotion

Optimizes glyph shaping, placement, and overall rendering for maximum readability.

Cmn
android

Public functions

open operator Boolean
equals(other: Any?)
android
open Int
android
open String
android

Public companion properties

Animated

val AnimatedTextMotion

Text is rendered for maximum linearity which provides smooth animations for text. Trade-off is the readability of the text on some low DPI devices, which still should not be a major concern. Use this TextMotion if you are planning to scale, translate, or rotate text.

Static

val StaticTextMotion

Optimizes glyph shaping, placement, and overall rendering for maximum readability. Intended for text that is not animated. This is the default TextMotion.

Public functions

equals

open operator fun equals(other: Any?): Boolean

hashCode

open fun hashCode(): Int

toString

open fun toString(): String