Skip to content

fix(apple): preserve decorations outside clipped views - #238

Merged
houko merged 7 commits into
mainfrom
fix/overflow-decoration-clip
Nov 16, 2026
Merged

houko merged 7 commits into
mainfrom
fix/overflow-decoration-clip

Conversation

@houko

@houko houko commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

On Apple, Overflow: Hidden sets masksToBounds on the styled layer. Core Animation then clips the view's own outer shadows and outline along with its children, while Windows, Linux and the web keep them outside the clip as CSS does (#210).

Change

  • A view that clips and draws an outer shadow, a React Native shadow or an outline (apple.NeedsClipHolder) leaves its own layer unclipped and clips elsewhere:
    • a plain view moves its children into a holder view clipped to its corners, with a shape mask where the corners differ in radius (apple.ClipHolder); an effect that hides the holder's children puts that mask back when it ends (apple.HolderMask);
    • a macOS scroll view clips its existing container, and an image its image layer, where one radius draws the corners.
  • AppKit re-masks a view's layer from clipsToBounds whenever its frame changes, so a view whose holder clips answers false and the holder true.
  • Texts, canvases, inputs, web, video and native views, iOS scroll views (whose children scroll inside the UIScrollView, where a holder would hold them still) and images or scroll views whose corners differ keep clipping their own decoration, as Android does (setClipToOutline clips the Box background with its shadows). The common case gets no extra view.
  • A holder is no second Tab stop: on macOS only the view's own NSView answers canBecomeKeyView and acceptsFirstResponder, as iOS's focus methods already require, so a pressable clipped card with a shadow stays one stop in the key view loop.
  • Holders are released with their views (the effect container leaked its NSView/UIView).
  • A holder is hit as its view where no child is, so a box-none view still lets the pointer through and iOS's header item lookup does not take the holder for the view; it takes the view's Perspective (ChildPerspective), which the view's sublayer transform would give only the flat holder, clipping or not: a holder stays once the shadow or outline it clipped for goes away, so every holder but a macOS scroll view's container (an effect's container too) follows each style and resize unclipped. A resize fits it to the style last drawn, animated corners included, and recentres the perspective, as a macOS layer's anchor is its corner.
  • An image's layer clips to rounded corners that share a radius on some corners as well as all four (it used Corners.Uniform), so an image with only its top corners rounded keeps them once its own layer leaves the clip.
  • Docs: core.Style.Overflow, docs/public/{en,zh}/layout.md (with the inner-view pattern) and styles.md, docs/architecture/styles.md; the remaining gaps (Android, the Apple views above) are a roadmap row, so ui.Dialog's Bare keeps its inner clipping view, whose comment now names Android.

Verification

  • go build ./..., Windows/Linux/Android arm64/wasm builds of core and ui, go tool nsgo check -target all
  • go tool nsgo test on internal/platform/apple, internal/platform/macos, core, ui, and -run 'Layer|Skills|Doc' .; new tests: TestClipHolderClipsToTheCorners, TestShapedCorners, TestViewsClipInAHolderToKeepTheirShadow, and TestViewsClipAsTheirStyleSays for the holder's clipsToBounds. Also TestClipHolderTakesThePerspective, TestImageClipsToItsRoundedCorners, macOS TestAHolderIsHitAsItsView and macOS TestAHolderKeepsThePerspective (a held to unheld transition and a resize), macOS TestAHolderIsNoTabStop (a real NSWindow's recalculated key view loop), each failing without its fix.
  • macOS, real window screenshots of the issue's repro plus variants (corners that differ, an outline, an image, a scroll view and one scrolled 100 points, a clip without shadow): every clipped card keeps its shadow and outline, children stay inside the corners including the 32/6-point mixed ones, and both still hold after the window is resized. nsgo test -target macos checked the corner clipping by pixels; its capture (cacheDisplayInRect:) draws no layer shadows, so shadows were checked from window screenshots.
  • macOS, real window (screencapture of the test window): a box-none, clipped, shadowed overlay lets a press through to the button under it; an image with only its top corners rounded, clipped and shadowed, keeps its square bottom corners and its shadow (before the image fix it showed square top corners too); a clipped, shadowed card with Perspective shows its rotated child in perspective (before the holder took it, flat); once its shadow is removed 8 seconds in, the child keeps its perspective (before the holder kept following the style, it turned flat).
  • iOS: builds and vets only. The iPhone is unavailable and the iOS simulator would not boot over SSH on the build machine, so the iOS check on a screen is still outstanding.
  • Android: unchanged; it still clips the view's own shadows, as documented.

Fixes #210 in part: the Android parity and the Apple views listed above stay on the roadmap.

@github-actions github-actions Bot added size/M bug Something isn't working documentation Improvements or additions to documentation macOS iOS core conflict Conflicts with the base branch; resolve it first labels Nov 15, 2026
@houko
houko force-pushed the fix/overflow-decoration-clip branch from 311f21d to 55783b7 Compare November 16, 2026 07:09
@github-actions github-actions Bot added ui and removed conflict Conflicts with the base branch; resolve it first labels Nov 16, 2026
@houko
houko force-pushed the fix/overflow-decoration-clip branch from 55783b7 to c8bf944 Compare November 16, 2026 08:15
@github-actions github-actions Bot added size/L and removed size/M labels Nov 16, 2026
@houko
houko force-pushed the fix/overflow-decoration-clip branch 2 times, most recently from ab8f7e2 to 8f9dce8 Compare November 16, 2026 09:24
@houko

houko commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator Author

Reviewed. Read the full diff against main and checked the following.

  • Regression found and fixed in this review: the holder is registered as its view, so on macOS it answered canBecomeKeyView and acceptsFirstResponder for a pressable view, and AppKit's recalculated key view loop stopped on a pressable, clipped, shadowed card twice (loop a, b, b's holder, c). Added commit "fix(macos): keep a view's holder out of the key view loop", which requires the view's own NSView as the iOS focus methods already do, with TestAHolderIsNoTabStop on a real NSWindow; it fails without the fix (holder takes the focus, loop a, b, b's holder, c) and passes with it (a, b, c, a).
  • The earlier perspective fix holds: reverting the ClipHolder, macOS holdClip and place changes makes TestClipHolderTakesThePerspective (m34 0 for an unclipped holder) and TestAHolderKeepsThePerspective (m34 0 once the shadow goes) fail.
  • macOS real window: three clipped cards with corner radius 32, a child overflowing the top-left corner and a child rotated 50 degrees in Y, two with Perspective 300, one losing its shadow 6 seconds in. Shadows draw outside the clip, children stay inside the rounded corners, the rotated child stays in perspective before and after the shadow is removed, and the clip remains once it is.
  • Rebased onto current main (no conflicts, no overlap with the notifications change). After the rebase: go build ./...; windows/linux amd64, android arm64 and js/wasm builds of core and ui; nsgo test on core (550), ui (155) and -run 'Layer|Skills|Doc' . (29); darwin vet of apple and macos, iOS arm64 vet of ios; go test of internal/platform/apple and internal/platform/macos all pass.
  • Main moved twice during the review, to 0.1.0 and then the web view changes; rebased again (only CHANGELOG.md conflicted) and re-ran the same builds and tests, all passing (core 553). Since 0.1.0 shipped, CHANGELOG.md takes a one-line Unreleased entry for this change, added in its own commit.
  • No hard-wrapped lines in the new text, docs in en and zh agree with the behaviour.
  • Not verified on a device: iOS (builds and vets only; the iOS holder, hit test and header item lookup changes still want an on-screen check). Android is unchanged.

@houko
houko marked this pull request as ready for review November 16, 2026 09:24
@houko
houko force-pushed the fix/overflow-decoration-clip branch from 8f9dce8 to 699d77d Compare November 16, 2026 09:32
…can draw

The holder clipped corners of different radii with one radius, gave every iOS scroll view a holder framed at its content offset, which stopped its children scrolling with it, and unclipped the own layer of texts, canvases, web and video views whose content is not in the holder. AppKit also masks a view's layer again as clipsToBounds answers on each frame change.

Holders now serve plain views, macOS scroll views' containers and images' image layers, with a shape mask for corners that differ (kept across an effect's mask), the styled view answers clipsToBounds false while its holder clips, and holders are released with their views.
Android and Apple's views without a holder clip their own outer shadows and outline with their children; the docs name them, show the inner-view pattern and record the gap in the roadmap.
…pective

A holder that clips a view's children answered hit tests where no child is, so a box-none view caught the pointer instead of letting it through, and iOS's header item lookup took the holder for the view. The view's ChildPerspective reached only the flat holder, leaving its children without perspective, a resize fitted the holder to the style before its animated corners, and an image with some corners rounded left its image layer square once the view's own layer stopped clipping. Holders now map hits to their view, take the perspective (scroll containers keep their translation), fit to the style last drawn, and the image layer clips to masked corners that share a radius.
A view that had a clip holder for its shadow or outline kept the holder once they went away, and the holder then took no perspective: the view's own sublayer transform reached only the flat holder, so its children lost Perspective. ClipHolder now takes ChildPerspective from any style, clipping or not, and every holder but a scroll view's container follows each style and resize unclipped, an effect's container included, so the perspective's centre follows the size on macOS, where a layer's anchor is its corner.
The holder that takes a view's children for its clip (or an effect) is registered as the view, so it answered canBecomeKeyView and acceptsFirstResponder for it and AppKit's recalculated key view loop stopped on a pressable, clipped, shadowed card twice. Only the view's own NSView takes the focus now, as the iOS focus methods already require.
@github-actions github-actions Bot added the conflict Conflicts with the base branch; resolve it first label Nov 16, 2026
@houko
houko force-pushed the fix/overflow-decoration-clip branch from 699d77d to ba996c0 Compare November 16, 2026 09:36
@houko
houko merged commit a15127f into main Nov 16, 2026
11 of 13 checks passed
@houko
houko deleted the fix/overflow-decoration-clip branch November 16, 2026 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working conflict Conflicts with the base branch; resolve it first core documentation Improvements or additions to documentation iOS macOS size/L ui

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Overflow Hidden clips a view's own outer shadows and outline on Apple but not on Windows, Linux or the web, and only an architecture note says so

1 participant