Moves gesture enable to inside the composable.

Creates a function just for navhost
This commit is contained in:
Vitor Pamplona
2026-03-26 14:37:16 -04:00
parent bba4d28e4b
commit 39e89834ba
2 changed files with 229 additions and 219 deletions
@@ -36,10 +36,8 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.core.util.Consumer import androidx.core.util.Consumer
import androidx.navigation.NavDestination.Companion.hasRoute
import androidx.navigation.compose.NavHost import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable import androidx.navigation.compose.composable
import androidx.navigation.compose.currentBackStackEntryAsState
import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.service.crashreports.DisplayCrashMessages import com.vitorpamplona.amethyst.service.crashreports.DisplayCrashMessages
import com.vitorpamplona.amethyst.service.relayClient.notifyCommand.compose.DisplayNotifyMessages import com.vitorpamplona.amethyst.service.relayClient.notifyCommand.compose.DisplayNotifyMessages
@@ -140,19 +138,27 @@ fun AppNavigation(
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
accountSessionManager: AccountSessionManager, accountSessionManager: AccountSessionManager,
) { ) {
println("AABBCC AppNavigation Begins")
val nav = rememberNav() val nav = rememberNav()
val navBackStackEntry by nav.controller.currentBackStackEntryAsState() AccountSwitcherAndLeftDrawerLayout(accountViewModel, accountSessionManager, nav) {
val isTabPagerRoute = BuildNavigation(accountViewModel, nav)
navBackStackEntry?.destination?.let { dest -> }
dest.hasRoute<Route.Home>() || dest.hasRoute<Route.Message>()
} ?: false
val drawerGesturesEnabled =
!isTabPagerRoute ||
nav.drawerState.isOpen ||
nav.drawerState.targetValue != nav.drawerState.currentValue
AccountSwitcherAndLeftDrawerLayout(accountViewModel, accountSessionManager, nav, drawerGesturesEnabled) { NavigateIfIntentRequested(nav, accountViewModel, accountSessionManager)
DisplayErrorMessages(accountViewModel.toastManager, accountViewModel, nav)
DisplayNotifyMessages(accountViewModel, nav)
DisplayCrashMessages(accountViewModel, nav)
DisplayBroadcastProgress(accountViewModel)
println("AABBCC AppNavigation Ends")
}
@Composable
fun BuildNavigation(
accountViewModel: AccountViewModel,
nav: Nav,
) {
NavHost( NavHost(
navController = nav.controller, navController = nav.controller,
startDestination = Route.Home, startDestination = Route.Home,
@@ -357,14 +363,6 @@ fun AppNavigation(
} }
} }
NavigateIfIntentRequested(nav, accountViewModel, accountSessionManager)
DisplayErrorMessages(accountViewModel.toastManager, accountViewModel, nav)
DisplayNotifyMessages(accountViewModel, nav)
DisplayCrashMessages(accountViewModel, nav)
DisplayBroadcastProgress(accountViewModel)
}
@Composable @Composable
private fun NavigateIfIntentRequested( private fun NavigateIfIntentRequested(
nav: Nav, nav: Nav,
@@ -37,9 +37,12 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.platform.LocalConfiguration
import androidx.navigation.NavDestination.Companion.hasRoute
import androidx.navigation.compose.currentBackStackEntryAsState
import com.vitorpamplona.amethyst.ui.navigation.drawer.AccountSwitchBottomSheet import com.vitorpamplona.amethyst.ui.navigation.drawer.AccountSwitchBottomSheet
import com.vitorpamplona.amethyst.ui.navigation.drawer.DrawerContent import com.vitorpamplona.amethyst.ui.navigation.drawer.DrawerContent
import com.vitorpamplona.amethyst.ui.navigation.navs.INav import com.vitorpamplona.amethyst.ui.navigation.navs.Nav
import com.vitorpamplona.amethyst.ui.navigation.routes.Route
import com.vitorpamplona.amethyst.ui.screen.AccountSessionManager import com.vitorpamplona.amethyst.ui.screen.AccountSessionManager
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@@ -48,8 +51,7 @@ import kotlinx.coroutines.launch
fun AccountSwitcherAndLeftDrawerLayout( fun AccountSwitcherAndLeftDrawerLayout(
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
accountSessionManager: AccountSessionManager, accountSessionManager: AccountSessionManager,
nav: INav, nav: Nav,
gesturesEnabled: Boolean = true,
content: @Composable () -> Unit, content: @Composable () -> Unit,
) { ) {
val scope = rememberCoroutineScope() val scope = rememberCoroutineScope()
@@ -82,9 +84,19 @@ fun AccountSwitcherAndLeftDrawerLayout(
} }
} }
val navBackStackEntry by nav.controller.currentBackStackEntryAsState()
val isTabPagerRoute =
navBackStackEntry?.destination?.let { dest ->
dest.hasRoute<Route.Home>() || dest.hasRoute<Route.Message>()
} ?: false
val drawerGesturesEnabled =
!isTabPagerRoute ||
nav.drawerState.isOpen ||
nav.drawerState.targetValue != nav.drawerState.currentValue
ModalNavigationDrawer( ModalNavigationDrawer(
drawerState = nav.drawerState, drawerState = nav.drawerState,
gesturesEnabled = gesturesEnabled, gesturesEnabled = drawerGesturesEnabled,
drawerContent = { drawerContent = {
DrawerContent(nav, openSheetFunction, accountViewModel) DrawerContent(nav, openSheetFunction, accountViewModel)
BackHandler(enabled = nav.drawerState.isOpen, nav::closeDrawer) BackHandler(enabled = nav.drawerState.isOpen, nav::closeDrawer)