{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

EnterExitState

@ExperimentalAnimationApi
public enum EnterExitState extends Enum

java.lang.Object
   ↳ kotlin.Enum
     ↳ androidx.compose.animation.EnterExitState

EnterExitState contains the three states that are involved in the enter and exit transition of AnimatedVisibility. More specifically, PreEnter and Visible defines the initial and target state of an enter transition, whereas Visible and PostExit are the initial and target state of an exit transition.

See blow for an example of custom enter/exit animation in AnimatedVisibility using Transition<EnterExitState> (i.e. AnimatedVisibilityScope.transition):

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.AnimatedVisibilityScope
import androidx.compose.animation.EnterExitState
import androidx.compose.animation.core.animateDp
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.scaleOut
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

var visible by remember { mutableStateOf(true) }
Box(modifier = Modifier.clickable { visible = !visible }) {
    AnimatedVisibility(
        visible = visible,
        modifier = Modifier.align(Alignment.Center),
        enter = fadeIn(),
        exit = fadeOut(animationSpec = tween(200)) + scaleOut()
    ) { // Content that needs to appear/disappear goes here:
        // Here we can optionally define a custom enter/exit animation by creating an animation
        // using the Transition<EnterExitState> object from AnimatedVisibilityScope:

        // As a part of the enter transition, the corner radius will be animated from 0.dp to 50.dp.
        val cornerRadius by transition.animateDp {
            when (it) {
                EnterExitState.PreEnter -> 0.dp
                EnterExitState.Visible -> 50.dp
                // No corner radius change when exiting.
                EnterExitState.PostExit -> 50.dp
            }
        }
        Box(
            Modifier.background(Color.Red, shape = RoundedCornerShape(cornerRadius))
                .height(100.dp).fillMaxWidth()
        )
    }
}
See also
AnimatedVisibility

Summary

Enum Values

PostExit

Target state of a custom exit animation in AnimatedVisibility.

PreEnter

The initial state of a custom enter animation in AnimatedVisibility..

Visible

The Visible state is the target state of a custom enter animation, also the initial state of a custom exit animation in AnimatedVisibility.

Public methods

final @NonNull EnumEntries<@NonNull EnterExitState>

EnterExitState contains the three states that are involved in the enter and exit transition of AnimatedVisibility.

final @NonNull EnterExitState

Returns the enum constant of this type with the specified name.

final @NonNull EnterExitState[]

Returns an array containing the constants of this enum type, in the order they're declared.

Enum Values

PostExit

@ExperimentalAnimationApi
EnterExitState EnterExitState.PostExit

Target state of a custom exit animation in AnimatedVisibility.

PreEnter

@ExperimentalAnimationApi
EnterExitState EnterExitState.PreEnter

The initial state of a custom enter animation in AnimatedVisibility..

Visible

@ExperimentalAnimationApi
EnterExitState EnterExitState.Visible

The Visible state is the target state of a custom enter animation, also the initial state of a custom exit animation in AnimatedVisibility.

Public methods

getEntries

public final @NonNull EnumEntries<@NonNull EnterExitStategetEntries()

EnterExitState contains the three states that are involved in the enter and exit transition of AnimatedVisibility. More specifically, PreEnter and Visible defines the initial and target state of an enter transition, whereas Visible and PostExit are the initial and target state of an exit transition.

See blow for an example of custom enter/exit animation in AnimatedVisibility using Transition<EnterExitState> (i.e. AnimatedVisibilityScope.transition):

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.AnimatedVisibilityScope
import androidx.compose.animation.EnterExitState
import androidx.compose.animation.core.animateDp
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.scaleOut
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

var visible by remember { mutableStateOf(true) }
Box(modifier = Modifier.clickable { visible = !visible }) {
    AnimatedVisibility(
        visible = visible,
        modifier = Modifier.align(Alignment.Center),
        enter = fadeIn(),
        exit = fadeOut(animationSpec = tween(200)) + scaleOut()
    ) { // Content that needs to appear/disappear goes here:
        // Here we can optionally define a custom enter/exit animation by creating an animation
        // using the Transition<EnterExitState> object from AnimatedVisibilityScope:

        // As a part of the enter transition, the corner radius will be animated from 0.dp to 50.dp.
        val cornerRadius by transition.animateDp {
            when (it) {
                EnterExitState.PreEnter -> 0.dp
                EnterExitState.Visible -> 50.dp
                // No corner radius change when exiting.
                EnterExitState.PostExit -> 50.dp
            }
        }
        Box(
            Modifier.background(Color.Red, shape = RoundedCornerShape(cornerRadius))
                .height(100.dp).fillMaxWidth()
        )
    }
}

valueOf

public final @NonNull EnterExitState valueOf(@NonNull String value)

Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

Throws
kotlin.IllegalArgumentException

if this enum type has no constant with the specified name

values

public final @NonNull EnterExitState[] values()

Returns an array containing the constants of this enum type, in the order they're declared.

This method may be used to iterate over the constants.