Repository navigation
Description
Context
On Apple targets, a view with Overflow: core.Hidden (or overflow-hidden) loses its own outer Shadows, its React Native shadow and its outline. The clip is masksToBounds on the view's own layer (internal/platform/apple/layer.go:71: layer.Send(selSetMasksToBounds, vs.Clip)), and the decor's shadow and outline layers are sublayers of that layer. The decor says so in an internal comment (internal/platform/apple/decor.go:23-24: "A layer that clips its children clips these too, as it clips its own shadow."). ui.Dialog works around it by moving the clip into an inner view when Bare is set (ui/dialog.go:80-83: "The clip is a view of its own: on Apple's targets a view that clips loses its outer shadow.").
The only place an app author could learn this is one line in the architecture notes, docs/architecture/styles.md:66 ("A view that clips clips its own shadows and outline on Apple, as it clips its React Native shadow."). Nothing an app author reads first mentions it:
core.Style.Overflow's doc (core/style.go:130-131) says it "clips children to the node's bounds and corners", which reads as children only.docs/public/en/layout.md:64says "Overflowclips children to a box".docs/public/en/styles.mdlists shadows and outlines (line 23) and shows ashadow-smcard (line 56) but says nothing about clipping.
The other desktop backends do what CSS does and keep the view's own decoration outside its clip:
- Windows draws the React Native shadow and outer box shadows (
internal/platform/windows/paint.go:707,:709) before it pushes the clip (:737), and draws the outline after popping it (:831). - Linux appends outset shadow nodes (
internal/platform/linux/paint.go:90) beforesh.pushClip(:112), and the outline after the pop (:142). - The web puts
outlineandbox-shadowon the element itself (internal/platform/web/decor.go:28-31) and clips with CSSoverflowon the same element (internal/platform/web/web.go:1804-1805), which never clips a box's ownbox-shadoworoutline.
From reading the code, Android seems to match Apple, not CSS. Box.draw paints outer shadows and the outline as part of the view's background drawable (internal/platform/android/java/dev/oneo/nsgo/Box.java:59-100), and a clipping view sets setClipToOutline(true) (NsgoView.java:3480, flag 0 being v.Clip from internal/platform/android/android.go:1840). That clips the background drawable too. I have not checked this on a device.
Minimal repro (builds against main). On Windows and Linux both cards have the same shadow. On macOS the right-hand card has none:
package main
import (
"github.com/nsgo-dev/nsgo"
"github.com/nsgo-dev/nsgo/core"
)
func card(clip bool) core.Node {
s := core.Style{Width: core.Pt(200), Height: core.Pt(120), CornerRadius: 16, Background: core.RGB(0xffffff),
Shadows: []core.BoxShadow{{Offset: core.Point{Y: 12}, Blur: 24, Spread: -4, Color: core.RGBA(0x000000, 0.35)}}}
if clip {
s.Overflow = core.Hidden
}
// A header strip that would poke out of the rounded corners without the clip.
return core.View{Style: s, Children: []core.Node{
core.View{Style: core.Style{Height: core.Pt(40), Background: core.RGB(0x3b82f6)}},
}}
}
func Root(cx *core.Scope) core.Node {
return core.View{Style: core.Style{FlexGrow: 1, Direction: core.Row, Gap: 48, Padding: core.All(48),
Background: core.RGB(0xeeeeee), AlignItems: core.AlignCenter, JustifyContent: core.JustifyCenter},
Children: []core.Node{card(false), card(true)}}
}
func main() { nsgo.Run(Root, nsgo.WindowSize(640, 320)) }The same happens with Class: "overflow-hidden rounded-2xl bg-white shadow-lg".
Why it matters for real apps
"Rounded card, clipped content, drop shadow" is one of the most common UI patterns: poster and thumbnail cards whose image has to follow the corners, hero banners, media control bars, popovers, toasts. Tailwind users write overflow-hidden rounded-xl shadow-lg by habit, because it works in every browser. In NSGo it looks right on the web, Windows and Linux, and the shadow disappears on the Mac. A team developing on Windows or Linux won't see it until someone runs the Mac build.
We hit this porting a desktop video player (Kando) from MyGo to NSGo. Its library's hero banner and poster cards each needed an extra inner clipping view, the same thing ui.Dialog does for Bare, plus a test that the outer views don't clip. The workaround is cheap once you know it. What costs time is finding out, and the only explanation is in the architecture notes and an internal comment.
Proposal
Document it now. Separately, decide whether Apple and Android should match CSS.
-
Docs, no behaviour change:
core.Style.Overflow: add a sentence like "On Apple and Android it also clips the node's own outer shadows, React Native shadow and outline; put the clip on an inner view to keep them, asui.Dialogdoes." (Adjust the Android part once someone checks it on a device.)docs/public/en/styles.md(shadows) anddocs/public/en/layout.md:64(Overflow): the same note, with a two-view example (outer view withShadowsandCornerRadius, inner view withOverflow: core.Hidden, the same radius minus the border, andFlexGrow: 1).docs/architecture/styles.md:66: say that Windows, Linux and the web keep the view's own shadows and outline outside the clip, so the line reads as a platform difference, not a general rule.
-
Parity, optional and for the maintainers to decide: when a view clips and also has outer shadows, an outline or a React Native shadow, the Apple backend could clip an inner holder layer for its content and children instead of setting
masksToBoundson the view's own layer. That is the splitui.Dialogdoes by hand, done once in the decor and only for views that need it, so the common case gets no extra layer. Android could do the same by drawing outer shadows and the outline outside the clipped render node. If this lands,Overflowmeans the same on every backend andui.Dialog's inner view can go.
Acceptance
-
core.Style.Overflow's doc says which backends also clip the node's own outer shadows and outline, and how to keep them. -
docs/public/en/styles.mdanddocs/public/en/layout.mdcover the same, with the two-view pattern. -
docs/architecture/styles.mdnames Windows, Linux and the web as keeping their own shadows and outline outside the clip, and says what Android does. - If parity is pursued: the repro above shows the same shadow on both cards on macOS and iOS (and Android), with no extra layer for clipping views that have no outer shadow or outline, and
ui.Dialog'sBarepath no longer needs its inner clipping view.
Activity