Skip to content

Commit

Permalink
feat: nav complete
Browse files Browse the repository at this point in the history
  • Loading branch information
JNdhlovu committed Sep 19, 2024
1 parent 284d996 commit 2ea9eff
Show file tree
Hide file tree
Showing 8 changed files with 509 additions and 337 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.PickVisualMediaRequest
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.result.contract.ActivityResultContracts.PickVisualMedia.ImageOnly
import androidx.annotation.DrawableRes
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
Expand All @@ -17,11 +16,7 @@ import androidx.lifecycle.viewmodel.compose.viewModel
import com.smileidentity.R
import com.smileidentity.SmileIDCrashReporting
import com.smileidentity.compose.components.LocalMetadata
import com.smileidentity.compose.nav.DocumentInstructionParams
import com.smileidentity.compose.nav.ImageConfirmParams
import com.smileidentity.compose.nav.ResultCallbacks
import com.smileidentity.compose.nav.Routes
import com.smileidentity.compose.nav.encodeUrl
import com.smileidentity.compose.nav.localNavigationState
import com.smileidentity.models.v2.Metadatum
import com.smileidentity.util.createDocumentFile
Expand All @@ -48,19 +43,11 @@ internal fun DocumentCaptureScreen(
resultCallbacks: ResultCallbacks,
jobId: String,
side: DocumentCaptureSide,
showInstructions: Boolean,
showAttribution: Boolean,
allowGallerySelection: Boolean,
showSkipButton: Boolean,
@DrawableRes instructionsHeroImage: Int,
instructionsTitleText: String,
instructionsSubtitleText: String,
captureTitleText: String,
knownIdAspectRatio: Float?,
onConfirm: (File) -> Unit,
onError: (Throwable) -> Unit,
knownIdAspectRatio: Float?,
modifier: Modifier = Modifier,
showConfirmation: Boolean = true,
metadata: SnapshotStateList<Metadatum> = LocalMetadata.current,
onSkip: () -> Unit = { },
viewModel: DocumentCaptureViewModel = viewModel(
Expand Down Expand Up @@ -97,7 +84,6 @@ internal fun DocumentCaptureScreen(
)
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
val documentImageToConfirm = uiState.documentImageToConfirm
val captureError = uiState.captureError
resultCallbacks.onDocumentInstructionAcknowledgedSelectFromGallery = {
Timber.v("onInstructionsAcknowledgedSelectFromGallery")
SmileIDCrashReporting.hub.addBreadcrumb("Selecting document photo from gallery")
Expand All @@ -108,60 +94,14 @@ internal fun DocumentCaptureScreen(
localNavigationState.screensNavigation.getNavController.popBackStack()
}
resultCallbacks.onDocumentInstructionSkip = onSkip
val aspectRatio by animateFloatAsState(
targetValue = uiState.idAspectRatio,
label = "ID Aspect Ratio",
)
when {
captureError != null -> onError(captureError)
showInstructions && !uiState.acknowledgedInstructions -> {
localNavigationState.screensNavigation.navigateTo(
Routes.Document.InstructionScreen(
params = DocumentInstructionParams(
heroImage = instructionsHeroImage,
title = instructionsTitleText,
subtitle = instructionsSubtitleText,
showAttribution = showAttribution,
allowPhotoFromGallery = allowGallerySelection,
showSkipButton = showSkipButton,
),
),
popUpTo = true,
popUpToInclusive = true,
)
}

documentImageToConfirm != null -> {
if (showConfirmation) {
resultCallbacks.onConfirmCapturedImage = {
viewModel.onConfirm(documentImageToConfirm, onConfirm)
localNavigationState.screensNavigation.getNavController.popBackStack()
}
resultCallbacks.onImageDialogRetake = {
viewModel.onRetry()
localNavigationState.screensNavigation.getNavController.popBackStack()
}
localNavigationState.screensNavigation.navigateTo(
Routes.Shared.ImageConfirmDialog(
ImageConfirmParams(
titleText = R.string.si_smart_selfie_confirmation_dialog_title,
subtitleText = R.string.si_smart_selfie_confirmation_dialog_subtitle,
imageFilePath = encodeUrl(documentImageToConfirm.absolutePath),
confirmButtonText =
R.string.si_doc_v_confirmation_dialog_confirm_button,
retakeButtonText = R.string.si_doc_v_confirmation_dialog_retake_button,
scaleFactor = 1.0f,
),
),
popUpTo = true,
popUpToInclusive = true,
)
} else {
viewModel.onConfirm(documentImageToConfirm, onConfirm)
}
}

documentImageToConfirm != null ->
viewModel.onConfirm(documentImageToConfirm, onConfirm)
else -> {
val aspectRatio by animateFloatAsState(
targetValue = uiState.idAspectRatio,
label = "ID Aspect Ratio",
)
CaptureScreenContent(
titleText = captureTitleText,
subtitleText = stringResource(id = uiState.directive.displayText),
Expand All @@ -176,13 +116,4 @@ internal fun DocumentCaptureScreen(
)
}
}

// NavigationBackHandler(
// navController = localNavigationState.screensNavigation.getNavController,
// ) { currentDestination ->
// localNavigationState.screensNavigation.getNavController.popBackStack()
// if (compareRouteStrings(startRoute, currentDestination)) {
// onResult(SmileIDResult.Error(OperationCanceledException("User cancelled")))
// }
// }
}
Loading

0 comments on commit 2ea9eff

Please sign in to comment.