Skip to content

Commit 2f7419d

Browse files
authored
Add crossfade transition (#286)
1 parent d7dbda9 commit 2f7419d

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package cafe.adriel.voyager.transitions
2+
3+
import androidx.compose.animation.Crossfade
4+
import androidx.compose.animation.core.FiniteAnimationSpec
5+
import androidx.compose.animation.core.tween
6+
import androidx.compose.runtime.Composable
7+
import androidx.compose.ui.Modifier
8+
import cafe.adriel.voyager.core.screen.Screen
9+
import cafe.adriel.voyager.navigator.Navigator
10+
11+
@Composable
12+
public fun CrossfadeTransition(
13+
navigator: Navigator,
14+
animationSpec: FiniteAnimationSpec<Float> = tween(),
15+
label: String = "Crossfade",
16+
modifier: Modifier = Modifier,
17+
content: @Composable (Screen) -> Unit = { it.Content() }
18+
) {
19+
Crossfade(
20+
targetState = navigator.lastItem,
21+
animationSpec = animationSpec,
22+
modifier = modifier,
23+
label = label
24+
) { screen ->
25+
navigator.saveableState("transition", screen) {
26+
content(screen)
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)