Merge pull request #77 from fknives/fix-compose-back-navigation
Fix back navigation in Compose implementation
This commit is contained in:
commit
041c721cc0
2 changed files with 31 additions and 11 deletions
|
|
@ -6,6 +6,7 @@ import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.testTag
|
import androidx.compose.ui.platform.testTag
|
||||||
|
import androidx.navigation.NavOptions
|
||||||
import androidx.navigation.compose.NavHost
|
import androidx.navigation.compose.NavHost
|
||||||
import androidx.navigation.compose.composable
|
import androidx.navigation.compose.composable
|
||||||
import androidx.navigation.compose.rememberNavController
|
import androidx.navigation.compose.rememberNavController
|
||||||
|
|
@ -24,34 +25,53 @@ fun AppNavigation(isUserLogeInUseCase: IsUserLoggedInUseCase = get()) {
|
||||||
|
|
||||||
LaunchedEffect(isUserLogeInUseCase) {
|
LaunchedEffect(isUserLogeInUseCase) {
|
||||||
delay(500)
|
delay(500)
|
||||||
navController.navigate(if (isUserLogeInUseCase.invoke()) "Home" else "Auth")
|
navController.navigate(
|
||||||
|
route = if (isUserLogeInUseCase.invoke()) RouteTag.HOME else RouteTag.AUTH,
|
||||||
|
navOptions = NavOptions.Builder().setPopUpTo(route = RouteTag.SPLASH, inclusive = true).build()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
NavHost(
|
NavHost(
|
||||||
navController,
|
navController,
|
||||||
startDestination = "Splash",
|
startDestination = RouteTag.SPLASH,
|
||||||
modifier = Modifier.background(MaterialTheme.colors.surface)
|
modifier = Modifier.background(MaterialTheme.colors.surface)
|
||||||
) {
|
) {
|
||||||
composable("Splash") { SplashScreen() }
|
composable(RouteTag.SPLASH) { SplashScreen() }
|
||||||
composable("Auth") {
|
composable(RouteTag.AUTH) {
|
||||||
AuthScreen(
|
AuthScreen(
|
||||||
modifier = Modifier.testTag(AppNavigationTag.AuthScreen),
|
modifier = Modifier.testTag(AppNavigationTag.AuthScreen),
|
||||||
authScreenState = rememberAuthScreenState(
|
authScreenState = rememberAuthScreenState(
|
||||||
onLoginSuccess = { navController.navigate("Home") }
|
onLoginSuccess = {
|
||||||
|
navController.navigate(
|
||||||
|
route = RouteTag.HOME,
|
||||||
|
navOptions = NavOptions.Builder().setPopUpTo(route = RouteTag.AUTH, inclusive = true).build()
|
||||||
|
)
|
||||||
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
composable("Home") {
|
composable(RouteTag.HOME) {
|
||||||
HomeScreen(
|
HomeScreen(
|
||||||
modifier = Modifier.testTag(AppNavigationTag.HomeScreen),
|
modifier = Modifier.testTag(AppNavigationTag.HomeScreen),
|
||||||
homeScreenState = rememberHomeScreenState(
|
homeScreenState = rememberHomeScreenState(
|
||||||
onLogout = { navController.navigate("Auth") }
|
onLogout = {
|
||||||
|
navController.navigate(
|
||||||
|
route = RouteTag.AUTH,
|
||||||
|
navOptions = NavOptions.Builder().setPopUpTo(route = RouteTag.HOME, inclusive = true).build()
|
||||||
|
)
|
||||||
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
object RouteTag {
|
||||||
|
const val HOME = "Home"
|
||||||
|
const val AUTH = "Auth"
|
||||||
|
const val SPLASH = "Splash"
|
||||||
|
}
|
||||||
|
|
||||||
object AppNavigationTag {
|
object AppNavigationTag {
|
||||||
const val AuthScreen = "AppNavigationTag.AuthScreen"
|
const val AuthScreen = "AppNavigationTag.AuthScreen"
|
||||||
const val HomeScreen = "AppNavigationTag.HomeScreen"
|
const val HomeScreen = "AppNavigationTag.HomeScreen"
|
||||||
|
|
|
||||||
|
|
@ -279,7 +279,7 @@ formatting:
|
||||||
active: false
|
active: false
|
||||||
autoCorrect: true
|
autoCorrect: true
|
||||||
indentSize: 4
|
indentSize: 4
|
||||||
maxLineLength: 120
|
maxLineLength: 140
|
||||||
ChainWrapping:
|
ChainWrapping:
|
||||||
active: true
|
active: true
|
||||||
autoCorrect: true
|
autoCorrect: true
|
||||||
|
|
@ -306,7 +306,7 @@ formatting:
|
||||||
continuationIndentSize: 4
|
continuationIndentSize: 4
|
||||||
MaximumLineLength:
|
MaximumLineLength:
|
||||||
active: true
|
active: true
|
||||||
maxLineLength: 120
|
maxLineLength: 140
|
||||||
ignoreBackTickedIdentifier: false
|
ignoreBackTickedIdentifier: false
|
||||||
ModifierOrdering:
|
ModifierOrdering:
|
||||||
active: true
|
active: true
|
||||||
|
|
@ -356,7 +356,7 @@ formatting:
|
||||||
active: true
|
active: true
|
||||||
autoCorrect: true
|
autoCorrect: true
|
||||||
indentSize: 4
|
indentSize: 4
|
||||||
maxLineLength: 120
|
maxLineLength: 140
|
||||||
SpacingAroundAngleBrackets:
|
SpacingAroundAngleBrackets:
|
||||||
active: false
|
active: false
|
||||||
autoCorrect: true
|
autoCorrect: true
|
||||||
|
|
@ -678,7 +678,7 @@ style:
|
||||||
active: false
|
active: false
|
||||||
MaxLineLength:
|
MaxLineLength:
|
||||||
active: true
|
active: true
|
||||||
maxLineLength: 120
|
maxLineLength: 140
|
||||||
excludePackageStatements: true
|
excludePackageStatements: true
|
||||||
excludeImportStatements: true
|
excludeImportStatements: true
|
||||||
excludeCommentStatements: false
|
excludeCommentStatements: false
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue