Animated scroll to top from hme bottom bar.
This commit is contained in:
parent
30b3de2681
commit
7de925a431
1 changed files with 23 additions and 3 deletions
|
|
@ -15,7 +15,10 @@ import androidx.compose.material3.TopAppBar
|
|||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.Stable
|
||||
import androidx.compose.runtime.derivedStateOf
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.staticCompositionLocalOf
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.shadow
|
||||
|
|
@ -39,6 +42,7 @@ import com.pixelized.rplexicon.ui.navigation.pages.composableQuests
|
|||
import com.pixelized.rplexicon.ui.navigation.pages.navigateToLexicon
|
||||
import com.pixelized.rplexicon.ui.navigation.pages.navigateToLocation
|
||||
import com.pixelized.rplexicon.ui.navigation.pages.navigateToQuestList
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
val LocalPageNavHost = staticCompositionLocalOf<NavHostController> {
|
||||
error("LocalScreenNavHost not ready")
|
||||
|
|
@ -54,6 +58,7 @@ fun HomeNavHost(
|
|||
questListState: LazyListState,
|
||||
locationListState: LazyListState,
|
||||
) {
|
||||
val scope = rememberCoroutineScope()
|
||||
CompositionLocalProvider(
|
||||
LocalSnack provides remember { SnackbarHostState() },
|
||||
) {
|
||||
|
|
@ -78,11 +83,26 @@ fun HomeNavHost(
|
|||
containerColor = MaterialTheme.colorScheme.surface,
|
||||
tonalElevation = 0.dp,
|
||||
) {
|
||||
bottomBarItems.forEach { item ->
|
||||
bottomBarItems.forEachIndexed { index, item ->
|
||||
val selected by remember {
|
||||
derivedStateOf {
|
||||
item.route == backStackEntry.value?.destination?.route
|
||||
}
|
||||
}
|
||||
NavigationBarItem(
|
||||
selected = item.route == backStackEntry.value?.destination?.route,
|
||||
selected = selected,
|
||||
onClick = {
|
||||
if (selected) {
|
||||
scope.launch {
|
||||
when (index) {
|
||||
0 -> lexiconListState.animateScrollToItem(index = 0)
|
||||
1 -> questListState.animateScrollToItem(index = 0)
|
||||
2 -> locationListState.animateScrollToItem(index = 0)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
item.onClick.invoke()
|
||||
}
|
||||
},
|
||||
label = {
|
||||
Text(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue