Skip to content

Commit

Permalink
add backhandlers to screens
Browse files Browse the repository at this point in the history
  • Loading branch information
X1nto committed Jan 15, 2024
1 parent f4ffd70 commit 659c3e3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class MainActivity : ComponentActivity() {
UserProfileScreen(
userId = destination.id,
modifier = Modifier.fillMaxSize(),
onBackClick = rootNavController::pop
onBackNavigate = rootNavController::pop
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -39,25 +40,26 @@ 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
)
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun UserProfileScreen(
state: UserProfileState,
onBackClick: () -> Unit,
onBackNavigate: () -> Unit,
modifier: Modifier = Modifier
) {
Scaffold(
Expand All @@ -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
Expand Down

0 comments on commit 659c3e3

Please sign in to comment.