AnimatedContent

fun <T> AnimatedContent(targetState: T, modifier: Modifier = Modifier, transitionSpec: AnimatedContentTransitionScope<T>.() -> ContentTransform = { fadeIn() togetherWith fadeOut() }, contentAlignment: Alignment = Alignment.Center, label: String = "TextFieldScopeAnimatedContent", contentKey: (targetState: T) -> Any? = { it }, content: @Composable TextFieldScope.(targetState: T) -> Unit)

Animated wrapper for the TextField trailing slot. Renders one of the TextFieldScope elements (Icon / Text) per targetState with a smooth transition.

The content lambda is invoked with TextFieldScope as its receiver, so callers naturally use the scope's elements (Icon(...), Text(...)). Children may be omitted entirely (e.g. an if without an else branch); empty states are valid and will simply render nothing for that target.

Parameters

targetState

The state value driving the transition. When it changes, content is recomposed for the new state and the transition runs from the previous state.

modifier

The Modifier to be applied to the wrapper. The required layoutId for the trailing slot is appended internally.

transitionSpec

Describes the enter / exit animation between adjacent target states. Defaults to a simple cross-fade.

contentAlignment

Alignment of the content within the wrapper while incoming and outgoing children overlap during the transition. Defaults to Alignment.Center.

label

Diagnostic label forwarded to the underlying androidx.compose.animation.AnimatedContent; appears in animation tooling.

contentKey

Optional key derivation function used to decide whether a transition should run. When targetState changes, the new and previous keys are compared; a transition runs only if they differ. Defaults to { it }, mirroring androidx.compose.animation.AnimatedContent and keying on targetState itself. Override when targetState is a complex type and only a subset of its fields should drive transitions (e.g. contentKey = { it.id }).

content

Composable lambda invoked with the current targetState. Only TextFieldScope.Icon / TextFieldScope.Text are accepted; any other content fails validation at runtime.