Skip to content

fix: preserve hCaptcha logo when using vector drawable support#245

Open
e271828- wants to merge 1 commit intofix/233-eliminate-png-density-variantsfrom
codex/fix-srccompat-logo-regression
Open

fix: preserve hCaptcha logo when using vector drawable support#245
e271828- wants to merge 1 commit intofix/233-eliminate-png-density-variantsfrom
codex/fix-srccompat-logo-regression

Conversation

@e271828-
Copy link
Contributor

@e271828- e271828- commented Mar 9, 2026

Summary

This fixes a regression introduced by the PNG density-variant optimization in 1d4778969f6feba5d0f6ec9923ac0efbeb37c88a.

That change correctly enabled vectorDrawables.useSupportLibrary and replaced android:src with app:srcCompat to avoid generating density-specific PNG fallbacks. The problem is that HCaptchaDialogFragment still inflates hcaptcha_fragment.xml through the plain DialogFragment / android.app.Dialog path. With a framework ImageView, app:srcCompat is ignored, so the loading logo drawable is never set at runtime.

Fix

  • Replace the layout tag with androidx.appcompat.widget.AppCompatImageView
  • Keep app:srcCompat and vectorDrawables.useSupportLibrary = true
  • Avoid broader changes to dialog construction, theming, or inflater setup

Using the explicit AppCompat widget is the narrowest and most compatible fix because it preserves the size reduction goal while making vector inflation work on the existing production path down to the module's supported API levels.

Test coverage

  • Add a Robolectric regression test that inflates the layout through the same plain Dialog context used by the fragment
  • Assert that the logo view is an AppCompatImageView
  • Assert that the logo drawable is non-null after inflation

Verification

  • ./gradlew :sdk:testDebugUnitTest --tests '*HCaptchaFragmentLayoutTest'
  • ./gradlew :sdk:testDebugUnitTest
  • Repository pre-commit hook completed successfully during commit creation

The PNG density-variant optimization switched the loading logo from
android:src to app:srcCompat and enabled
vectorDrawables.useSupportLibrary. That removed the generated PNG
fallbacks, but it also introduced a runtime regression in the current
DialogFragment code path.

HCaptchaDialogFragment inflates hcaptcha_fragment.xml through the plain
DialogFragment/android.app.Dialog inflater path. In that path, the logo
view remained a framework ImageView, which does not consume the
app:srcCompat attribute. The result was that the loading logo drawable
was left unset at runtime.

Fix this by changing the XML tag to
androidx.appcompat.widget.AppCompatImageView while keeping
app:srcCompat. This preserves the size reduction from using vector
support while making drawable inflation work correctly on the existing
production path without changing dialog construction or theming.

Add a Robolectric regression test that inflates the layout through the
same plain Dialog context used by the fragment and verifies that the
logo view is an AppCompatImageView with a non-null drawable.
@github-actions
Copy link

github-actions bot commented Mar 9, 2026

Diffuse report:

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

 AAR      │ old      │ new      │ diff      
──────────┼──────────┼──────────┼───────────
      jar │ 59.4 KiB │ 59.4 KiB │       0 B 
 manifest │    411 B │    411 B │       0 B 
      res │ 78.2 KiB │ 28.3 KiB │ -49.9 KiB 
    other │    1 KiB │    1 KiB │       0 B 
──────────┼──────────┼──────────┼───────────
    total │  139 KiB │ 89.1 KiB │ -49.9 KiB 

 JAR     │ old │ new │ diff      
─────────┼─────┼─────┼───────────
 classes │  38 │  38 │ 0 (+0 -0) 
 methods │ 569 │ 569 │ 0 (+0 -0) 
  fields │ 174 │ 174 │ 0 (+0 -0)
AAR
 size     │ diff      │ path                                           
──────────┼───────────┼────────────────────────────────────────────────
          │ -17.1 KiB │ - res/drawable-xxxhdpi-v4/ic_hcaptcha_logo.png 
          │ -12.4 KiB │ - res/drawable-xxhdpi-v4/ic_hcaptcha_logo.png  
          │    -8 KiB │ - res/drawable-xhdpi-v4/ic_hcaptcha_logo.png   
          │  -5.7 KiB │ - res/drawable-hdpi-v4/ic_hcaptcha_logo.png    
          │    -4 KiB │ - res/drawable-mdpi-v4/ic_hcaptcha_logo.png    
          │  -2.8 KiB │ - res/drawable-ldpi-v4/ic_hcaptcha_logo.png    
          │ -10.9 KiB │ - res/drawable-anydpi-v21/ic_hcaptcha_logo.xml 
 10.9 KiB │ +10.9 KiB │ + res/drawable/ic_hcaptcha_logo.xml            
          │       0 B │ - res/drawable-anydpi-v21/                     
          │       0 B │ - res/drawable-xxxhdpi-v4/                     
          │       0 B │ - res/drawable-xxhdpi-v4/                      
          │       0 B │ - res/drawable-xhdpi-v4/                       
          │       0 B │ - res/drawable-hdpi-v4/                        
          │       0 B │ - res/drawable-ldpi-v4/                        
          │       0 B │ - res/drawable-mdpi-v4/                        
      0 B │       0 B │ + res/drawable/                                
  1.6 KiB │     +93 B │ ∆ res/layout/hcaptcha_fragment.xml             
──────────┼───────────┼────────────────────────────────────────────────
 12.5 KiB │ -49.9 KiB │ (total)

@github-actions
Copy link

github-actions bot commented Mar 9, 2026

Benchmark report:

Test name Time ms. (median) Allocations (median)
com.hcaptcha.sdk.HCaptchaBenchmarkTest.EMULATOR_UNLOCKED_benchmarkInvisibleVerification +1034.43 +774
com.hcaptcha.sdk.HCaptchaBenchmarkTest.EMULATOR_UNLOCKED_benchmarkInvisibleVerificationColdRun +1117.37 +1007
com.hcaptcha.sdk.HCaptchaBenchmarkTest.EMULATOR_UNLOCKED_benchmarkInvisibleSetup +20.65 +230
com.hcaptcha.sdk.HCaptchaDebugInfoTest.EMULATOR_UNLOCKED_benchmarkDebugInfo -0.24 -5595
com.hcaptcha.sdk.HCaptchaDebugInfoTest.EMULATOR_UNLOCKED_benchmarkDebugSys +85.96 +2

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