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

feat: skip api submission #76

Merged
merged 4 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
18 changes: 12 additions & 6 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ buildscript {
dependencies {
classpath "com.android.tools.build:gradle:8.3.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:compose-compiler-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
classpath "org.jlleitschuh.gradle:ktlint-gradle:12.1.1"
}
}
Expand All @@ -27,6 +29,8 @@ apply plugin: "com.android.library"
apply plugin: "kotlin-android"
apply plugin: 'kotlin-kapt'
apply plugin: "org.jlleitschuh.gradle.ktlint"
apply plugin: "org.jetbrains.kotlin.plugin.serialization"
apply plugin: "org.jetbrains.kotlin.plugin.compose"

def getExtOrDefault(name) {
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["SmileId_" + name]
Expand Down Expand Up @@ -97,7 +101,7 @@ android {

sourceSets {
main {
java.srcDirs += ["src/oldarch"]
java.srcDirs += ["src/oldarch"]
}
}
}
Expand All @@ -108,8 +112,8 @@ repositories {
gradlePluginPortal()
}

def kotlin_version = getExtOrDefault("kotlinVersion")
def smile_id_sdk_version = getExtOrDefault("androidVersion")
def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : getExtOrDefault("kotlinVersion")
def smile_id_sdk_version = rootProject.ext.has("androidVersion") ? rootProject.ext.get("androidVersion") : getExtOrDefault("androidVersion")

dependencies {
implementation "com.facebook.react:react-native:0.72"
Expand All @@ -119,14 +123,16 @@ dependencies {
implementation "com.google.mlkit:object-detection:17.0.2"
implementation "com.jakewharton.timber:timber"
implementation 'androidx.appcompat:appcompat:1.7.0'
implementation("androidx.navigation:navigation-compose:2.8.1")
implementation("androidx.lifecycle:lifecycle-runtime-compose:2.8.6")
implementation("androidx.navigation:navigation-compose:2.8.4")
implementation("androidx.lifecycle:lifecycle-runtime-compose:2.8.7")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.3")
implementation("androidx.compose.runtime:runtime:1.7.5")

testImplementation 'junit:junit:4.13.2'

androidTestImplementation 'androidx.test.ext:junit:1.2.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
androidTestImplementation platform('androidx.compose:compose-bom:2024.09.02')
androidTestImplementation platform('androidx.compose:compose-bom:2024.11.00')
androidTestImplementation 'androidx.compose.ui:ui-test-junit4'

debugImplementation 'androidx.compose.ui:ui-tooling'
Expand Down
2 changes: 1 addition & 1 deletion android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ SmileId_minSdkVersion=21
SmileId_targetSdkVersion=34
SmileId_compileSdkVersion=34
SmileId_ndkversion=21.4.7075529
SmileId_androidVersion=10.3.1
SmileId_androidVersion=10.3.7-SNAPSHOT
19 changes: 19 additions & 0 deletions android/src/main/java/com/smileidentity/react/utils/ReactUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import com.smileidentity.models.IdInfo
import com.smileidentity.models.JobType
import com.smileidentity.models.PartnerParams
import com.smileidentity.util.randomUserId
import kotlinx.collections.immutable.ImmutableMap
import kotlinx.collections.immutable.PersistentMap
import kotlinx.collections.immutable.persistentMapOf
import kotlinx.collections.immutable.toImmutableMap
import kotlinx.collections.immutable.toPersistentMap
import timber.log.Timber

fun ReadableMap.toMap(): Map<String, String> {
Expand Down Expand Up @@ -60,3 +65,17 @@ fun ReadableMap.getMapOrDefault(key: String, defaultValue: ReadableMap? = null):
}
return defaultValue
}

fun ReadableMap.getImmutableMapOrDefault(
key: String,
defaultValue: ImmutableMap<String, String> = persistentMapOf()
): ImmutableMap<String, String> {
return if (hasKey(key)) {
getMap(key)?.toHashMap()
?.mapValues { it.value?.toString() ?: "" }
?.toPersistentMap()
?: defaultValue
} else {
defaultValue
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import com.facebook.react.uimanager.SimpleViewManager
import com.facebook.react.uimanager.ThemedReactContext
import com.smileidentity.react.toIdInfo
import com.smileidentity.react.utils.getBoolOrDefault
import com.smileidentity.react.utils.getImmutableMapOrDefault
import com.smileidentity.react.utils.getStringOrDefault
import com.smileidentity.react.utils.toMap
import com.smileidentity.react.views.SmileIDBiometricKYCView

@ReactModule(name = SmileIDBiometricKYCViewManager.NAME)
Expand Down Expand Up @@ -47,7 +47,7 @@ class SmileIDBiometricKYCViewManager(
?: return view.emitFailure(IllegalArgumentException("idInfo is required to run Biometric KYC"))
val idInfo = idInfoMap.toIdInfo()
?: return view.emitFailure(IllegalArgumentException("idInfo is required to run Biometric KYC"))
view.extraPartnerParams = params.getMap("extraPartnerParams")?.toMap()
view.extraPartnerParams = params.getImmutableMapOrDefault("extraPartnerParams")
view.userId = params.getStringOrDefault("userId")
view.jobId = params.getStringOrDefault("jobId")
view.idInfo = idInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import com.facebook.react.module.annotations.ReactModule
import com.facebook.react.uimanager.SimpleViewManager
import com.facebook.react.uimanager.ThemedReactContext
import com.smileidentity.react.utils.getBoolOrDefault
import com.smileidentity.react.utils.getMapOrDefault
import com.smileidentity.react.utils.getImmutableMapOrDefault
import com.smileidentity.react.utils.getStringOrDefault
import com.smileidentity.react.utils.toMap
import com.smileidentity.react.views.SmileIDConsentView

@ReactModule(name = SmileIDConsentViewManager.NAME)
Expand Down Expand Up @@ -54,7 +53,7 @@ class SmileIDConsentViewManager(
val productName = params.getString("productName")
?: return view.emitFailure(IllegalArgumentException("productName is required to show Consent Screen"))

view.extraPartnerParams = params.getMapOrDefault("extraPartnerParams")?.toMap()
view.extraPartnerParams = params.getImmutableMapOrDefault("extraPartnerParams")
view.userId = params.getStringOrDefault("userId")
view.jobId = params.getStringOrDefault("jobId")
view.partnerName = partnerName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import com.facebook.react.uimanager.SimpleViewManager
import com.facebook.react.uimanager.ThemedReactContext
import com.smileidentity.react.utils.getBoolOrDefault
import com.smileidentity.react.utils.getFloatOrDefault
import com.smileidentity.react.utils.getMapOrDefault
import com.smileidentity.react.utils.getImmutableMapOrDefault
import com.smileidentity.react.utils.getStringOrDefault
import com.smileidentity.react.utils.toMap
import com.smileidentity.react.views.SmileIDDocumentVerificationView

@ReactModule(name = SmileIDDocumentVerificationViewManager.NAME)
Expand Down Expand Up @@ -46,7 +45,7 @@ class SmileIDDocumentVerificationViewManager(
params?.let {
val countryCode = params.getString("countryCode")
?: return view.emitFailure(IllegalArgumentException("countryCode is required to run Document Verification"))
view.extraPartnerParams = params.getMapOrDefault("extraPartnerParams")?.toMap()
view.extraPartnerParams = params.getImmutableMapOrDefault("extraPartnerParams")
view.userId = params.getStringOrDefault("userId")
view.jobId = params.getStringOrDefault("jobId")
view.countryCode = countryCode
Expand All @@ -59,6 +58,7 @@ class SmileIDDocumentVerificationViewManager(
view.documentType = params.getStringOrDefault("documentType", null)
view.idAspectRatio = params.getFloatOrDefault("idAspectRatio")
view.allowNewEnroll = params.getBoolOrDefault("allowNewEnroll", false)
view.skipApiSubmission = params.getBoolOrDefault("skipApiSubmission", false)
view.renderContent()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import com.facebook.react.uimanager.SimpleViewManager
import com.facebook.react.uimanager.ThemedReactContext
import com.smileidentity.react.utils.getBoolOrDefault
import com.smileidentity.react.utils.getFloatOrDefault
import com.smileidentity.react.utils.getMapOrDefault
import com.smileidentity.react.utils.getImmutableMapOrDefault
import com.smileidentity.react.utils.getStringOrDefault
import com.smileidentity.react.utils.toMap
import com.smileidentity.react.views.SmileIDEnhancedDocumentVerificationView

@ReactModule(name = SmileIDEnhancedDocumentVerificationViewManager.NAME)
Expand Down Expand Up @@ -46,7 +45,7 @@ class SmileIDEnhancedDocumentVerificationViewManager(
params?.let {
val countryCode = params.getString("countryCode")
?: return view.emitFailure(IllegalArgumentException("countryCode is required to run Enhanced Document Verification"))
view.extraPartnerParams = params.getMapOrDefault("extraPartnerParams")?.toMap()
view.extraPartnerParams = params.getImmutableMapOrDefault("extraPartnerParams")
view.userId = params.getStringOrDefault("userId")
view.jobId = params.getStringOrDefault("jobId")
view.countryCode = countryCode
Expand All @@ -58,6 +57,7 @@ class SmileIDEnhancedDocumentVerificationViewManager(
view.documentType = params.getStringOrDefault("documentType")
view.idAspectRatio = params.getFloatOrDefault("idAspectRatio")
view.allowNewEnroll = params.getBoolOrDefault("allowNewEnroll", false)
view.skipApiSubmission = params.getBoolOrDefault("skipApiSubmission", false)
view.renderContent()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import com.facebook.react.module.annotations.ReactModule
import com.facebook.react.uimanager.SimpleViewManager
import com.facebook.react.uimanager.ThemedReactContext
import com.smileidentity.react.utils.getBoolOrDefault
import com.smileidentity.react.utils.getMapOrDefault
import com.smileidentity.react.utils.getImmutableMapOrDefault
import com.smileidentity.react.utils.getStringOrDefault
import com.smileidentity.react.utils.toMap
import com.smileidentity.react.views.SmileIDSmartSelfieAuthenticationView

@ReactModule(name = SmileIDSmartSelfieAuthenticationViewManager.NAME)
Expand Down Expand Up @@ -43,13 +42,14 @@ class SmileIDSmartSelfieAuthenticationViewManager(
// Extract params from args and apply to view
val params = args?.getMap(0)
params?.let {
view.extraPartnerParams = params.getMapOrDefault("extraPartnerParams")?.toMap()
view.extraPartnerParams = params.getImmutableMapOrDefault("extraPartnerParams")
view.userId = params.getStringOrDefault("userId")
view.jobId = params.getStringOrDefault("jobId")
view.allowAgentMode = params.getBoolOrDefault("allowAgentMode", false)
view.showAttribution = params.getBoolOrDefault("showAttribution", true)
view.showInstructions = params.getBoolOrDefault("showInstructions", true)
view.allowNewEnroll = params.getBoolOrDefault("allowNewEnroll", false)
view.skipApiSubmission = params.getBoolOrDefault("skipApiSubmission", false)
view.renderContent()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import com.facebook.react.module.annotations.ReactModule
import com.facebook.react.uimanager.SimpleViewManager
import com.facebook.react.uimanager.ThemedReactContext
import com.smileidentity.react.utils.getBoolOrDefault
import com.smileidentity.react.utils.getMapOrDefault
import com.smileidentity.react.utils.getImmutableMapOrDefault
import com.smileidentity.react.utils.getStringOrDefault
import com.smileidentity.react.utils.toMap
import com.smileidentity.react.views.SmileIDSmartSelfieEnrollmentView

@ReactModule(name = SmileIDSmartSelfieEnrollmentViewManager.NAME)
Expand Down Expand Up @@ -43,13 +42,14 @@ class SmileIDSmartSelfieEnrollmentViewManager(
// Extract params from args and apply to view
val params = args?.getMap(0)
params?.let {
view.extraPartnerParams = params.getMapOrDefault("extraPartnerParams")?.toMap()
view.extraPartnerParams = params.getImmutableMapOrDefault("extraPartnerParams")
view.userId = params.getStringOrDefault("userId")
view.jobId = params.getStringOrDefault("jobId")
view.allowAgentMode = params.getBoolOrDefault("allowAgentMode", false)
view.showAttribution = params.getBoolOrDefault("showAttribution", true)
view.showInstructions = params.getBoolOrDefault("showInstructions", true)
view.allowNewEnroll = params.getBoolOrDefault("allowNewEnroll", false)
view.skipApiSubmission = params.getBoolOrDefault("skipApiSubmission", false)
view.renderContent()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import com.smileidentity.react.utils.SelfieCaptureResultAdapter
import com.smileidentity.results.SmileIDResult
import com.smileidentity.util.randomJobId
import com.smileidentity.util.randomUserId
import kotlinx.collections.immutable.toImmutableMap

class SmileIDBiometricKYCView(context: ReactApplicationContext) : SmileIDView(context) {
var idInfo: IdInfo? = null
Expand All @@ -34,7 +33,7 @@ class SmileIDBiometricKYCView(context: ReactApplicationContext) : SmileIDView(co
allowNewEnroll = allowNewEnroll ?: false,
showAttribution = showAttribution ?: true,
showInstructions = showInstructions ?: true,
extraPartnerParams = (extraPartnerParams ?: mapOf()).toImmutableMap(),
extraPartnerParams = extraPartnerParams,
) { res ->
when (res) {
is SmileIDResult.Success -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,10 @@ class SmileIDDocumentCaptureView(context: ReactApplicationContext) : SmileIDView
DocumentCaptureScreen(
jobId = jobId,
side = if (front) DocumentCaptureSide.Front else DocumentCaptureSide.Back,
showInstructions = showInstructions,
showAttribution = showAttribution,
allowGallerySelection = allowGalleryUpload,
showConfirmation = showConfirmation,
showSkipButton = false,
instructionsHeroImage = hero,
instructionsTitleText = stringResource(instructionTitle),
instructionsSubtitleText = stringResource(instructionSubTitle),
captureTitleText = stringResource(captureTitleText),
knownIdAspectRatio = idAspectRatio,
onConfirm = { file -> handleConfirmation(file) },
onError = { throwable -> emitFailure(throwable) },
onSkip = { }
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ class SmileIDDocumentVerificationView(context: ReactApplicationContext) : SmileI
allowGalleryUpload = allowGalleryUpload,
captureBothSides = captureBothSides,
allowNewEnroll = allowNewEnroll ?: false,
skipApiSubmission = skipApiSubmission,
bypassSelfieCaptureWithFile = bypassSelfieCaptureWithFile,
extraPartnerParams = (extraPartnerParams ?: mapOf()).toImmutableMap(),
extraPartnerParams = extraPartnerParams,
) { res ->
when (res) {
is SmileIDResult.Success -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class SmileIDEnhancedDocumentVerificationView(context: ReactApplicationContext)
allowNewEnroll = allowNewEnroll ?: false,
allowGalleryUpload = allowGalleryUpload,
captureBothSides = captureBothSides,
extraPartnerParams = (extraPartnerParams ?: mapOf()).toImmutableMap(),
skipApiSubmission = skipApiSubmission,
extraPartnerParams = extraPartnerParams,
) { res ->
when (res) {
is SmileIDResult.Success -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import com.smileidentity.compose.SmartSelfieAuthentication
import com.smileidentity.react.results.SmartSelfieCaptureResult
import com.smileidentity.react.utils.SelfieCaptureResultAdapter
import com.smileidentity.results.SmileIDResult
import com.smileidentity.util.randomJobId
import com.smileidentity.util.randomUserId
import kotlinx.collections.immutable.toImmutableMap

Expand All @@ -25,9 +24,10 @@ class SmileIDSmartSelfieAuthenticationView(context: ReactApplicationContext) :
userId = userId ?: rememberSaveable { randomUserId() },
allowAgentMode = allowAgentMode ?: false,
allowNewEnroll = allowNewEnroll ?: false,
showAttribution = showAttribution ?: true,
showInstructions = showInstructions ?: true,
extraPartnerParams = (extraPartnerParams ?: mapOf()).toImmutableMap(),
showAttribution = showAttribution,
showInstructions = showInstructions,
skipApiSubmission = skipApiSubmission,
extraPartnerParams = extraPartnerParams,
) { res ->
when (res) {
is SmileIDResult.Success -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ import com.smileidentity.compose.SmartSelfieEnrollment
import com.smileidentity.react.results.SmartSelfieCaptureResult
import com.smileidentity.react.utils.SelfieCaptureResultAdapter
import com.smileidentity.results.SmileIDResult
import com.smileidentity.util.randomJobId
import com.smileidentity.util.randomUserId
import kotlinx.collections.immutable.toImmutableMap

class SmileIDSmartSelfieEnrollmentView(context: ReactApplicationContext) : SmileIDView(context) {

override fun renderContent() {
composeView.apply {
val customViewModelStoreOwner = CustomViewModelStoreOwner()
setContent {
val customViewModelStoreOwner = CustomViewModelStoreOwner()
CompositionLocalProvider(LocalViewModelStoreOwner provides customViewModelStoreOwner) {
SmileID.SmartSelfieEnrollment(
userId = userId ?: rememberSaveable { randomUserId() },
allowAgentMode = allowAgentMode ?: false,
allowNewEnroll = allowNewEnroll ?: false,
showAttribution = showAttribution ?: true,
showInstructions = showInstructions ?: true,
extraPartnerParams = (extraPartnerParams ?: mapOf()).toImmutableMap(),
showAttribution = showAttribution,
showInstructions = showInstructions,
skipApiSubmission = skipApiSubmission,
extraPartnerParams = extraPartnerParams,
) { res ->
when (res) {
is SmileIDResult.Success -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactContext
import com.facebook.react.bridge.WritableMap
import com.facebook.react.uimanager.events.RCTEventEmitter
import com.smileidentity.SmileID
import com.smileidentity.models.JobType
import com.smileidentity.react.utils.DocumentCaptureResultAdapter
import kotlinx.collections.immutable.ImmutableMap
import kotlinx.collections.immutable.persistentMapOf
import timber.log.Timber

@SuppressLint("CheckResult")
Expand All @@ -25,8 +25,9 @@ abstract class SmileIDView(context: ReactApplicationContext) : LinearLayout(cont
var allowAgentMode: Boolean? = false
var allowNewEnroll: Boolean? = false
var showInstructions: Boolean = true
var skipApiSubmission: Boolean = false
var showAttribution: Boolean = true
var extraPartnerParams: Map<String, String>? = null
var extraPartnerParams: ImmutableMap<String, String> = persistentMapOf()
private var eventEmitter: RCTEventEmitter
private var productThrowable: Throwable? = null

Expand Down Expand Up @@ -112,3 +113,4 @@ abstract class SmileIDView(context: ReactApplicationContext) : LinearLayout(cont
}
}
}

2 changes: 2 additions & 0 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apply plugin: "com.android.application"
apply plugin: "com.facebook.react"
apply plugin: "kotlin-android"
apply plugin: "org.jlleitschuh.gradle.ktlint"
apply plugin: "org.jetbrains.kotlin.plugin.compose"
/**
* This is the configuration block to customize your React Native Android app.
* By default you don't need to apply any configuration, just uncomment the lines you need.
Expand Down Expand Up @@ -114,6 +115,7 @@ dependencies {
// The version of react-native is set by the React Native Gradle Plugin
implementation("com.facebook.react:react-android")
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation("androidx.compose.runtime:runtime:1.7.5")

if (hermesEnabled.toBoolean()) {
implementation("com.facebook.react:hermes-android")
Expand Down
Loading
Loading