Skip to content

Fix element targeting for native dialog windows on Android#226

Open
iujames wants to merge 1 commit into
mainfrom
fix/dialog-overlay-layering
Open

Fix element targeting for native dialog windows on Android#226
iujames wants to merge 1 commit into
mainfrom
fix/dialog-overlay-layering

Conversation

@iujames
Copy link
Copy Markdown
Contributor

@iujames iujames commented May 20, 2026

Summary

  • Fixes element targeting/layout capture failing to traverse dialog window view hierarchies on Android
  • Root cause: findTopMost() used findViewById(android.R.id.content) != null to filter window roots, but dialog windows often don't have android.R.id.content, so the SDK falls back to the Activity's DecorView and misses views inside the dialog
  • Regression introduced in 678c882 (Feb 2024) when the filter was ported from the Android SDK's split-screen fix
  • Companion PR for Android SDK: Fix Appcues overlay layering behind native dialog windows appcues-android-sdk#708

Changes

ReactNativeElementTargeting.kt — Replace findViewById(android.R.id.content) filter with isOwnedBy(activity) && isDecorView(). Uses ContextWrapper unwrap to match dialog DecorViews whose context is wrapped in ContextThemeWrapper. Aligns with the same fix in appcues-android-sdk.

EventsScreen.tsx — Added native Modal to example app Events screen for testing overlay layering with dialog windows.

Test plan

  • Open RN Modal, launch debugger via deep link → debugger appears above modal
  • Verified regression: without fix, debugger renders behind modal
  • Screen capture accessible while native modal is displayed

Made with Cursor

Summary by CodeRabbit

Release Notes

  • New Features

    • Added a native modal dialog to the events screen that allows users to trigger event tracking directly from within the modal interface. The modal includes dedicated controls for event triggering and dismissal.
  • Refactor

    • Improved window detection logic to enhance reliability in identifying application windows.

Review Change Stack

findTopMost used findViewById(android.R.id.content) which misses dialog
windows that don't have that view. Replaced with ContextWrapper unwrap +
isDecorView() check, matching the fix in appcues-android-sdk.

Also added a native Modal to the example app Events screen for testing
overlay layering with dialog windows on Android.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 20, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2bda0cf8-ed77-4bde-8059-6dfa5bd8c099

📥 Commits

Reviewing files that changed from the base of the PR and between 6c762db and d86928c.

📒 Files selected for processing (2)
  • android/src/main/java/com/appcuesreactnative/ReactNativeElementTargeting.kt
  • example/src/screens/main/EventsScreen.tsx

📝 Walkthrough

Walkthrough

This PR introduces two independent changes: a refactoring of Android Activity decor view selection logic and a new modal demo feature in the example app. The Android change updates how Activity.getParentView() identifies the topmost window decor view by replacing a generic list helper with activity-aware helpers that verify view ownership via ContextWrapper unwrapping and restrict candidates to DecorView instances. The example app change adds an interactive modal to EventsScreen that demonstrates modal UI, in-modal event tracking, and close controls, complete with state management and styling.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing element targeting for native dialog windows on Android by improving how the topmost window decor view is determined.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/dialog-overlay-layering

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

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