Skip to content

davidliu/LazyColumnItemDiffAnimations

Repository files navigation

LazyColumnItemDiffAnimations

An experimental method for providing item diff animations in a LazyColumn. Note that this only handles additions and removals, not moves.

ezgif-4-c97be879c5b6

inline fun <T> LazyListScope.animatedItemsIndexed(
    state: List<AnimatedItem<T>>,
    enterTransition: EnterTransition = expandVertically(),
    exitTransition: ExitTransition = shrinkVertically(),
    noinline key: ((item: T) -> Any)? = null,
    crossinline itemContent: @Composable LazyItemScope.(index: Int, item: T) -> Unit
)

The state parameter should be obtained through the use of the updateAnimatedItemsState method:

fun <T> updateAnimatedItemsState(
    newList: List<T>
): State<List<AnimatedItem<T>>> 

Implementation is found here.

Example usage:

val animationState by updateAnimatedItemsState(list)
LazyColumn(Modifier.fillMaxSize()) {
    animatedItemsIndexed(animationState, key = { it }) { _, item ->
        // item content
        // ...
    }
}

This repo also provides an example activity.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages