Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: compose passive sitekey #165

Merged
merged 3 commits into from
Aug 21, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: update compose example to add hideDialog checkbox
CAMOBAP committed Aug 21, 2024

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
commit 888dfbe67f5612852af4f7fa945496388d078acc
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.runtime.*
import androidx.compose.material3.Button
import androidx.compose.material3.Checkbox
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
@@ -28,31 +29,49 @@ class ComposeActivity : ComponentActivity() {
setContent {
var hCaptchaStarted by remember { mutableStateOf(false) }
var hCaptchaLoaded by remember { mutableStateOf(false) }
var hideDialog by remember { mutableStateOf(false) }
var text by remember { mutableStateOf("") }

Column(
modifier = Modifier.fillMaxSize().padding(16.dp),
verticalArrangement = Arrangement.Bottom
) {
// Multiline Text
TextField(
value = text,
placeholder = { Text("Verification result will be here...") },
onValueChange = { newText -> text = newText },
modifier = Modifier
.fillMaxWidth()
.height(200.dp)
.background(Color.Gray)
)

Spacer(modifier = Modifier.weight(1f))

Row(
verticalAlignment = Alignment.CenterVertically
) {
Checkbox(
checked = hideDialog,
onCheckedChange = { isChecked ->
hideDialog = isChecked
}
)

Text(
text = "Hide Dialog (Passive Site Key)",
)
}

Button(
onClick = {
hCaptchaStarted = !hCaptchaStarted
},
modifier = Modifier
.fillMaxWidth()
.padding(top = 16.dp)
.padding(vertical = 16.dp)
) {
Text(text = "Toggle WebView")
Text(text = "Verify with HCaptcha")
}

if (hCaptchaStarted && !hCaptchaLoaded) {
@@ -68,11 +87,12 @@ class ComposeActivity : ComponentActivity() {
}
}

// WebView Dialog
if (hCaptchaStarted) {
HCaptchaCompose(HCaptchaConfig
.builder()
.siteKey("10000000-ffff-ffff-ffff-000000000001")
.hideDialog(hideDialog)
.diagnosticLog(true)
.build()) { result ->
when (result) {
is HCaptchaResponse.Success -> {
@@ -89,7 +109,7 @@ class ComposeActivity : ComponentActivity() {
}
is HCaptchaResponse.Event -> {
if (result.event == HCaptchaEvent.Opened) {
hCaptchaLoaded = true;
hCaptchaLoaded = true
}
println("Event: ${result.event}")
}