diff --git a/identity-example/src/main/java/com/stripe/android/identity/example/ComposeExampleActivity.kt b/identity-example/src/main/java/com/stripe/android/identity/example/ComposeExampleActivity.kt index 28877b90509..5cea54da04b 100644 --- a/identity-example/src/main/java/com/stripe/android/identity/example/ComposeExampleActivity.kt +++ b/identity-example/src/main/java/com/stripe/android/identity/example/ComposeExampleActivity.kt @@ -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, @@ -114,40 +106,49 @@ abstract class ComposeExampleActivity : ComponentActivity() { mutableStateOf(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, diff --git a/identity/src/main/java/com/stripe/android/identity/IdentityVerificationSheet.kt b/identity/src/main/java/com/stripe/android/identity/IdentityVerificationSheet.kt index 13e66aae1c6..d429c35fbc2 100644 --- a/identity/src/main/java/com/stripe/android/identity/IdentityVerificationSheet.kt +++ b/identity/src/main/java/com/stripe/android/identity/IdentityVerificationSheet.kt @@ -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( @@ -114,7 +117,7 @@ interface IdentityVerificationSheet { IdentityVerificationSheetContract(), identityVerificationCallback::onVerificationFlowResult ) - return remember(configuration, identityVerificationCallback) { + return remember(configuration) { StripeIdentityVerificationSheet( activityResultLauncher, context,