Skip to content

ax: prune background elements occluded by later opaque sibling views - #38

Open
chiroro-jr wants to merge 1 commit into
Developing-Gamer:mainfrom
chiroro-jr:fix/opaque-sibling-occlusion
Open

chiroro-jr wants to merge 1 commit into
Developing-Gamer:mainfrom
chiroro-jr:fix/opaque-sibling-occlusion

Conversation

@chiroro-jr

Copy link
Copy Markdown
Contributor

Problem

When an app displays an opaque in-VC sibling overlay (for example a search suggestions overlay like DartNative's AppBar.searchBar / DNSearchOverlayHost covering the screen with an opaque UIView, or an opaque view controller sliding over a previous page) without setting accessibilityViewIsModal, hooks/ax.c:walk() walks all subviews in painter order and emits both the occluded background views and the visible overlay views.

In SearchAppBar, expanding the search overlay produced 37–40 elements: all 18 hidden background rows (including occluded buttons like "Switch to: leading + search + avatar" and duplicate copies of every mail row) leaked alongside the 16 visible overlay rows.

Fix

In hooks/ax.c, buffer each window's walked elements with their painter-order index z and track solid opaque UIView containers painted later in the same window:

  • A UIView (depth > 0, >= 40x40 pt) is recorded as an occluder before recursing into its descendants (so it can mathematically never occlude itself or its own children) when:
    • cumulative effective alpha >= 0.99,
    • neither it nor any ancestor has non-zero layer.zPosition,
    • layer.mask == nil, and
    • its resolved layer.backgroundColor / view.backgroundColor has CGColorGetAlpha >= 0.99 (looked up via dlsym(RTLD_DEFAULT, "CGColorGetAlpha"), requiring no new link flags).
  • Clip occluder bounds through ancestor clipsToBounds / masksToBounds rects and inset vertically by layer.cornerRadius.
  • Before emitting elements for non-SpringBoard windows, skip any earlier element (e.z < occ.z, zPosition == 0) whose visible window-clipped rect has its center inside occ.frame and >= 80% of its visible area covered by occ.frame.
  • Leave SpringBoard and WebContent (dump_web_now) unpruned.

(Note: hooks/prebuilt/libagentsim-ax.dylib is intentionally not committed in this PR so maintainers can rebuild it with hooks/build.sh on macOS.)

Verification

  • Compiled hooks/ax.c for arm64-apple-ios15.0-simulator with -O2 -Wall -Werror (zero warnings).
  • Live-verified on iOS 27.2 (iPhone18,1):
    • DartNative SearchAppBar (expanded overlay): all 18 hidden background rows (The bar region IS the search pill..., Switch to: leading + search + avatar, and all 8 duplicate background mail rows) are pruned while all 16 visible suggestions rows and navigation bar controls (Search in mail, Close, Back) remain intact (44 ms dump).
    • Regression checks: Home Screen (15 elements), Settings (13 SwiftUI/UIKit elements), DartNative LiquidGlass (Glass & Fluid Merge, 13 translucent glass/text elements), and Safari WebContent (example.com DOM + toolbar) all snapshot cleanly with zero regressions.

@Developing-Gamer

Copy link
Copy Markdown
Owner

Not merged yet. This changes what every snapshot returns on a heuristic (opaque background colour, alpha, clipping), so a wrong guess hides real elements. It needs testing on more apps than we have here, and it overlaps #33's modal handling. Happy to take it after #33 lands, ideally with a switch to turn it off and the before and after element counts on a few apps.

@chiroro-jr
chiroro-jr force-pushed the fix/opaque-sibling-occlusion branch from a874373 to 3096bd4 Compare November 27, 2026 14:00
@chiroro-jr

Copy link
Copy Markdown
Contributor Author

Thanks for the review — you called it right on testing more apps! Testing open-source SwiftUI apps immediately surfaced a real false-positive occlusion case in the earlier flat-window implementation:

What changed (rebased onto main 4367fa8)

  1. Fixed SwiftUI ZStack overlay false occlusion: In LiquidGlassShowcase (ZStack { NavigationStack; Button { Image(systemName: "chevron.left") } }), _UIHostingView.accessibilityElements returns children in VoiceOver reading order ([0] = Back at top-left, [1] = UILayoutContainerView containing an opaque HostingView), not painter order. The previous flat g_occs check saw HostingView after Back and hid the visible Back button. Occlusion is now scoped strictly to UIView.subviews painter-order sibling steps (mark_occluded(sub_e0, e_before, o_before, g_noccs, wf)), never across accessibilityElements / accessibilityElementAtIndex: siblings.
  2. Added opt-out switch:
    • CLI: agent-sim snapshot --no-occlusion
    • MCP: snapshot optional no_occlusion: true
    • Env: AGENT_SIM_NO_OCCLUSION=1 (checked both client-side and in hooks/ax.c, forwarded via req-<pid> so no phone restart is needed and older hooks stay backward compatible).

Before / After Element Counts (Live on iOS 27.2 iPhone18,1)

App / Screen --no-occlusion (before) Default (after) Notes
Home Screen (SpringBoard) 15 15 SpringBoard unpruned
Settings (com.apple.Preferences) 13 13 Zero elements lost
SwiftChartsExamples (com.oss.swiftcharts) 5 5 Zero elements lost
SwiftUICatalog Toggles (com.oss.swiftuicatalog) 10 10 Zero elements lost
SwiftUIProbe detail (ZStack overlay Back button) 3 3 @e1 button "Back" (34,135) preserved & tappable
LiquidGlassShowcase Button Styles (ZStack overlay Back button) 13 13 @e1 button "Back" (34,135) preserved & tappable (previously hidden!)
DartNative SearchAppBar (expanded opaque search overlay) 37 19 All 18 occluded background rows pruned; all 19 visible overlay & nav controls intact

Happy to rebase once more after #33 lands as well!

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