From 659c3e32bf550eae36809f4a1d6df18f413976e3 Mon Sep 17 00:00:00 2001 From: Xinto Date: Mon, 15 Jan 2024 13:43:20 +0400 Subject: [PATCH] add backhandlers to screens --- .../src/main/java/dev/xinto/argos/ui/MainActivity.kt | 2 +- .../ui/screen/meuserprofile/MeUserProfileScreen.kt | 2 ++ .../argos/ui/screen/userprofile/UserProfileScreen.kt | 10 ++++++---- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/androidApp/src/main/java/dev/xinto/argos/ui/MainActivity.kt b/androidApp/src/main/java/dev/xinto/argos/ui/MainActivity.kt index b89946d..78d1ac8 100644 --- a/androidApp/src/main/java/dev/xinto/argos/ui/MainActivity.kt +++ b/androidApp/src/main/java/dev/xinto/argos/ui/MainActivity.kt @@ -132,7 +132,7 @@ class MainActivity : ComponentActivity() { UserProfileScreen( userId = destination.id, modifier = Modifier.fillMaxSize(), - onBackClick = rootNavController::pop + onBackNavigate = rootNavController::pop ) } } diff --git a/androidApp/src/main/java/dev/xinto/argos/ui/screen/meuserprofile/MeUserProfileScreen.kt b/androidApp/src/main/java/dev/xinto/argos/ui/screen/meuserprofile/MeUserProfileScreen.kt index 626d383..8acb584 100644 --- a/androidApp/src/main/java/dev/xinto/argos/ui/screen/meuserprofile/MeUserProfileScreen.kt +++ b/androidApp/src/main/java/dev/xinto/argos/ui/screen/meuserprofile/MeUserProfileScreen.kt @@ -1,5 +1,6 @@ package dev.xinto.argos.ui.screen.meuserprofile +import androidx.activity.compose.BackHandler import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.scaleIn import androidx.compose.animation.scaleOut @@ -41,6 +42,7 @@ fun MeUserProfileScreen( val state by viewModel.state.collectAsStateWithLifecycle() val canSave by viewModel.canSave.collectAsStateWithLifecycle() val saving by viewModel.saving.collectAsStateWithLifecycle() + BackHandler(onBack = onBackNavigate) MeUserProfileScreen( modifier = modifier, onBackNavigate = onBackNavigate, diff --git a/androidApp/src/main/java/dev/xinto/argos/ui/screen/userprofile/UserProfileScreen.kt b/androidApp/src/main/java/dev/xinto/argos/ui/screen/userprofile/UserProfileScreen.kt index 501de0d..5cdd6df 100644 --- a/androidApp/src/main/java/dev/xinto/argos/ui/screen/userprofile/UserProfileScreen.kt +++ b/androidApp/src/main/java/dev/xinto/argos/ui/screen/userprofile/UserProfileScreen.kt @@ -1,5 +1,6 @@ package dev.xinto.argos.ui.screen.userprofile +import androidx.activity.compose.BackHandler import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column @@ -39,17 +40,18 @@ import org.koin.androidx.compose.getStateViewModel @Composable fun UserProfileScreen( userId: String, - onBackClick: () -> Unit, + onBackNavigate: () -> Unit, modifier: Modifier = Modifier ) { val viewModel: UserProfileViewModel = getStateViewModel(state = { bundleOf(UserProfileViewModel.KEY_USER_ID to userId) }) val state by viewModel.state.collectAsStateWithLifecycle() + BackHandler(onBack = onBackNavigate) UserProfileScreen( modifier = modifier, state = state, - onBackClick = onBackClick + onBackNavigate = onBackNavigate ) } @@ -57,7 +59,7 @@ fun UserProfileScreen( @Composable fun UserProfileScreen( state: UserProfileState, - onBackClick: () -> Unit, + onBackNavigate: () -> Unit, modifier: Modifier = Modifier ) { Scaffold( @@ -66,7 +68,7 @@ fun UserProfileScreen( TopAppBar( title = { Text(stringResource(R.string.userprofile_title)) }, navigationIcon = { - IconButton(onClick = onBackClick) { + IconButton(onClick = onBackNavigate) { Icon( painter = painterResource(R.drawable.ic_arrow_back), contentDescription = null