raghunandan
07/03/2024, 4:49 AMraghunandan
07/03/2024, 4:51 AMIan Lake
07/03/2024, 5:20 AMraghunandan
07/03/2024, 7:57 AMraghunandan
09/13/2024, 4:01 PMraghunandan
09/14/2024, 1:43 AM@OptIn(ExperimentalSharedTransitionApi::class)
@Composable
fun SimpleJetsnackApp() {
val navController = rememberNavController()
SharedTransitionLayout {
CompositionLocalProvider(
LocalSharedTransitionScope provides this
) {
NavHost(navController = navController, startDestination = "home") {
composable("home") {
CompositionLocalProvider(
LocalNavAnimatedVisibilityScope provides this
) {
HomeScreen(onSnackSelected = { navController.navigate("detail") })
}
}
composable(
"detail",
) {
DetailScreen()
}
}
}
}
}
@OptIn(ExperimentalSharedTransitionApi::class)
@Composable
fun HomeScreen(onSnackSelected: () -> Unit) {
val sharedTransitionScope = LocalSharedTransitionScope.current
?: throw IllegalStateException("No SharedElementScope found")
val animatedVisibilityScope = LocalNavAnimatedVisibilityScope.current
?: throw IllegalStateException("No SharedElementScope found")
Scaffold(
bottomBar = {
with(animatedVisibilityScope) {
with(sharedTransitionScope) {
NavigationBar(
modifier = Modifier
.renderInSharedTransitionScopeOverlay(zIndexInOverlay = 1f)
) {
NavigationBarItem(
icon = { Icon(Icons.Filled.Home, contentDescription = "Home") },
label = { Text("Home") },
selected = true, // You'll need to manage the selected state
onClick = { /*TODO*/ }
)
NavigationBarItem(
icon = { Icon(Icons.Filled.Settings, contentDescription = "Settings") },
label = { Text("Settings") },
selected = false, // You'll need to manage the selected state
onClick = { /*TODO*/ }
)
}
}
}
}
) { innerPadding ->
Column(
modifier = Modifier
.padding(innerPadding)
.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Button(onClick = onSnackSelected) {
Text("Go to Detail")
}
}
}
}
@Composable
fun DetailScreen() {
// Detail screen content
Box(
modifier = Modifier
.fillMaxSize()
.background(Color.LightGray),
contentAlignment = Alignment.Center
) {
Text("Detail Screen")
}
}
val LocalNavAnimatedVisibilityScope = compositionLocalOf<AnimatedVisibilityScope?> { null }
@OptIn(ExperimentalSharedTransitionApi::class)
val LocalSharedTransitionScope = compositionLocalOf<SharedTransitionScope?> { null }
A very basic implementation based on jet snack.