Skip to content

Commit

Permalink
Fix auth screen navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
X1nto committed Nov 10, 2024
1 parent 4e6727f commit 95fb7e6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
5 changes: 4 additions & 1 deletion app/src/main/java/com/xinto/mauth/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class MainActivity : FragmentActivity() {
)
)
}
initial is MauthDestination.Auth -> {
initial is MauthDestination.Auth && action !is NavAction.Pop -> {
fadeIn() + scaleIn(
initialScale = 0.9f
) togetherWith fadeOut() + slideOut {
Expand Down Expand Up @@ -174,6 +174,9 @@ class MainActivity : FragmentActivity() {
} else {
navigator.replaceAll(MauthDestination.Home)
}
},
onBackPress = if (screen.nextDestination == null) null else { ->
navigator.pop()
}
)
}
Expand Down
36 changes: 33 additions & 3 deletions app/src/main/java/com/xinto/mauth/ui/screen/auth/AuthScreen.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.xinto.mauth.ui.screen.auth

import androidx.activity.compose.BackHandler
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.LargeTopAppBar
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
Expand All @@ -8,6 +12,7 @@ import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.xinto.mauth.R
Expand All @@ -20,7 +25,8 @@ import org.koin.androidx.compose.getViewModel
@Composable
fun AuthScreen(
modifier: Modifier = Modifier,
onAuthSuccess: () -> Unit
onAuthSuccess: () -> Unit,
onBackPress: (() -> Unit)? = null
) {
val viewModel: AuthViewModel = getViewModel()
val code by viewModel.code.collectAsStateWithLifecycle()
Expand All @@ -39,6 +45,9 @@ fun AuthScreen(
}
}

BackHandler(enabled = onBackPress != null) {
onBackPress?.invoke()
}
LaunchedEffect(code) {
if (viewModel.validate(code)) {
onAuthSuccess()
Expand All @@ -62,7 +71,8 @@ fun AuthScreen(
showFingerprint = canUseBiometrics,
onFingerprintClick = {
biometricHandler.requestBiometrics(promptData)
}
},
onBackPress = onBackPress
)
}

Expand All @@ -74,6 +84,7 @@ fun AuthScreen(
onClear: () -> Unit,
showFingerprint: Boolean,
onFingerprintClick: () -> Unit,
onBackPress: (() -> Unit)? = null,
modifier: Modifier = Modifier
) {
val pinBoardState = rememberPinBoardState(
Expand All @@ -86,7 +97,26 @@ fun AuthScreen(
PinScaffold(
modifier = modifier,
description = {
Text(stringResource(R.string.auth_title))
if (onBackPress == null) {
Text(stringResource(R.string.auth_title))
}
},
topBar = {
if (onBackPress != null) {
LargeTopAppBar(
title = {
Text(stringResource(R.string.auth_title))
},
navigationIcon = {
IconButton(onClick = onBackPress) {
Icon(
painter = painterResource(R.drawable.ic_arrow_back),
contentDescription = null
)
}
}
)
}
},
codeLength = code.length,
state = pinBoardState
Expand Down

0 comments on commit 95fb7e6

Please sign in to comment.