commonMain.com.arkivanov.decompose.extensions.compose.stack.animation.Fade.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of extensions-compose Show documentation
Show all versions of extensions-compose Show documentation
Kotlin Multiplatform lifecycle-aware business logic components
The newest version!
package com.arkivanov.decompose.extensions.compose.stack.animation
import androidx.compose.animation.core.FiniteAnimationSpec
import androidx.compose.animation.core.tween
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import kotlin.math.abs
/**
* A simple fading animation. Appearing children's `alpha` is animated from [minAlpha] to 1.0.
* Disappearing children's `alpha` is animated from 1.0 to [minAlpha].
*/
fun fade(
animationSpec: FiniteAnimationSpec = tween(),
minAlpha: Float = 0F,
): StackAnimator =
stackAnimator(animationSpec = animationSpec) { factor, _, content ->
content(Modifier.alpha(getFadeAlpha(factor = factor, minAlpha = minAlpha)))
}
internal fun getFadeAlpha(factor: Float, minAlpha: Float): Float =
(1F - abs(factor) * (1F - minAlpha)).coerceIn(minimumValue = 0F, maximumValue = 1F)
© 2015 - 2024 Weber Informatics LLC | Privacy Policy