Skip to content

Commit

Permalink
Add crossfade transition (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
Revxrsal authored Jan 19, 2024
1 parent d7dbda9 commit 2f7419d
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package cafe.adriel.voyager.transitions

import androidx.compose.animation.Crossfade
import androidx.compose.animation.core.FiniteAnimationSpec
import androidx.compose.animation.core.tween
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import cafe.adriel.voyager.core.screen.Screen
import cafe.adriel.voyager.navigator.Navigator

@Composable
public fun CrossfadeTransition(
navigator: Navigator,
animationSpec: FiniteAnimationSpec<Float> = tween(),
label: String = "Crossfade",
modifier: Modifier = Modifier,
content: @Composable (Screen) -> Unit = { it.Content() }
) {
Crossfade(
targetState = navigator.lastItem,
animationSpec = animationSpec,
modifier = modifier,
label = label
) { screen ->
navigator.saveableState("transition", screen) {
content(screen)
}
}
}

0 comments on commit 2f7419d

Please sign in to comment.