Move the home scrollstate to the main composable to avoid fab annimation.

This commit is contained in:
Thomas Andres Gomez 2023-10-02 09:13:25 +02:00
parent 6924418d21
commit be602d5325
10 changed files with 46 additions and 18 deletions

View file

@ -49,6 +49,9 @@ fun HomeNavHost(
navHostController: NavHostController = rememberNavController(), navHostController: NavHostController = rememberNavController(),
bottomBarItems: List<BottomBarItem> = rememberBottomBarItems(navHostController), bottomBarItems: List<BottomBarItem> = rememberBottomBarItems(navHostController),
startDestination: String = LEXICON_LIST_ROUTE, startDestination: String = LEXICON_LIST_ROUTE,
lexiconListState: LazyListState,
questListState: LazyListState,
locationListState: LazyListState,
) { ) {
CompositionLocalProvider( CompositionLocalProvider(
LocalSnack provides remember { SnackbarHostState() }, LocalSnack provides remember { SnackbarHostState() },
@ -105,9 +108,9 @@ fun HomeNavHost(
navController = navHostController, navController = navHostController,
startDestination = startDestination, startDestination = startDestination,
) { ) {
composableLexicon() composableLexicon(lazyListState = lexiconListState)
composableQuests() composableQuests(lazyListState = questListState)
composableLocations() composableLocations(lazyListState = locationListState)
} }
} }
} }

View file

@ -9,7 +9,6 @@ import androidx.navigation.NavHostController
import androidx.navigation.NavOptionsBuilder import androidx.navigation.NavOptionsBuilder
import androidx.navigation.compose.NavHost import androidx.navigation.compose.NavHost
import androidx.navigation.compose.rememberNavController import androidx.navigation.compose.rememberNavController
import com.pixelized.rplexicon.ui.navigation.screens.AUTHENTICATION_ROUTE
import com.pixelized.rplexicon.ui.navigation.screens.HOME_ROUTE import com.pixelized.rplexicon.ui.navigation.screens.HOME_ROUTE
import com.pixelized.rplexicon.ui.navigation.screens.composableAuthentication import com.pixelized.rplexicon.ui.navigation.screens.composableAuthentication
import com.pixelized.rplexicon.ui.navigation.screens.composableCharacterSheet import com.pixelized.rplexicon.ui.navigation.screens.composableCharacterSheet
@ -41,7 +40,11 @@ fun ScreenNavHost(
startDestination = startDestination, startDestination = startDestination,
) { ) {
composableAuthentication() composableAuthentication()
composableHome() composableHome(
lexiconListState = lexiconListState,
questListState = questListState,
locationListState = locationListState,
)
composableLexiconDetail() composableLexiconDetail()
composableLexiconSearch() composableLexiconSearch()
composableQuestDetail() composableQuestDetail()

View file

@ -12,12 +12,16 @@ private const val ROUTE = "lexicon"
const val LEXICON_LIST_ROUTE = ROUTE const val LEXICON_LIST_ROUTE = ROUTE
fun NavGraphBuilder.composableLexicon() { fun NavGraphBuilder.composableLexicon(
lazyListState: LazyListState,
) {
animatedComposable( animatedComposable(
route = LEXICON_LIST_ROUTE, route = LEXICON_LIST_ROUTE,
animation = NavigationAnimation.Fade, animation = NavigationAnimation.Fade,
) { ) {
LexiconScreen() LexiconScreen(
lazyListState = lazyListState
)
} }
} }

View file

@ -12,12 +12,16 @@ private const val ROUTE = "locations"
const val LOCATION_LIST_ROUTE = ROUTE const val LOCATION_LIST_ROUTE = ROUTE
fun NavGraphBuilder.composableLocations() { fun NavGraphBuilder.composableLocations(
lazyListState: LazyListState,
) {
animatedComposable( animatedComposable(
route = LOCATION_LIST_ROUTE, route = LOCATION_LIST_ROUTE,
animation = NavigationAnimation.Fade, animation = NavigationAnimation.Fade,
) { ) {
LocationScreen() LocationScreen(
lazyListState = lazyListState,
)
} }
} }

View file

@ -12,12 +12,16 @@ private const val ROUTE = "quests"
const val QUEST_LIST_ROUTE = ROUTE const val QUEST_LIST_ROUTE = ROUTE
fun NavGraphBuilder.composableQuests() { fun NavGraphBuilder.composableQuests(
lazyListState: LazyListState,
) {
animatedComposable( animatedComposable(
route = QUEST_LIST_ROUTE, route = QUEST_LIST_ROUTE,
animation = NavigationAnimation.Fade, animation = NavigationAnimation.Fade,
) { ) {
QuestListScreen() QuestListScreen(
lazyListState = lazyListState,
)
} }
} }

View file

@ -1,5 +1,6 @@
package com.pixelized.rplexicon.ui.navigation.screens package com.pixelized.rplexicon.ui.navigation.screens
import androidx.compose.foundation.lazy.LazyListState
import androidx.navigation.NavGraphBuilder import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavHostController import androidx.navigation.NavHostController
import androidx.navigation.NavOptionsBuilder import androidx.navigation.NavOptionsBuilder
@ -11,12 +12,20 @@ private const val ROUTE = "home"
const val HOME_ROUTE = ROUTE const val HOME_ROUTE = ROUTE
fun NavGraphBuilder.composableHome() { fun NavGraphBuilder.composableHome(
lexiconListState: LazyListState,
questListState: LazyListState,
locationListState: LazyListState,
) {
animatedComposable( animatedComposable(
route = HOME_ROUTE, route = HOME_ROUTE,
animation = NavigationAnimation.Push, animation = NavigationAnimation.Push,
) { ) {
HomeNavHost() HomeNavHost(
lexiconListState = lexiconListState,
questListState = questListState,
locationListState = locationListState,
)
} }
} }

View file

@ -18,6 +18,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.sizeIn import androidx.compose.foundation.layout.sizeIn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.LazyRow import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.rememberScrollState

View file

@ -52,11 +52,11 @@ import kotlinx.coroutines.launch
@OptIn(ExperimentalMaterialApi::class) @OptIn(ExperimentalMaterialApi::class)
@Composable @Composable
fun LexiconScreen( fun LexiconScreen(
viewModel: LexiconViewModel = hiltViewModel() viewModel: LexiconViewModel = hiltViewModel(),
lazyListState: LazyListState,
) { ) {
val scope = rememberCoroutineScope() val scope = rememberCoroutineScope()
val screen = LocalScreenNavHost.current val screen = LocalScreenNavHost.current
val lazyListState = rememberLazyListState()
val refresh = rememberPullRefreshState( val refresh = rememberPullRefreshState(
refreshing = false, refreshing = false,

View file

@ -38,10 +38,10 @@ import kotlinx.coroutines.launch
@Composable @Composable
fun LocationScreen( fun LocationScreen(
viewModel: LocationViewModel = hiltViewModel(), viewModel: LocationViewModel = hiltViewModel(),
lazyListState: LazyListState,
) { ) {
val scope = rememberCoroutineScope()
val lazyListState = rememberLazyListState()
val screen = LocalScreenNavHost.current val screen = LocalScreenNavHost.current
val scope = rememberCoroutineScope()
val refresh = rememberPullRefreshState( val refresh = rememberPullRefreshState(
refreshing = false, refreshing = false,

View file

@ -38,10 +38,10 @@ import kotlinx.coroutines.launch
@Composable @Composable
fun QuestListScreen( fun QuestListScreen(
viewModel: QuestListViewModel = hiltViewModel(), viewModel: QuestListViewModel = hiltViewModel(),
lazyListState: LazyListState,
) { ) {
val scope = rememberCoroutineScope() val scope = rememberCoroutineScope()
val screen = LocalScreenNavHost.current val screen = LocalScreenNavHost.current
val lazyListState = rememberLazyListState()
val refresh = rememberPullRefreshState( val refresh = rememberPullRefreshState(
refreshing = false, refreshing = false,