TextMotion
Defines ways to render and place glyphs to provide readability and smooth animations for text.
TextMotion
Class
Common
expect class TextMotion
Defines ways to render and place glyphs to provide readability and smooth animations for text.
Companion Object
Properties
Common
val Static: TextMotion
Optimizes glyph shaping, placement, and overall rendering for maximum readability.
Intended for text that is not animated. This is the default TextMotion.
Common
val Animated: TextMotion
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.
Android
actual class TextMotion
internal constructor(
internal val linearity: Linearity,
internal val subpixelTextPositioning: Boolean,
)
Implementation of possible TextMotion configurations on Android.
Companion Object
Properties
Android
actual val Static: TextMotion
Android
actual val Animated: TextMotion
Code Examples
TextMotionSample
/**
* This sample demonstrates how to define TextMotion on a Text composable that scales up and down
* repeatedly.
*/
@Composable
fun TextMotionSample() {
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),
)
}
