From e3354bff83e930212d1347d8f149dfbf53185abf Mon Sep 17 00:00:00 2001 From: Juma Allan Date: Mon, 23 Sep 2024 20:02:33 +0300 Subject: [PATCH] Migrate to Compose Fragments (#450) * migrate to new fragment compose wrapper * updated CHANGELOG.md * updated CHANGELOG.md --- CHANGELOG.md | 1 + gradle/libs.versions.toml | 1 + lib/lib.gradle.kts | 1 + .../fragment/BiometricKYCFragment.kt | 36 ++++++-------- .../fragment/DocumentVerificationFragment.kt | 48 ++++++++----------- .../EnhancedDocumentVerificationFragment.kt | 48 ++++++++----------- .../SmartSelfieAuthenticationFragment.kt | 34 ++++++------- .../fragment/SmartSelfieEnrollmentFragment.kt | 34 ++++++------- 8 files changed, 88 insertions(+), 115 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e6c50ac5..0319cf61d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 10.3.0 * Changed initialize() to return a deferred result (allow partners to handle errors) +* Update to Compose Fragment and remove ComposeView ## 10.2.7 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 00b6c0d76..878da61a7 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -73,6 +73,7 @@ androidx-compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling androidx-core = { module = "androidx.core:core-ktx", version.ref = "androidx-core" } androidx-core-splashscreen = { group = "androidx.core", name = "core-splashscreen", version.ref = "androidx-core-splashscreen" } androidx-fragment = { module = "androidx.fragment:fragment-ktx", version.ref = "androidx-fragment" } +androidx-fragment-compose = { module = "androidx.fragment:fragment-compose", version.ref = "androidx-fragment" } androidx-lifecycle-runtime = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "androidx-lifecycle" } androidx-lifecycle-runtime-compose = { module = "androidx.lifecycle:lifecycle-runtime-compose", version.ref = "androidx-lifecycle" } androidx-lifecycle-viewmodel-compose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "androidx-lifecycle" } diff --git a/lib/lib.gradle.kts b/lib/lib.gradle.kts index b7e7422bd..7a164a802 100644 --- a/lib/lib.gradle.kts +++ b/lib/lib.gradle.kts @@ -160,6 +160,7 @@ dependencies { implementation(libs.androidx.core) implementation(libs.androidx.fragment) + implementation(libs.androidx.fragment.compose) implementation(libs.androidx.activity.compose) implementation(libs.androidx.annotation.experimental) diff --git a/lib/src/main/java/com/smileidentity/fragment/BiometricKYCFragment.kt b/lib/src/main/java/com/smileidentity/fragment/BiometricKYCFragment.kt index 3db635d09..caf0c95fe 100644 --- a/lib/src/main/java/com/smileidentity/fragment/BiometricKYCFragment.kt +++ b/lib/src/main/java/com/smileidentity/fragment/BiometricKYCFragment.kt @@ -3,10 +3,9 @@ package com.smileidentity.fragment import android.os.Bundle import android.view.LayoutInflater import android.view.ViewGroup -import androidx.compose.ui.platform.ComposeView -import androidx.compose.ui.platform.ViewCompositionStrategy import androidx.fragment.app.Fragment import androidx.fragment.app.setFragmentResult +import androidx.fragment.compose.content import com.smileidentity.SmileID import com.smileidentity.compose.BiometricKYC import com.smileidentity.fragment.BiometricKYCFragment.Companion.KEY_REQUEST @@ -108,26 +107,21 @@ class BiometricKYCFragment : Fragment() { inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?, - ) = ComposeView(requireContext()).apply { - // Dispose of the Composition when the view's LifecycleOwner is destroyed. see: - // https://developer.android.com/jetpack/compose/interop/interop-apis#compose-in-fragments - setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) + ) = content { val args = requireArguments() - setContent { - SmileID.BiometricKYC( - idInfo = args.idInfo, - userId = args.userId, - jobId = args.jobId, - allowNewEnroll = args.allowNewEnroll, - allowAgentMode = args.allowAgentMode, - showAttribution = args.showAttribution, - showInstructions = args.showInstructions, - extraPartnerParams = (args.extraPartnerParams ?: mapOf()).toImmutableMap(), - onResult = { - setFragmentResult(KEY_REQUEST, Bundle().apply { smileIDResult = it }) - }, - ) - } + SmileID.BiometricKYC( + idInfo = args.idInfo, + userId = args.userId, + jobId = args.jobId, + allowNewEnroll = args.allowNewEnroll, + allowAgentMode = args.allowAgentMode, + showAttribution = args.showAttribution, + showInstructions = args.showInstructions, + extraPartnerParams = (args.extraPartnerParams ?: mapOf()).toImmutableMap(), + onResult = { + setFragmentResult(KEY_REQUEST, Bundle().apply { smileIDResult = it }) + }, + ) } } diff --git a/lib/src/main/java/com/smileidentity/fragment/DocumentVerificationFragment.kt b/lib/src/main/java/com/smileidentity/fragment/DocumentVerificationFragment.kt index fe2f48199..39a4e005a 100644 --- a/lib/src/main/java/com/smileidentity/fragment/DocumentVerificationFragment.kt +++ b/lib/src/main/java/com/smileidentity/fragment/DocumentVerificationFragment.kt @@ -3,10 +3,9 @@ package com.smileidentity.fragment import android.os.Bundle import android.view.LayoutInflater import android.view.ViewGroup -import androidx.compose.ui.platform.ComposeView -import androidx.compose.ui.platform.ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed import androidx.fragment.app.Fragment import androidx.fragment.app.setFragmentResult +import androidx.fragment.compose.content import com.smileidentity.SmileID import com.smileidentity.compose.DocumentVerification import com.smileidentity.fragment.DocumentVerificationFragment.Companion.KEY_REQUEST @@ -115,32 +114,27 @@ class DocumentVerificationFragment : Fragment() { inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?, - ) = ComposeView(requireContext()).apply { - // Dispose of the Composition when the view's LifecycleOwner is destroyed. see: - // https://developer.android.com/jetpack/compose/interop/interop-apis#compose-in-fragments - setViewCompositionStrategy(DisposeOnViewTreeLifecycleDestroyed) + ) = content { val args = requireArguments() - setContent { - val aspectRatio = args.idAspectRatio - SmileID.DocumentVerification( - countryCode = args.countryCode, - documentType = args.documentType, - userId = args.userId, - jobId = args.jobId, - allowNewEnroll = args.allowNewEnroll, - showAttribution = args.showAttribution, - allowAgentMode = args.allowAgentMode, - allowGalleryUpload = args.allowGalleryUpload, - showInstructions = args.showInstructions, - idAspectRatio = if (aspectRatio > 0) aspectRatio else null, - captureBothSides = args.captureBothSides, - bypassSelfieCaptureWithFile = args.bypassSelfieCaptureWithFile, - extraPartnerParams = (args.extraPartnerParams ?: mapOf()).toImmutableMap(), - onResult = { - setFragmentResult(KEY_REQUEST, Bundle().apply { smileIDResult = it }) - }, - ) - } + val aspectRatio = args.idAspectRatio + SmileID.DocumentVerification( + countryCode = args.countryCode, + documentType = args.documentType, + userId = args.userId, + jobId = args.jobId, + allowNewEnroll = args.allowNewEnroll, + showAttribution = args.showAttribution, + allowAgentMode = args.allowAgentMode, + allowGalleryUpload = args.allowGalleryUpload, + showInstructions = args.showInstructions, + idAspectRatio = if (aspectRatio > 0) aspectRatio else null, + captureBothSides = args.captureBothSides, + bypassSelfieCaptureWithFile = args.bypassSelfieCaptureWithFile, + extraPartnerParams = (args.extraPartnerParams ?: mapOf()).toImmutableMap(), + onResult = { + setFragmentResult(KEY_REQUEST, Bundle().apply { smileIDResult = it }) + }, + ) } } diff --git a/lib/src/main/java/com/smileidentity/fragment/EnhancedDocumentVerificationFragment.kt b/lib/src/main/java/com/smileidentity/fragment/EnhancedDocumentVerificationFragment.kt index 142cd07ac..5c499ca38 100644 --- a/lib/src/main/java/com/smileidentity/fragment/EnhancedDocumentVerificationFragment.kt +++ b/lib/src/main/java/com/smileidentity/fragment/EnhancedDocumentVerificationFragment.kt @@ -3,10 +3,9 @@ package com.smileidentity.fragment import android.os.Bundle import android.view.LayoutInflater import android.view.ViewGroup -import androidx.compose.ui.platform.ComposeView -import androidx.compose.ui.platform.ViewCompositionStrategy import androidx.fragment.app.Fragment import androidx.fragment.app.setFragmentResult +import androidx.fragment.compose.content import com.smileidentity.SmileID import com.smileidentity.compose.EnhancedDocumentVerificationScreen import com.smileidentity.fragment.EnhancedDocumentVerificationFragment.Companion.KEY_REQUEST @@ -113,32 +112,27 @@ class EnhancedDocumentVerificationFragment : Fragment() { inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?, - ) = ComposeView(requireContext()).apply { - // Dispose of the Composition when the view's LifecycleOwner is destroyed. see: - // https://developer.android.com/jetpack/compose/interop/interop-apis#compose-in-fragments - setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) + ) = content { val args = requireArguments() - setContent { - val aspectRatio = args.idAspectRatio - SmileID.EnhancedDocumentVerificationScreen( - countryCode = args.countryCode, - documentType = args.documentType, - userId = args.userId, - jobId = args.jobId, - allowNewEnroll = args.allowNewEnroll, - showAttribution = args.showAttribution, - allowAgentMode = args.allowAgentMode, - allowGalleryUpload = args.allowGalleryUpload, - showInstructions = args.showInstructions, - captureBothSides = args.captureBothSides, - bypassSelfieCaptureWithFile = args.bypassSelfieCaptureWithFile, - idAspectRatio = if (aspectRatio > 0) aspectRatio else null, - extraPartnerParams = (args.extraPartnerParams ?: mapOf()).toImmutableMap(), - onResult = { - setFragmentResult(KEY_REQUEST, Bundle().apply { smileIDResult = it }) - }, - ) - } + val aspectRatio = args.idAspectRatio + SmileID.EnhancedDocumentVerificationScreen( + countryCode = args.countryCode, + documentType = args.documentType, + userId = args.userId, + jobId = args.jobId, + allowNewEnroll = args.allowNewEnroll, + showAttribution = args.showAttribution, + allowAgentMode = args.allowAgentMode, + allowGalleryUpload = args.allowGalleryUpload, + showInstructions = args.showInstructions, + captureBothSides = args.captureBothSides, + bypassSelfieCaptureWithFile = args.bypassSelfieCaptureWithFile, + idAspectRatio = if (aspectRatio > 0) aspectRatio else null, + extraPartnerParams = (args.extraPartnerParams ?: mapOf()).toImmutableMap(), + onResult = { + setFragmentResult(KEY_REQUEST, Bundle().apply { smileIDResult = it }) + }, + ) } } diff --git a/lib/src/main/java/com/smileidentity/fragment/SmartSelfieAuthenticationFragment.kt b/lib/src/main/java/com/smileidentity/fragment/SmartSelfieAuthenticationFragment.kt index 8f9ed0327..27fa072b9 100644 --- a/lib/src/main/java/com/smileidentity/fragment/SmartSelfieAuthenticationFragment.kt +++ b/lib/src/main/java/com/smileidentity/fragment/SmartSelfieAuthenticationFragment.kt @@ -3,10 +3,9 @@ package com.smileidentity.fragment import android.os.Bundle import android.view.LayoutInflater import android.view.ViewGroup -import androidx.compose.ui.platform.ComposeView -import androidx.compose.ui.platform.ViewCompositionStrategy import androidx.fragment.app.Fragment import androidx.fragment.app.setFragmentResult +import androidx.fragment.compose.content import com.smileidentity.SmileID import com.smileidentity.compose.SmartSelfieAuthentication import com.smileidentity.fragment.SmartSelfieAuthenticationFragment.Companion.KEY_REQUEST @@ -115,25 +114,20 @@ class SmartSelfieAuthenticationFragment : Fragment() { inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?, - ) = ComposeView(requireContext()).apply { - // Dispose of the Composition when the view's LifecycleOwner is destroyed. see: - // https://developer.android.com/jetpack/compose/interop/interop-apis#compose-in-fragments - setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) + ) = content { val args = requireArguments() - setContent { - SmileID.SmartSelfieAuthentication( - userId = args.userId, - jobId = args.jobId, - allowNewEnroll = args.allowNewEnroll, - allowAgentMode = args.allowAgentMode, - showAttribution = args.showAttribution, - showInstructions = args.showInstructions, - extraPartnerParams = (args.extraPartnerParams ?: mapOf()).toImmutableMap(), - onResult = { - setFragmentResult(KEY_REQUEST, Bundle().apply { smileIdResult = it }) - }, - ) - } + SmileID.SmartSelfieAuthentication( + userId = args.userId, + jobId = args.jobId, + allowNewEnroll = args.allowNewEnroll, + allowAgentMode = args.allowAgentMode, + showAttribution = args.showAttribution, + showInstructions = args.showInstructions, + extraPartnerParams = (args.extraPartnerParams ?: mapOf()).toImmutableMap(), + onResult = { + setFragmentResult(KEY_REQUEST, Bundle().apply { smileIdResult = it }) + }, + ) } } diff --git a/lib/src/main/java/com/smileidentity/fragment/SmartSelfieEnrollmentFragment.kt b/lib/src/main/java/com/smileidentity/fragment/SmartSelfieEnrollmentFragment.kt index fa960e4ca..088dc0ca1 100644 --- a/lib/src/main/java/com/smileidentity/fragment/SmartSelfieEnrollmentFragment.kt +++ b/lib/src/main/java/com/smileidentity/fragment/SmartSelfieEnrollmentFragment.kt @@ -3,10 +3,9 @@ package com.smileidentity.fragment import android.os.Bundle import android.view.LayoutInflater import android.view.ViewGroup -import androidx.compose.ui.platform.ComposeView -import androidx.compose.ui.platform.ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed import androidx.fragment.app.Fragment import androidx.fragment.app.setFragmentResult +import androidx.fragment.compose.content import com.smileidentity.SmileID import com.smileidentity.compose.SmartSelfieEnrollment import com.smileidentity.fragment.SmartSelfieEnrollmentFragment.Companion.KEY_REQUEST @@ -112,25 +111,20 @@ class SmartSelfieEnrollmentFragment : Fragment() { inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?, - ) = ComposeView(requireContext()).apply { - // Dispose of the Composition when the view's LifecycleOwner is destroyed. see: - // https://developer.android.com/jetpack/compose/interop/interop-apis#compose-in-fragments - setViewCompositionStrategy(DisposeOnViewTreeLifecycleDestroyed) + ) = content { val args = requireArguments() - setContent { - SmileID.SmartSelfieEnrollment( - userId = args.userId, - jobId = args.jobId, - allowNewEnroll = args.allowNewEnroll, - allowAgentMode = args.allowAgentMode, - showAttribution = args.showAttribution, - showInstructions = args.showInstructions, - extraPartnerParams = (args.extraPartnerParams ?: mapOf()).toImmutableMap(), - onResult = { - setFragmentResult(KEY_REQUEST, Bundle().apply { smileIdResult = it }) - }, - ) - } + SmileID.SmartSelfieEnrollment( + userId = args.userId, + jobId = args.jobId, + allowNewEnroll = args.allowNewEnroll, + allowAgentMode = args.allowAgentMode, + showAttribution = args.showAttribution, + showInstructions = args.showInstructions, + extraPartnerParams = (args.extraPartnerParams ?: mapOf()).toImmutableMap(), + onResult = { + setFragmentResult(KEY_REQUEST, Bundle().apply { smileIdResult = it }) + }, + ) } }