commonMain.com.arkivanov.decompose.extensions.compose.stack.animation.StackAnimation.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of extensions-compose-jvm Show documentation
Show all versions of extensions-compose-jvm Show documentation
Kotlin Multiplatform lifecycle-aware business logic components
The newest version!
package com.arkivanov.decompose.extensions.compose.stack.animation
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.arkivanov.decompose.Child
import com.arkivanov.decompose.FaultyDecomposeApi
import com.arkivanov.decompose.router.stack.ChildStack
/**
* Tracks the [ChildStack] changes and animates between child widget.
*/
fun interface StackAnimation {
@Composable
operator fun invoke(
stack: ChildStack,
modifier: Modifier,
content: @Composable (child: Child.Created) -> Unit,
)
}
/**
* Creates an implementation of [StackAnimation] that allows different [StackAnimator]s.
*
* FaultyDecomposeApi. Please note that this API uses `movableContentOf` Compose API.
* Even though `movableContentOf` is not marked as experimental, it was known to contain bugs,
* e.g. https://issuetracker.google.com/issues/270656235, https://issuetracker.google.com/issues/290343159.
*
* @param disableInputDuringAnimation disables input and touch events while animating, default value is `true`.
* @param selector provides a [StackAnimator] for the current [Child], other [Child] and [Direction].
*/
@FaultyDecomposeApi
fun stackAnimation(
disableInputDuringAnimation: Boolean = true,
selector: (child: Child.Created, otherChild: Child.Created, direction: Direction) -> StackAnimator?,
): StackAnimation =
MovableStackAnimation(
disableInputDuringAnimation = disableInputDuringAnimation,
selector = selector,
)
/**
* Creates an implementation of [StackAnimation] that allows different [StackAnimator]s.
*
* @param disableInputDuringAnimation disables input and touch events while animating, default value is `true`.
* @param selector provides a [StackAnimator] for the current [Child].
*/
fun stackAnimation(
disableInputDuringAnimation: Boolean = true,
selector: (child: Child.Created) -> StackAnimator?,
): StackAnimation =
SimpleStackAnimation(
disableInputDuringAnimation = disableInputDuringAnimation,
selector = selector,
)
/**
* Creates an implementation of [StackAnimation] with the provided [StackAnimator].
*
* @param animator a [StackAnimator] to be used for animation, default is [fade].
* @param disableInputDuringAnimation disables input and touch events while animating, default value is `true`.
*/
fun stackAnimation(
animator: StackAnimator = fade(),
disableInputDuringAnimation: Boolean = true,
): StackAnimation =
SimpleStackAnimation(
disableInputDuringAnimation = disableInputDuringAnimation,
selector = { animator },
)
© 2015 - 2024 Weber Informatics LLC | Privacy Policy