Skip to content

Commit

Permalink
setting up enhanced biometric screens
Browse files Browse the repository at this point in the history
  • Loading branch information
jumaallan committed Dec 17, 2024
1 parent b4ae365 commit a0a2832
Show file tree
Hide file tree
Showing 10 changed files with 395 additions and 4 deletions.
8 changes: 4 additions & 4 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
SmileId_kotlinVersion=2.0.0
SmileId_minSdkVersion=21
SmileId_targetSdkVersion=34
SmileId_compileSdkVersion=34
SmileId_targetSdkVersion=35
SmileId_compileSdkVersion=35
SmileId_ndkversion=21.4.7075529
SmileId_androidVersion=10.3.7
SmileId_kotlinCompilerExtensionVersion=1.5.11
SmileId_androidVersion=10.4.0
#SmileId_kotlinCompilerExtensionVersion=1.5.11
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import com.smileidentity.react.viewmanagers.SmileIDDocumentCaptureViewManager
import com.smileidentity.react.viewmanagers.SmileIDDocumentVerificationViewManager
import com.smileidentity.react.viewmanagers.SmileIDEnhancedDocumentVerificationViewManager
import com.smileidentity.react.viewmanagers.SmileIDSmartSelfieAuthenticationViewManager
import com.smileidentity.react.viewmanagers.SmileIDSmartSelfieAuthenticationEnhancedViewManager
import com.smileidentity.react.viewmanagers.SmileIDSmartSelfieCaptureViewManager
import com.smileidentity.react.viewmanagers.SmileIDSmartSelfieEnrollmentViewManager
import com.smileidentity.react.viewmanagers.SmileIDSmartSelfieEnrollmentEnhancedViewManager
import com.smileidentity.react.views.SmileIDDocumentCaptureView

class SmileIdPackage : TurboReactPackage() {
Expand All @@ -24,6 +26,8 @@ class SmileIdPackage : TurboReactPackage() {
SmileIDDocumentCaptureViewManager(reactContext),
SmileIDSmartSelfieEnrollmentViewManager(reactContext),
SmileIDSmartSelfieAuthenticationViewManager(reactContext),
SmileIDSmartSelfieEnrollmentEnhancedViewManager(reactContext),
SmileIDSmartSelfieAuthenticationEnhancedViewManager(reactContext),
SmileIDDocumentVerificationViewManager(reactContext),
SmileIDEnhancedDocumentVerificationViewManager(reactContext),
SmileIDConsentViewManager(reactContext),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.smileidentity.react.viewmanagers

import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReadableArray
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.getImmutableMapOrDefault
import com.smileidentity.react.utils.getStringOrDefault
import com.smileidentity.react.views.SmileIDSmartSelfieAuthenticationEnhancedView

@ReactModule(name = SmileIDSmartSelfieAuthenticationEnhancedViewManager.NAME)
class SmileIDSmartSelfieAuthenticationEnhancedViewManager(
private val reactApplicationContext: ReactApplicationContext
) : SimpleViewManager<SmileIDSmartSelfieAuthenticationEnhancedView>() {

override fun getName(): String = NAME

override fun getExportedCustomBubblingEventTypeConstants(): Map<String, Any> {
return mapOf(
"onSmileResult" to mapOf(
"phasedRegistrationNames" to mapOf(
"bubbled" to "onResult"
)
)
)
}

override fun getCommandsMap(): Map<String, Int> {
return mapOf("setParams" to COMMAND_SET_PARAMS)
}

override fun receiveCommand(
view: SmileIDSmartSelfieAuthenticationEnhancedView,
commandId: String?,
args: ReadableArray?
) {
super.receiveCommand(view, commandId, args)
when (commandId?.toInt()) {
COMMAND_SET_PARAMS -> {
// Extract params from args and apply to view
val params = args?.getMap(0)
params?.let {
view.extraPartnerParams = params.getImmutableMapOrDefault("extraPartnerParams")
view.userId = params.getStringOrDefault("userId")
view.showAttribution = params.getBoolOrDefault("showAttribution", true)
view.showInstructions = params.getBoolOrDefault("showInstructions", true)
view.allowNewEnroll = params.getBoolOrDefault("allowNewEnroll", false)
view.renderContent()
}
}
}
}

override fun createViewInstance(p0: ThemedReactContext): SmileIDSmartSelfieAuthenticationEnhancedView {
return SmileIDSmartSelfieAuthenticationEnhancedView(reactApplicationContext)
}

companion object {
const val NAME = "SmileIDSmartSelfieAuthenticationEnhancedView"
const val COMMAND_SET_PARAMS = 2
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.smileidentity.react.viewmanagers

import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReadableArray
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.getImmutableMapOrDefault
import com.smileidentity.react.utils.getStringOrDefault
import com.smileidentity.react.views.SmileIDSmartSelfieEnrollmentEnhancedView

@ReactModule(name = SmileIDSmartSelfieEnrollmentEnhancedViewManager.NAME)
class SmileIDSmartSelfieEnrollmentEnhancedViewManager(
private val reactApplicationContext: ReactApplicationContext
) : SimpleViewManager<SmileIDSmartSelfieEnrollmentEnhancedView>() {

override fun getName(): String = NAME

override fun getExportedCustomBubblingEventTypeConstants(): Map<String, Any> {
return mapOf(
"onSmileResult" to mapOf(
"phasedRegistrationNames" to mapOf(
"bubbled" to "onResult"
)
)
)
}

override fun getCommandsMap(): Map<String, Int> {
return mapOf("setParams" to COMMAND_SET_PARAMS)
}

override fun receiveCommand(
view: SmileIDSmartSelfieEnrollmentEnhancedView,
commandId: String?,
args: ReadableArray?
) {
super.receiveCommand(view, commandId, args)
when (commandId?.toInt()) {
COMMAND_SET_PARAMS -> {
// Extract params from args and apply to view
val params = args?.getMap(0)
params?.let {
view.extraPartnerParams = params.getImmutableMapOrDefault("extraPartnerParams")
view.userId = params.getStringOrDefault("userId")
view.showAttribution = params.getBoolOrDefault("showAttribution", true)
view.showInstructions = params.getBoolOrDefault("showInstructions", true)
view.allowNewEnroll = params.getBoolOrDefault("allowNewEnroll", false)
view.renderContent()
}
}
}
}

override fun createViewInstance(p0: ThemedReactContext): SmileIDSmartSelfieEnrollmentEnhancedView {
return SmileIDSmartSelfieEnrollmentEnhancedView(reactApplicationContext)
}

companion object {
const val NAME = "SmileIDSmartSelfieEnrollmentEnhancedView"
const val COMMAND_SET_PARAMS = 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.smileidentity.react.views

import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.lifecycle.viewmodel.compose.LocalViewModelStoreOwner
import com.facebook.react.bridge.ReactApplicationContext
import com.smileidentity.SmileID
import com.smileidentity.compose.SmartSelfieAuthenticationEnhanced
import com.smileidentity.react.results.SmartSelfieCaptureResult
import com.smileidentity.react.utils.SelfieCaptureResultAdapter
import com.smileidentity.results.SmileIDResult
import com.smileidentity.util.randomUserId
import kotlinx.collections.immutable.toImmutableMap

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

override fun renderContent() {
composeView.apply {
val customViewModelStoreOwner = CustomViewModelStoreOwner()
setContent {
CompositionLocalProvider(LocalViewModelStoreOwner provides customViewModelStoreOwner) {
SmileID.SmartSelfieAuthenticationEnhanced(
userId = userId ?: rememberSaveable { randomUserId() },
allowNewEnroll = allowNewEnroll ?: false,
showAttribution = showAttribution,
showInstructions = showInstructions,
extraPartnerParams = extraPartnerParams,
) { res ->
when (res) {
is SmileIDResult.Success -> {
// val result =
// SmartSelfieCaptureResult(
// selfieFile = res.data.selfieFile,
// livenessFiles = res.data.livenessFiles,
// apiResponse = res.data.apiResponse,
// )
// val newMoshi =
// SmileID.moshi
// .newBuilder()
// .add(SelfieCaptureResultAdapter.FACTORY)
// .build()
// val json =
// try {
// newMoshi
// .adapter(SmartSelfieCaptureResult::class.java)
// .toJson(result)
// } catch (e: Exception) {
// emitFailure(e)
// return@SmartSelfieAuthentication
// }
// json?.let { js ->
// emitSuccess(js)
// }
}

is SmileIDResult.Error -> emitFailure(res.throwable)
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.smileidentity.react.views

import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.lifecycle.viewmodel.compose.LocalViewModelStoreOwner
import com.facebook.react.bridge.ReactApplicationContext
import com.smileidentity.SmileID
import com.smileidentity.compose.SmartSelfieEnrollmentEnhanced
import com.smileidentity.react.results.SmartSelfieCaptureResult
import com.smileidentity.react.utils.SelfieCaptureResultAdapter
import com.smileidentity.results.SmileIDResult
import com.smileidentity.util.randomUserId
import kotlinx.collections.immutable.toImmutableMap

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

override fun renderContent() {
composeView.apply {
setContent {
val customViewModelStoreOwner = CustomViewModelStoreOwner()
CompositionLocalProvider(LocalViewModelStoreOwner provides customViewModelStoreOwner) {
SmileID.SmartSelfieEnrollmentEnhanced(
userId = userId ?: rememberSaveable { randomUserId() },
allowNewEnroll = allowNewEnroll ?: false,
showAttribution = showAttribution,
showInstructions = showInstructions,
extraPartnerParams = extraPartnerParams,
) { res ->
when (res) {
is SmileIDResult.Success -> {
// val result =
// SmartSelfieCaptureResult(
// selfieFile = res.data.selfieFile,
// livenessFiles = res.data.livenessFiles,
// apiResponse = res.data.apiResponse,
// )
// val newMoshi =
// SmileID.moshi
// .newBuilder()
// .add(SelfieCaptureResultAdapter.FACTORY)
// .build()
// val json =
// try {
// newMoshi
// .adapter(SmartSelfieCaptureResult::class.java)
// .toJson(result)
// } catch (e: Exception) {
// emitFailure(e)
// return@SmartSelfieEnrollment
// }
// json?.let { js ->
// emitSuccess(js)
// }
}

is SmileIDResult.Error -> emitFailure(res.throwable)
}
}
}
}
}
}
}
34 changes: 34 additions & 0 deletions example/src/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import type {
DocumentVerificationRequest,
SmartSelfieAuthenticationRequest,
SmartSelfieEnrollmentRequest,
SmartSelfieAuthenticationRequestEnhanced,
SmartSelfieEnrollmentRequestEnhanced

Check failure on line 11 in example/src/HomeScreen.tsx

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
} from '@smile_identity/react-native';

import { SmileID } from '@smile_identity/react-native';
Expand Down Expand Up @@ -58,6 +60,14 @@ export const HomeScreen = ({ navigation }: { navigation: any }) => {
...defaultProductRef.current,
userId: 'user_0ffc7e8b-9b31-41bc-8131-03103a45d944',
});
const [smartSelfieEnrollmentEnhanced, setSmartSelfieEnrollmentEnhanced] =
useState<SmartSelfieEnrollmentRequestEnhanced>({
userId: 'user_0ffc7e8b-9b31-41bc-8131-03103a45d944',
})

Check failure on line 66 in example/src/HomeScreen.tsx

View workflow job for this annotation

GitHub Actions / lint

Insert `;`
const [smartSelfieAuthenticationEnhanced, setSmartSelfieAuthenticationEnhanced] =

Check failure on line 67 in example/src/HomeScreen.tsx

View workflow job for this annotation

GitHub Actions / lint

Replace `smartSelfieAuthenticationEnhanced,·setSmartSelfieAuthenticationEnhanced]·=` with `⏎····smartSelfieAuthenticationEnhanced,⏎····setSmartSelfieAuthenticationEnhanced,`
useState<SmartSelfieAuthenticationRequestEnhanced>({

Check failure on line 68 in example/src/HomeScreen.tsx

View workflow job for this annotation

GitHub Actions / lint

Replace `···` with `]·=`
userId: 'user_0ffc7e8b-9b31-41bc-8131-03103a45d944',

Check failure on line 69 in example/src/HomeScreen.tsx

View workflow job for this annotation

GitHub Actions / lint

Replace `········` with `····`
})

Check failure on line 70 in example/src/HomeScreen.tsx

View workflow job for this annotation

GitHub Actions / lint

Replace `····})` with `});`
const [documentVerification, setDocumentVerification] =
useState<DocumentVerificationRequest>({
...defaultProductRef.current,
Expand Down Expand Up @@ -135,6 +145,20 @@ export const HomeScreen = ({ navigation }: { navigation: any }) => {
},
});

setSmartSelfieEnrollmentEnhanced({
userId: generateUuid('user_'),
allowNewEnroll: false,
showInstructions: true,
showAttribution: true,
})

Check failure on line 153 in example/src/HomeScreen.tsx

View workflow job for this annotation

GitHub Actions / lint

Insert `;`

setSmartSelfieAuthenticationEnhanced({
userId: 'user_0ffc7e8b-9b31-41bc-8131-03103a45d944',
allowNewEnroll: false,
showInstructions: true,
showAttribution: true,
})

Check failure on line 160 in example/src/HomeScreen.tsx

View workflow job for this annotation

GitHub Actions / lint

Insert `;`

setDocumentVerification({
...defaultProductRef.current,
countryCode: 'ZW',
Expand Down Expand Up @@ -186,6 +210,14 @@ export const HomeScreen = ({ navigation }: { navigation: any }) => {
title: 'SmartSelfie Authentication',
product: smartSelfieAuthentication,
},
{
title: 'SmartSelfie Enrollment (Enhanced)',
product: smartSelfieEnrollmentEnhanced,
},
{
title: 'SmartSelfie Authentication (Enhanced)',
product: smartSelfieAuthenticationEnhanced,
},
{
title: 'Document Verification',
product: documentVerification,
Expand All @@ -208,6 +240,8 @@ export const HomeScreen = ({ navigation }: { navigation: any }) => {
documentCapture,
smartSelfieEnrollment,
smartSelfieAuthentication,
smartSelfieEnrollmentEnhanced,
smartSelfieAuthenticationEnhanced,
documentVerification,
biometricKYC,
consentScreen,
Expand Down
4 changes: 4 additions & 0 deletions example/src/types/Product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import type {
SmileIDViewProps,
SmartSelfieEnrollmentRequest,
SmartSelfieAuthenticationRequest,
SmartSelfieEnrollmentRequestEnhanced,
SmartSelfieAuthenticationRequestEnhanced,
BiometricKYCRequest,
ConsentRequest,
} from '@smile_identity/react-native';
Expand All @@ -15,6 +17,8 @@ export type Product = {
| DocumentVerificationRequest
| SmartSelfieEnrollmentRequest
| SmartSelfieAuthenticationRequest
| SmartSelfieEnrollmentRequestEnhanced
| SmartSelfieAuthenticationRequestEnhanced
| BiometricKYCRequest
| SmileIDViewProps
| ConsentRequest;
Expand Down
Loading

0 comments on commit a0a2832

Please sign in to comment.