diff --git a/CHANGES.md b/CHANGES.md index a8af002..c501b6c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,9 @@ # Changelog +# 4.1.1 + +- Fix: back button should cancel hCaptcha in compose-sdk + # 4.1.0 - Feat: preload WebView on `setup` call diff --git a/compose-sdk/build.gradle b/compose-sdk/build.gradle index 1b7b0c4..be28f31 100644 --- a/compose-sdk/build.gradle +++ b/compose-sdk/build.gradle @@ -20,11 +20,11 @@ android { // See https://developer.android.com/studio/publish/versioning // versionCode must be integer and be incremented by one for every new update // android system uses this to prevent downgrades - versionCode 45 + versionCode 46 // version number visible to the user // should follow semantic versioning (See https://semver.org) - versionName "4.1.0" + versionName "4.1.1" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles "consumer-rules.pro" diff --git a/compose-sdk/src/main/java/com/hcaptcha/sdk/HCaptchaCompose.kt b/compose-sdk/src/main/java/com/hcaptcha/sdk/HCaptchaCompose.kt index 553af84..e153787 100644 --- a/compose-sdk/src/main/java/com/hcaptcha/sdk/HCaptchaCompose.kt +++ b/compose-sdk/src/main/java/com/hcaptcha/sdk/HCaptchaCompose.kt @@ -2,17 +2,24 @@ package com.hcaptcha.sdk import android.os.Handler import android.os.Looper +import androidx.compose.foundation.clickable +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.size import androidx.compose.runtime.Composable +import androidx.compose.runtime.DisposableEffect +import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.unit.dp import androidx.compose.ui.viewinterop.AndroidView import androidx.compose.ui.window.Dialog -import androidx.compose.ui.window.DialogProperties @Composable public fun HCaptchaCompose(config: HCaptchaConfig, onResult: (HCaptchaResponse) -> Unit) { @@ -29,25 +36,46 @@ public fun HCaptchaCompose(config: HCaptchaConfig, onResult: (HCaptchaResponse) helper.value = HCaptchaWebViewHelper( handler, context, config, internalConfig, verifier, this ) + } } + var dismissed by remember { mutableStateOf(false) } HCaptchaLog.d("HCaptchaCompose($config)") + DisposableEffect(dismissed) { + onDispose { + if (dismissed) { + verifier.onFailure(HCaptchaException(HCaptchaError.CHALLENGE_CLOSED)); + helper.value?.destroy() + } + } + } + if (config.hideDialog) { AndroidView( modifier = Modifier.size(0.dp), factory = { preloadedWebView } ) - } else { + } else if (!dismissed) { Dialog( - onDismissRequest = {}, - properties = DialogProperties(usePlatformDefaultWidth = false) + onDismissRequest = { dismissed = true } ) { - AndroidView( - modifier = Modifier.fillMaxSize(), - factory = { preloadedWebView } - ) + Column( + modifier = Modifier + .fillMaxSize() + .clickable( + interactionSource = MutableInteractionSource(), + indication = null, + onClick = { dismissed = true } + ), + verticalArrangement = Arrangement.Center, + horizontalAlignment = Alignment.CenterHorizontally + ) { + AndroidView( + factory = { preloadedWebView } + ) + } } } } \ No newline at end of file diff --git a/sdk/build.gradle b/sdk/build.gradle index 8413d4c..95e2973 100644 --- a/sdk/build.gradle +++ b/sdk/build.gradle @@ -28,11 +28,11 @@ android { // See https://developer.android.com/studio/publish/versioning // versionCode must be integer and be incremented by one for every new update // android system uses this to prevent downgrades - versionCode 45 + versionCode 46 // version number visible to the user // should follow semantic versioning (See https://semver.org) - versionName "4.1.0" + versionName "4.1.1" buildConfigField 'String', 'VERSION_NAME', "\"${defaultConfig.versionName}_${defaultConfig.versionCode}\""