Skip to content

Commit

Permalink
Migrate to Compose Fragments (#450)
Browse files Browse the repository at this point in the history
* migrate to new fragment compose wrapper

* updated CHANGELOG.md

* updated CHANGELOG.md
  • Loading branch information
jumaallan authored Sep 23, 2024
1 parent c7e2052 commit e3354bf
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 115 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
1 change: 1 addition & 0 deletions lib/lib.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 })
},
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 })
},
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 })
},
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 })
},
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 })
},
)
}
}

Expand Down

0 comments on commit e3354bf

Please sign in to comment.