Skip to content

fix: adds click outside close and overlay settings#45

Merged
pandeymangg merged 4 commits intomainfrom
fix/click-outside-close-android
Feb 11, 2026
Merged

fix: adds click outside close and overlay settings#45
pandeymangg merged 4 commits intomainfrom
fix/click-outside-close-android

Conversation

@pandeymangg
Copy link
Contributor

@pandeymangg pandeymangg commented Feb 10, 2026

What does this PR do?

Implements the Android SDK counterpart to formbricks/formbricks#7197 and mirrors formbricks/ios#38, which replaces the darkOverlay boolean with a new overlay enum (none, light, dark) and fixes clickOutsideClose not being passed to the survey JS library.

Fixes #44

Changes

New SurveyOverlay enum (Survey.kt)

  • Added SurveyOverlay enum with cases NONE, LIGHT, DARK, with @SerializedName annotations matching the backend's SurveyOverlay schema.

Model updates (Project.kt, Survey.kt)

  • Project.darkOverlay: Boolean?Project.overlay: SurveyOverlay?
  • SurveyProjectOverwrites.darkOverlay: Boolean?SurveyProjectOverwrites.overlay: SurveyOverlay?

Native overlay background (FormbricksFragment.kt)

  • The modal dim amount was previously hardcoded to 0.5f regardless of config. It now respects the resolved overlay value:
    • DARK → dark semi-transparent background (0.6f)
    • LIGHT → light semi-transparent background (0.3f)
    • NONE → fully transparent (0.0f)
  • show() now accepts an overlay parameter, resolved by SurveyManager.

Overlay resolution (SurveyManager.kt)

  • Added resolveOverlay(survey) helper that follows the correct precedence: survey-level projectOverwrites.overlay → project-level overlayNONE.
  • track() resolves and passes the overlay to the presenter.

WebView data (FormbricksViewModel.kt)

  • Replaced data["darkOverlay"] (Bool) with data["overlay"] (String: "none" / "light" / "dark"), matching the JS survey library's expected prop.
  • Bug fix: Added data["clickOutside"], which was missing entirely. Without it, the JS survey library's click-outside-to-dismiss handler never activated, even when clickOutsideClose was true.

Test updates (FormbricksViewModelInstrumentedTest.kt, Environment.json)

  • Updated mock JSON: "darkOverlay": false"overlay": "none".
  • Updated Project constructor in tests to use overlay instead of darkOverlay.

How should this be tested?

  • Create a survey with overlay set to Dark → verify the native modal shows a dark semi-transparent background and the JS overlay renders dark
  • Create a survey with overlay set to Light → verify a lighter background
  • Create a survey with overlay set to None → verify a fully transparent background
  • Enable clickOutsideClose with a light or dark overlay → verify tapping outside the survey card dismisses it
  • Disable clickOutsideClose → verify tapping outside does nothing
  • Verify survey-level projectOverwrites.overlay overrides the project-level default
  • Verify backward compatibility: surveys without an overlay field default to none

@pandeymangg pandeymangg requested a review from Dhruwang February 10, 2026 10:57
@coderabbitai
Copy link

coderabbitai bot commented Feb 10, 2026

Walkthrough

This change replaces the boolean darkOverlay field with a new SurveyOverlay enum type that supports three states: NONE, LIGHT, and DARK. The enum is introduced in the Survey.kt model and applied across the codebase, updating Project.kt and SurveyProjectOverwrites to use the new overlay field instead of darkOverlay. The Formbricks.kt and SurveyManager.kt are modified to pass and resolve overlay values, while FormbricksFragment.kt is enhanced to compute dim amounts dynamically based on the overlay style. Test data and test cases are updated to reflect the new field structure and parameter names.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main changes: adding click outside close and overlay settings functionality, which is the core focus of the changeset across all modified files.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, detailing the new SurveyOverlay enum, model updates, native overlay background changes, overlay resolution logic, and webview data fixes with testing instructions.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
android/src/main/java/com/formbricks/android/model/environment/Survey.kt (1)

37-42: Minor: Use KDoc style (/** ... */) instead of /// for documentation comments.

Kotlin's documentation convention uses KDoc (/** ... */), not triple-slash comments which are a Swift/C# convention. This won't affect functionality but is inconsistent with Kotlin idioms.

Suggested fix
-/// Defines the overlay style displayed behind a survey modal.
+/** Defines the overlay style displayed behind a survey modal. */
 enum class SurveyOverlay(val value: String) {
android/src/androidTest/java/com/formbricks/android/webview/FormbricksViewModelInstrumentedTest.kt (1)

73-80: Consider adding assertions for the new overlay and clickOutside JSON fields.

The test verifies several JSON keys but doesn't assert the presence or values of the newly added overlay and clickOutside fields. Since this PR specifically introduces these fields, it would be valuable to verify they appear correctly in the output (e.g., "overlay":"none" and "clickOutside":false for the null-input case).

Suggested additions
         assertTrue(json.contains("\"languageCode\":\"default\""))
+        assertTrue(json.contains("\"clickOutside\":false"))
+        assertTrue(json.contains("\"overlay\":\"none\""))
     }
android/src/main/java/com/formbricks/android/manager/SurveyManager.kt (1)

396-404: Overlay resolution is duplicated in FormbricksViewModel.getJson.

The same precedence logic (survey.projectOverwrites.overlay → project.overlay → NONE) is repeated in FormbricksViewModel.kt (line 154). Consider reusing resolveOverlay from SurveyManager in the ViewModel to keep the precedence logic in one place and avoid divergence.

Also, resolveOverlay is currently public — consider making it internal since it's an SDK implementation detail.

android/src/main/java/com/formbricks/android/webview/FormbricksFragment.kt (1)

277-284: Nit: use Kotlin-style KDoc (/** */) instead of ///.

/// is a Swift/C#/Dart doc-comment style. Kotlin uses /** ... */ for documentation comments that are picked up by KDoc tooling.

Suggested fix
-        /// Returns the appropriate dim amount for the given overlay style.
+        /** Returns the appropriate dim amount for the given overlay style. */
         fun dimAmountFor(overlay: SurveyOverlay): Float {

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Member

@Dhruwang Dhruwang left a comment

Choose a reason for hiding this comment

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

Looks good, just need to fix the coverage !

@sonarqubecloud
Copy link

@pandeymangg pandeymangg added this pull request to the merge queue Feb 11, 2026
Merged via the queue into main with commit 8a02e06 Feb 11, 2026
7 checks passed
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.

Add support for closable overlays

2 participants