Skip to content

fix(compose-sdk): restore dialog dim after hidden loading#248

Merged
e271828- merged 3 commits intomainfrom
fix/alt_dimming
Mar 23, 2026
Merged

fix(compose-sdk): restore dialog dim after hidden loading#248
e271828- merged 3 commits intomainfrom
fix/alt_dimming

Conversation

@e271828-
Copy link
Copy Markdown
Contributor

Summary

This restores the Compose dialog dimming behavior for loading=false so it matches the existing View SDK semantics.

Intended behavior

  • If loading=false, the dialog should start without the dim-behind backdrop while the captcha is still hidden/loading.
  • If a visible checkbox is rendered, the dialog should regain its normal dimmed backdrop as soon as the checkbox is shown.
  • If an invisible flow escalates into a visible challenge, the dialog should regain its normal dimmed backdrop when that visible state is entered.
  • Existing behavior outside this transition should remain unchanged, including embedded rendering, dialog cancellation, and preloaded WebView reuse.

Implementation

  • Replace the window global-layout dim mutation with state-driven dim handling in Compose.
  • Restore dim on the same semantic transitions already used by the View SDK:
    • Loaded for checkbox sizes
    • Opened for invisible flows
  • Centralize the dialog window flag management in a helper that preserves the original window dim configuration and restores it on disposal.

Validation

Ran on the Medium_Phone emulator with normal Gradle instrumentation:

./gradlew :test:connectedDebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.hcaptcha.sdk.compose.HCaptchaComposeTest

Passed: 11/11 tests, 0 failures.

That includes coverage for:

  • loading=false remaining undimmed while the captcha is still hidden
  • dim restoration when a checkbox becomes visible
  • dim restoration when the invisible-flow visible state is entered
  • existing Compose dialog flows such as cancellation, back handling, custom host rendering, and preloaded WebView reuse

Keep Compose dialog dimming aligned with the View SDK when loading is disabled.

Intended behavior:
- If loading=false, the dialog should start without the dim-behind backdrop while the captcha is still hidden/loading.
- If a visible checkbox is rendered, the dialog should regain its normal dimmed backdrop as soon as the checkbox is shown.
- If an invisible flow escalates into a visible challenge, the dialog should regain its normal dimmed backdrop when that visible state is entered.
- Unchanged flows such as embedded rendering, dialog cancellation, and preloaded WebView reuse should keep their prior behavior.

Implementation:
- Track dialog dimming as Compose state instead of repeatedly mutating the window from a global layout listener.
- Restore dim on the same semantic transitions used by the View SDK: Loaded for checkbox sizes, Opened for invisible flows.
- Centralize window flag updates in a dialog setup helper that preserves and restores the window's original dim configuration.

Tests:
- Add emulator-backed coverage for the loading=false hidden state.
- Add emulator-backed coverage for dim restoration when a checkbox becomes visible.
- Add emulator-backed coverage for the invisible-flow dim restoration state transition.
- Preserve existing Compose behavior checks for embedded mode, dialog cancellation, and WebView reuse.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 19, 2026

Diffuse report:

OLD: sdk-main.aar
NEW: sdk-pr.aar

 AAR      │ old       │ new       │ diff 
──────────┼───────────┼───────────┼──────
      jar │  94.7 KiB │  94.7 KiB │ +4 B 
 manifest │     411 B │     411 B │  0 B 
      res │  28.3 KiB │  28.3 KiB │  0 B 
    other │     1 KiB │     1 KiB │  0 B 
──────────┼───────────┼───────────┼──────
    total │ 124.4 KiB │ 124.4 KiB │ +4 B 

 JAR     │ old │ new │ diff      
─────────┼─────┼─────┼───────────
 classes │  61 │  61 │ 0 (+0 -0) 
 methods │ 800 │ 800 │ 0 (+0 -0) 
  fields │ 270 │ 270 │ 0 (+0 -0)
AAR
 size     │ diff │ path          
──────────┼──────┼───────────────
 94.7 KiB │ +4 B │ ∆ classes.jar 
──────────┼──────┼───────────────
 94.7 KiB │ +4 B │ (total)

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 19, 2026

Benchmark report:

Test name Time ms. (median) Allocations (median)
com.hcaptcha.sdk.HCaptchaBenchmarkTest.EMULATOR_UNLOCKED_benchmarkInvisibleVerification +628.32 +919
com.hcaptcha.sdk.HCaptchaBenchmarkTest.EMULATOR_UNLOCKED_benchmarkInvisibleVerificationColdRun +679.82 +1442
com.hcaptcha.sdk.HCaptchaBenchmarkTest.EMULATOR_UNLOCKED_benchmarkInvisibleSetup +0.86 +514
com.hcaptcha.sdk.HCaptchaDebugInfoTest.EMULATOR_UNLOCKED_benchmarkDebugInfo +21.45 -5571
com.hcaptcha.sdk.HCaptchaDebugInfoTest.EMULATOR_UNLOCKED_benchmarkDebugSys +59.07 +2

Copy link
Copy Markdown
Collaborator

@CAMOBAP CAMOBAP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested exmple-compose-app

Spotted dimming issue in example-app. Fixed in PR #249
The issue in example-app note related to these changes

CAMOBAP and others added 2 commits March 23, 2026 08:17
* chore: allow change siteKey in runtime

* chore: remove no-op Setup button and setupArmed state

* fix(sdk): prevent stale readyForInteraction after dialog dismiss

---------

Co-authored-by: Aliaksandr Babrykovich <aliaksandr.babrykovich@callstack.com>
# Conflicts:
#	example-compose-app/src/main/java/com/hcaptcha/example/compose/ComposeActivity.kt
@e271828- e271828- merged commit b77da62 into main Mar 23, 2026
12 checks passed
@e271828- e271828- deleted the fix/alt_dimming branch March 23, 2026 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants