Skip to content

Commit

Permalink
fix: home screen transition issues [WPB-11580] (#3508)
Browse files Browse the repository at this point in the history
  • Loading branch information
saleniuk authored Oct 15, 2024
1 parent 3f305a7 commit e97b005
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions app/src/main/kotlin/com/wire/android/ui/home/HomeStateHolder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import androidx.compose.material3.DrawerState
import androidx.compose.material3.DrawerValue
import androidx.compose.material3.rememberDrawerState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
Expand All @@ -44,15 +42,12 @@ class HomeStateHolder(
val coroutineScope: CoroutineScope,
val navController: NavHostController,
val drawerState: DrawerState,
val currentNavigationItem: HomeDestination,
val searchBarState: SearchBarState,
val navigator: Navigator,
private val currentNavigationItemState: State<HomeDestination>,
private val lazyListStates: Map<HomeDestination, LazyListState>,
lazyListStates: Map<HomeDestination, LazyListState>,
) {
val currentNavigationItem: HomeDestination
get() = currentNavigationItemState.value
val currentLazyListState: LazyListState
get() = lazyListStates[currentNavigationItem] ?: error("No LazyListState found for $currentNavigationItem")
val currentLazyListState = lazyListStates[currentNavigationItem] ?: error("No LazyListState found for $currentNavigationItem")

fun closeDrawer() {
coroutineScope.launch {
Expand All @@ -78,22 +73,23 @@ fun rememberHomeScreenState(
): HomeStateHolder {
val searchBarState = rememberSearchbarState()
val navBackStackEntry by navController.currentBackStackEntryAsState()
val currentNavigationItemState = remember {
derivedStateOf {
navBackStackEntry?.destination?.route?.let { HomeDestination.fromRoute(it) } ?: HomeDestination.Conversations
}
}
val currentRoute = navBackStackEntry?.destination?.route
val currentNavigationItem = currentRoute?.let { HomeDestination.fromRoute(it) } ?: HomeDestination.Conversations
val lazyListStates = HomeDestination.values().associateWith { rememberLazyListState() }

return remember {
val homeState = remember(
currentNavigationItem
) {
HomeStateHolder(
coroutineScope = coroutineScope,
navController = navController,
drawerState = drawerState,
currentNavigationItemState = currentNavigationItemState,
searchBarState = searchBarState,
navigator = navigator,
lazyListStates = lazyListStates
coroutineScope,
navController,
drawerState,
currentNavigationItem,
searchBarState,
navigator,
lazyListStates
)
}

return homeState
}

0 comments on commit e97b005

Please sign in to comment.