Skip to content

Commit

Permalink
don't remember callback
Browse files Browse the repository at this point in the history
  • Loading branch information
ccen-stripe committed Aug 11, 2022
1 parent 129f5ea commit fa29c71
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 37 deletions.
Expand Up @@ -54,14 +54,6 @@ abstract class ComposeExampleActivity : ComponentActivity() {

private val viewModel: IdentityExampleViewModel by viewModels()

private val logoUri: Uri
get() = Uri.Builder()
.scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
.authority(resources.getResourcePackageName(getBrandLogoResId))
.appendPath(resources.getResourceTypeName(getBrandLogoResId))
.appendPath(resources.getResourceEntryName(getBrandLogoResId))
.build()

data class IdentitySubmissionState(
val shouldUseNativeSdk: Boolean = true,
val allowDrivingLicense: Boolean = true,
Expand Down Expand Up @@ -114,40 +106,49 @@ abstract class ComposeExampleActivity : ComponentActivity() {
mutableStateOf<LoadingState>(LoadingState.Idle)
}
var vsId by remember { mutableStateOf("") }
val identityVerificationSheet = IdentityVerificationSheet.rememberIdentityVerificationSheet(
configuration = IdentityVerificationSheet.Configuration(
val configuration = remember {
IdentityVerificationSheet.Configuration(
// Or use webImage by
// brandLogo = Uri.parse("https://path/to/a/logo.jpg")
brandLogo = logoUri
brandLogo = Uri.Builder()
.scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
.authority(resources.getResourcePackageName(getBrandLogoResId))
.appendPath(resources.getResourceTypeName(getBrandLogoResId))
.appendPath(resources.getResourceEntryName(getBrandLogoResId))
.build()
)
) { result ->
when (result) {
is IdentityVerificationSheet.VerificationFlowResult.Failed -> {
onLoadingStateChanged(
LoadingState.Result(
vsId = vsId,
resultString = "Verification result: ${result.javaClass.simpleName} - ${result.throwable}"
}
val identityVerificationSheet =
IdentityVerificationSheet.rememberIdentityVerificationSheet(
configuration = configuration
) { result ->
when (result) {
is IdentityVerificationSheet.VerificationFlowResult.Failed -> {
onLoadingStateChanged(
LoadingState.Result(
vsId = vsId,
resultString = "Verification result: ${result.javaClass.simpleName} - ${result.throwable}"
)
)
)
}
is IdentityVerificationSheet.VerificationFlowResult.Canceled -> {
onLoadingStateChanged(
LoadingState.Result(
vsId = vsId,
resultString = "Verification result: ${result.javaClass.simpleName}"
}
is IdentityVerificationSheet.VerificationFlowResult.Canceled -> {
onLoadingStateChanged(
LoadingState.Result(
vsId = vsId,
resultString = "Verification result: ${result.javaClass.simpleName}"
)
)
)
}
is IdentityVerificationSheet.VerificationFlowResult.Completed -> {
onLoadingStateChanged(
LoadingState.Result(
vsId = vsId,
resultString = "Verification result: ${result.javaClass.simpleName}"
}
is IdentityVerificationSheet.VerificationFlowResult.Completed -> {
onLoadingStateChanged(
LoadingState.Result(
vsId = vsId,
resultString = "Verification result: ${result.javaClass.simpleName}"
)
)
)
}
}
}
}

LoadVSView(
loadingState,
Expand Down
Expand Up @@ -101,8 +101,11 @@ interface IdentityVerificationSheet {
* Creates a [IdentityVerificationSheet] instance in a [Composable]. Which would be
* recreated if [configuration] or [identityVerificationCallback] changed.
*
* This API registers an [ActivityResultLauncher] into LocalContext.current and notifies its
* result to [identityVerificationCallback].
* This API uses Compose specific API [rememberLauncherForActivityResult] to register a
* [ActivityResultLauncher] into current activity, it should be called as part of Compose
* initialization path.
* The [IdentityVerificationSheet] created is remembered across recompositions.
* Recomposition will always return the value produced by composition.
*/
@Composable
fun rememberIdentityVerificationSheet(
Expand All @@ -114,7 +117,7 @@ interface IdentityVerificationSheet {
IdentityVerificationSheetContract(),
identityVerificationCallback::onVerificationFlowResult
)
return remember(configuration, identityVerificationCallback) {
return remember(configuration) {
StripeIdentityVerificationSheet(
activityResultLauncher,
context,
Expand Down

0 comments on commit fa29c71

Please sign in to comment.