CamoSurface
Concept
1. Why
CamoSurface is the most basic container: a region with a background, a shape and a depth. It is the component through which the skin's surface treatment shows up. On the Material skin it's paper with a shadow; on a later glass skin the same call becomes a blurred pane. It also sets the content color for everything inside, which is how text on a colored panel stays readable.
2. Shape
Level → colors
SurfaceLevel | Background | Content color |
|---|---|---|
Surface (default) | surface | onSurface |
Lowest | surfaceContainerLowest | onSurface |
Low | surfaceContainerLow | onSurface |
Container | surfaceContainer | onSurface |
High | surfaceContainerHigh | onSurface |
Highest | surfaceContainerHighest | onSurface |
Levels say how separated a region is from the background: Apple's grouped backgrounds, Fluent's neutral backgrounds 1–6 and Carbon's layers all map onto them (see Theme §3.3).
Material mapping preview: Paper, where elevation is a shadow, and separation comes from the surface level. See Material Skin.
3. API
Contract
fun CamoSurface(
level: SurfaceLevel = Surface,
shape: ShapeRole = None,
elevation: ElevationLevel = Level0,
border: Boolean = false, // a hairline outline for panels (from SurfaceTheme)
content: Slot,
)
| Parameter | What it's for |
|---|---|
level | which surface role to paint |
shape | corner radius role, and clipping of content to that shape |
elevation | semantic depth. The skin decides how it looks. |
border | draws an outline around the shape: panels separated by a hairline, Minimal's standard look. Cards keep CamoCard(appearance = Outline). |
content | anything |
State → renderer: SurfaceState(level, shape, elevation, border). Slots: SurfaceSlots(content).
Tokens used
colors.surface, the fivesurfaceContainer*roles, andonSurfaceshapes.<shape>elevation.<level>colors.outlineVariant(border)
Component theme
theme.components.surface: SurfaceTheme?. Every field is nullable in the theme. The skin's defaults(theme) fills whatever isn't set.
| Field | Type | Default (Minimal) | What it's for |
|---|---|---|---|
borderWidth | Dp | 1 (one logical px) | the outline when border = true |
borderColor | Color | outlineVariant | the outline color |
Accessibility
- Not focusable, with no role. It's a pure container.
- Its content keeps its own semantics.
- A surface does not block touches to content underneath unless the platform requires it (a dialog's scrim is a different component).
4. Build steps
- Implement
CamoSurfacein core: build the state and slots, callskin.surface.render. DebugSkinsurface renderer: a flat colored box, clipped to the shape, that sets the content color.- Sample: one surface per level, with a
CamoTextinside each, in light and dark. - Test:
- a
CamoTextinside any level has the coloronSurface, and each level paints its own role; - the content is clipped to the shape;
border = truedraws the outline inborderColorand doesn't change the content size;elevationis passed through to the surface treatment (check with a spy treatment in the test).
- a
Done when
- Each level paints its role and gives
onSurfaceto text inside it. - Swapping
DebugSkin→MinimalSkin(in M3) changes the look with no call-site change.
5. Edge cases
| Case | Decided behavior |
|---|---|
Nested surfaces (a High inside a Surface) | Each sets its own content color. The innermost wins. |
Colored surfaces (a primary or warning panel) | Not a surface level. Use CamoCard(appearance = Soft, tone = Warning), which uses the tone's container colors. This keeps SurfaceLevel neutral. |
| Elevation on a glass skin (Later) | Glass reads the same ElevationLevel. Its treatment decides the blur strength. Callers don't change anything. |
| RTL | No directional content. The shape is symmetric. |
| Shadow clipping by a parent | A platform concern: document padding in the platform note. |
Implementation
1. Why
This is the plain container that shows the skin's surface treatment, and resets the content color and icon style for its content. It's the first place where SurfaceTreatment.modifier(...) is used, so it's where Paper (and later Glass) is proven.
2. Shape
3. API
@Composable
public fun CamoSurface(
modifier: Modifier = Modifier,
level: SurfaceLevel = SurfaceLevel.Surface,
shape: ShapeRole = ShapeRole.None,
elevation: ElevationLevel = ElevationLevel.Level0,
border: Boolean = false, // drawn by the renderer with Modifier.border(style.borderWidth, style.borderColor, shape)
content: @Composable () -> Unit,
)
public fun CamoColors.surfaceOf(level: SurfaceLevel): Color = when (level) {
SurfaceLevel.Surface -> surface
SurfaceLevel.Lowest -> surfaceContainerLowest
SurfaceLevel.Low -> surfaceContainerLow
SurfaceLevel.Container -> surfaceContainer
SurfaceLevel.High -> surfaceContainerHigh
SurfaceLevel.Highest -> surfaceContainerHighest
}
CamoSurface has no behavior modifier (it isn't interactive), so modifier is passed through as given. Its only component theme is SurfaceTheme (borderWidth, borderColor), resolved to SurfaceStyle; everything else comes from roles.
The renderer:
@Composable override fun Render(state: SurfaceState, slots: SurfaceSlots, theme: CamoTheme, style: SurfaceStyle, modifier: Modifier) {
val color = theme.colors.surfaceOf(state.level)
val shape = theme.shapes.of(state.shape)
Box(modifier
.then(Camouflage.skin.surfaceTreatment.modifier(color, shape, theme.elevation.of(state.elevation), theme))
.then(if (state.border) Modifier.border(style.borderWidth, style.borderColor, shape) else Modifier)) {
ProvideContentStyle(theme.colors.onSurface, IconStyle(24.dp, theme.colors.onSurface)) { slots.content() }
}
}
4. Build steps
SurfaceLevel→ color mapping,ShapeRole→ shape,ElevationLevel→ dp.CamoSurface+SurfaceRendererin DebugSkin (flat color, clip).commonTest: the background pixel color equalssurfaceOf(level)(captureToImage()on jvm); text inside isonSurface; the content is clipped to the shape (a pixel at the corner is transparent).
Done when
- Six surfaces (one per level) render in light and dark.
5. Edge cases
| Case | Decided behavior |
|---|---|
| Shadows clipped by a parent | Modifier.shadow draws outside the bounds. A parent with clipToBounds cuts it. Give the parent padding ≥ the elevation. |
| Shadows on web and iOS | Rendered by Skia on every non-Android target. They look almost the same as Android's RenderNode shadows, but not identically. Screenshot tests are per platform. |
| Touches pass through | Box doesn't consume pointer events, so content below still receives touches outside the content (the base rule). |