Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert Navigation Changes #524

Merged
merged 5 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
295 changes: 111 additions & 184 deletions lib/src/main/java/com/smileidentity/compose/SmileIDExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,29 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.painter.Painter
import androidx.lifecycle.viewmodel.compose.viewModel
import com.smileidentity.SmileID
import com.smileidentity.compose.biometric.OrchestratedBiometricKYCScreen
import com.smileidentity.compose.components.LocalMetadata
import com.smileidentity.compose.components.SmileThemeSurface
import com.smileidentity.compose.consent.OrchestratedConsentScreen
import com.smileidentity.compose.consent.bvn.OrchestratedBvnConsentScreen
import com.smileidentity.compose.nav.BaseSmileIDScreen
import com.smileidentity.compose.nav.BiometricKYCParams
import com.smileidentity.compose.nav.DocumentCaptureParams
import com.smileidentity.compose.nav.OrchestratedBiometricCaptureParams
import com.smileidentity.compose.nav.OrchestratedDocumentParams
import com.smileidentity.compose.nav.OrchestratedSelfieCaptureParams
import com.smileidentity.compose.nav.ResultCallbacks
import com.smileidentity.compose.nav.Routes
import com.smileidentity.compose.nav.SelfieCaptureParams
import com.smileidentity.compose.nav.SerializableFile
import com.smileidentity.compose.nav.getDocumentCaptureRoute
import com.smileidentity.compose.nav.getSelfieCaptureRoute
import com.smileidentity.compose.document.OrchestratedDocumentVerificationScreen
import com.smileidentity.compose.selfie.OrchestratedSelfieCaptureScreen
import com.smileidentity.compose.theme.colorScheme
import com.smileidentity.compose.theme.typography
import com.smileidentity.models.IdInfo
import com.smileidentity.models.JobType
import com.smileidentity.results.BiometricKycResult
import com.smileidentity.results.DocumentVerificationResult
import com.smileidentity.results.EnhancedDocumentVerificationResult
import com.smileidentity.results.SmartSelfieResult
import com.smileidentity.results.SmileIDCallback
import com.smileidentity.util.randomJobId
import com.smileidentity.util.randomUserId
import com.smileidentity.viewmodel.document.DocumentVerificationViewModel
import com.smileidentity.viewmodel.document.EnhancedDocumentVerificationViewModel
import com.smileidentity.viewmodel.viewModelFactory
import java.io.File
import java.net.URL
import kotlinx.collections.immutable.ImmutableMap
Expand All @@ -56,8 +53,6 @@ import kotlinx.collections.immutable.persistentMapOf
* front camera will be used.
* @param showAttribution Whether to show the Smile ID attribution or not on the Instructions screen
* @param showInstructions Whether to deactivate capture screen's instructions for SmartSelfie.
* @param useStrictMode Whether to use strict mode or not. Strict mode enables an advanced, more
* secure, and more accurate UX for higher pass rates. [showInstructions] will be ignored
* @param extraPartnerParams Custom values specific to partners
* @param colorScheme The color scheme to use for the UI. This is passed in so that we show a Smile
* ID branded UI by default, but allow the user to override it if they want.
Expand All @@ -74,44 +69,25 @@ fun SmileID.SmartSelfieEnrollment(
allowAgentMode: Boolean = false,
showAttribution: Boolean = true,
showInstructions: Boolean = true,
useStrictMode: Boolean = false,
extraPartnerParams: ImmutableMap<String, String> = persistentMapOf(),
skipApiSubmission: Boolean = false,
colorScheme: ColorScheme = SmileID.colorScheme,
typography: Typography = SmileID.typography,
onResult: SmileIDCallback<SmartSelfieResult> = {},
) {
// TODO: Eventually use the new UI even for nonStrictMode, but with active liveness disabled
val commonParams = SelfieCaptureParams(
userId = userId,
jobId = jobId,
allowNewEnroll = allowNewEnroll,
allowAgentMode = allowAgentMode,
showAttribution = showAttribution,
showInstructions = showInstructions,
extraPartnerParams = extraPartnerParams,
isEnroll = true,
skipApiSubmission = skipApiSubmission,
)
val screenDestination = getSelfieCaptureRoute(
useStrictMode = useStrictMode,
params = commonParams,
)
val orchestratedDestination = Routes.Orchestrated.SelfieRoute(
params = OrchestratedSelfieCaptureParams(
captureParams = commonParams,
startRoute = screenDestination,
showStartRoute = true,
),
)
BaseSmileIDScreen(
orchestratedDestination = orchestratedDestination,
screenDestination = screenDestination,
resultCallbacks = ResultCallbacks(onSmartSelfieResult = onResult),
modifier = modifier,
colorScheme = colorScheme,
typography = typography,
)
SmileThemeSurface(colorScheme = colorScheme, typography = typography) {
OrchestratedSelfieCaptureScreen(
modifier = modifier,
userId = userId,
jobId = jobId,
allowNewEnroll = allowNewEnroll,
isEnroll = true,
allowAgentMode = allowAgentMode,
showAttribution = showAttribution,
showInstructions = showInstructions,
extraPartnerParams = extraPartnerParams,
onResult = onResult,
)
}
}

/**
Expand All @@ -130,8 +106,6 @@ fun SmileID.SmartSelfieEnrollment(
* front camera will be used.
* @param showAttribution Whether to show the Smile ID attribution or not on the Instructions screen
* @param showInstructions Whether to deactivate capture screen's instructions for SmartSelfie.
* @param useStrictMode Whether to use strict mode or not. Strict mode enables an advanced, more
* secure, and more accurate UX for higher pass rates. [showInstructions] will be ignored
* @param extraPartnerParams Custom values specific to partners
* @param colorScheme The color scheme to use for the UI. This is passed in so that we show a Smile
* ID branded UI by default, but allow the user to override it if they want.
Expand All @@ -148,41 +122,25 @@ fun SmileID.SmartSelfieAuthentication(
allowAgentMode: Boolean = false,
showAttribution: Boolean = true,
showInstructions: Boolean = true,
useStrictMode: Boolean = false,
extraPartnerParams: ImmutableMap<String, String> = persistentMapOf(),
skipApiSubmission: Boolean = false,
colorScheme: ColorScheme = SmileID.colorScheme,
typography: Typography = SmileID.typography,
onResult: SmileIDCallback<SmartSelfieResult> = {},
) {
// TODO: Eventually use the new UI even for nonStrictMode, but with active liveness disabled
val commonParams = SelfieCaptureParams(
userId,
jobId,
allowNewEnroll,
allowAgentMode,
showAttribution,
showInstructions,
extraPartnerParams,
isEnroll = false,
skipApiSubmission,
)
val screenDestination = getSelfieCaptureRoute(useStrictMode, commonParams)
val orchestratedDestination = Routes.Orchestrated.SelfieRoute(
params = OrchestratedSelfieCaptureParams(
commonParams,
startRoute = screenDestination,
showStartRoute = true,
),
)
BaseSmileIDScreen(
orchestratedDestination,
screenDestination,
ResultCallbacks(onSmartSelfieResult = onResult),
modifier,
colorScheme,
typography,
)
SmileThemeSurface(colorScheme = colorScheme, typography = typography) {
OrchestratedSelfieCaptureScreen(
modifier = modifier,
userId = userId,
jobId = jobId,
allowNewEnroll = allowNewEnroll,
isEnroll = false,
allowAgentMode = allowAgentMode,
showAttribution = showAttribution,
showInstructions = showInstructions,
extraPartnerParams = extraPartnerParams,
onResult = onResult,
)
}
}

/**
Expand Down Expand Up @@ -234,42 +192,41 @@ fun SmileID.DocumentVerification(
allowAgentMode: Boolean = false,
allowGalleryUpload: Boolean = false,
showInstructions: Boolean = true,
skipApiSubmission: Boolean = false,
extraPartnerParams: ImmutableMap<String, String> = persistentMapOf(),
colorScheme: ColorScheme = SmileID.colorScheme,
typography: Typography = SmileID.typography,
onResult: SmileIDCallback<DocumentVerificationResult> = {},
) {
val commonParams = DocumentCaptureParams(
userId = userId,
jobId = jobId,
showInstructions = showInstructions,
showAttribution = showAttribution,
allowAgentMode = allowAgentMode,
allowGallerySelection = allowGalleryUpload,
knownIdAspectRatio = idAspectRatio,
allowNewEnroll = allowNewEnroll,
countryCode = countryCode,
documentType = documentType,
captureBothSides = captureBothSides,
skipApiSubmission = skipApiSubmission,
selfieFile = bypassSelfieCaptureWithFile?.let { SerializableFile.fromFile(it) },
extraPartnerParams = extraPartnerParams,
)
val screenDestination = getDocumentCaptureRoute(
commonParams,
)
val orchestratedDestination = Routes.Orchestrated.DocVRoute(
params = OrchestratedDocumentParams(commonParams),
)
BaseSmileIDScreen(
orchestratedDestination,
screenDestination,
ResultCallbacks(onDocVResult = onResult),
modifier,
colorScheme,
typography,
)
SmileThemeSurface(colorScheme = colorScheme, typography = typography) {
val metadata = LocalMetadata.current
OrchestratedDocumentVerificationScreen(
modifier = modifier,
userId = userId,
jobId = jobId,
showAttribution = showAttribution,
allowAgentMode = allowAgentMode,
allowGalleryUpload = allowGalleryUpload,
showInstructions = showInstructions,
idAspectRatio = idAspectRatio,
onResult = onResult,
viewModel = viewModel(
factory = viewModelFactory {
DocumentVerificationViewModel(
jobType = JobType.DocumentVerification,
userId = userId,
jobId = jobId,
allowNewEnroll = allowNewEnroll,
countryCode = countryCode,
documentType = documentType,
captureBothSides = captureBothSides,
selfieFile = bypassSelfieCaptureWithFile,
extraPartnerParams = extraPartnerParams,
metadata = metadata,
)
},
),
)
}
}

/**
Expand Down Expand Up @@ -322,42 +279,41 @@ fun SmileID.EnhancedDocumentVerificationScreen(
allowAgentMode: Boolean = false,
allowGalleryUpload: Boolean = false,
showInstructions: Boolean = true,
skipApiSubmission: Boolean = false,
extraPartnerParams: ImmutableMap<String, String> = persistentMapOf(),
colorScheme: ColorScheme = SmileID.colorScheme,
typography: Typography = SmileID.typography,
onResult: SmileIDCallback<EnhancedDocumentVerificationResult> = {},
) {
val commonParams = DocumentCaptureParams(
userId = userId,
jobId = jobId,
showInstructions = showInstructions,
showAttribution = showAttribution,
allowAgentMode = allowAgentMode,
allowGallerySelection = allowGalleryUpload,
knownIdAspectRatio = idAspectRatio,
allowNewEnroll = allowNewEnroll,
countryCode = countryCode,
documentType = documentType,
captureBothSides = captureBothSides,
skipApiSubmission = skipApiSubmission,
selfieFile = bypassSelfieCaptureWithFile?.let { SerializableFile.fromFile(it) },
extraPartnerParams = extraPartnerParams,
)
val screenDestination = getDocumentCaptureRoute(
commonParams,
)
val orchestratedDestination = Routes.Orchestrated.EnhancedDocVRoute(
params = OrchestratedDocumentParams(commonParams),
)
BaseSmileIDScreen(
orchestratedDestination,
screenDestination,
ResultCallbacks(onEnhancedDocVResult = onResult),
modifier,
colorScheme,
typography,
)
SmileThemeSurface(colorScheme = colorScheme, typography = typography) {
val metadata = LocalMetadata.current
OrchestratedDocumentVerificationScreen(
modifier = modifier,
userId = userId,
jobId = jobId,
showAttribution = showAttribution,
allowAgentMode = allowAgentMode,
allowGalleryUpload = allowGalleryUpload,
showInstructions = showInstructions,
idAspectRatio = idAspectRatio,
onResult = onResult,
viewModel = viewModel(
factory = viewModelFactory {
EnhancedDocumentVerificationViewModel(
jobType = JobType.EnhancedDocumentVerification,
userId = userId,
jobId = jobId,
allowNewEnroll = allowNewEnroll,
countryCode = countryCode,
documentType = documentType,
captureBothSides = captureBothSides,
selfieFile = bypassSelfieCaptureWithFile,
extraPartnerParams = extraPartnerParams,
metadata = metadata,
)
},
),
)
}
}

/**
Expand Down Expand Up @@ -399,49 +355,20 @@ fun SmileID.BiometricKYC(
typography: Typography = SmileID.typography,
onResult: SmileIDCallback<BiometricKycResult> = {},
) {
val commonParams = SelfieCaptureParams(
userId,
jobId,
allowNewEnroll,
allowAgentMode,
showAttribution,
showInstructions,
extraPartnerParams,
true,
skipApiSubmission = true,
)
val selfieDestination = getSelfieCaptureRoute(false, commonParams)
val screenDestination = Routes.Orchestrated.SelfieRoute(
params = OrchestratedSelfieCaptureParams(
commonParams,
startRoute = selfieDestination,
showStartRoute = true,
),
)
val orchestratedDestination = Routes.Orchestrated.BiometricKycRoute(
OrchestratedBiometricCaptureParams(
BiometricKYCParams(
idInfo = idInfo,
userId = userId,
jobId = jobId,
showInstructions = showInstructions,
showAttribution = showAttribution,
allowAgentMode = allowAgentMode,
allowNewEnroll = allowNewEnroll,
extraPartnerParams = extraPartnerParams,
),
startRoute = screenDestination,
showStartRoute = true,
),
)
BaseSmileIDScreen(
orchestratedDestination,
selfieDestination,
ResultCallbacks(onBiometricKYCResult = onResult),
modifier,
colorScheme,
typography,
)
SmileThemeSurface(colorScheme = colorScheme, typography = typography) {
OrchestratedBiometricKYCScreen(
modifier = modifier,
idInfo = idInfo,
userId = userId,
jobId = jobId,
allowNewEnroll = allowNewEnroll,
allowAgentMode = allowAgentMode,
showAttribution = showAttribution,
showInstructions = showInstructions,
extraPartnerParams = extraPartnerParams,
onResult = onResult,
)
}
}

/**
Expand Down
Loading
Loading