↓ Skip to main content

Haze 2.2: A new look for Glass

·4 mins

Haze 2.2 is out. Haze brings background blur and glass effects to Jetpack Compose and Compose Multiplatform. Haze 2.1 made Glass stable and gave us surfaces that could merge as they moved together. In 2.2, a lot of the change is at the edges.

Look where the REGULAR card overlaps the blue circle. In the screenshot on the right, you can follow the edge of the card even where the colours blur together.

Two views of pink Glass cards and a blue circle. In the right-hand view, thin dark outlines make the overlapping shapes easier to distinguish.
Regular Glass in the desktop Glass Playground. Haze 2.1 is on the left and 2.2 is on the right.

Both demos start in Regular. Try dragging the REGULAR card across the circle in each version to see how the edge looks as the backdrop changes. For more room, open the Haze 2.1 Playground or the Haze 2.2 Playground in its own tab.

Follow the edge
#

At the corners, the curve eases into the straight sides. Glass now uses continuous 16 dp corners by default, and the mask, refraction and lighting all follow the new shape.

The light catches the rim along the top and bottom, just inside the shape. Just outside it, a thin dark outline is strongest on the left and right. When two surfaces merge in a hazeGlassContainer, the rim and outline follow the joined shape.

For continuous corners at another radius, pass a ContinuousRoundedCornerShape to your style’s shape. It’s a regular Compose shape, so it also works with Modifier.clip and Modifier.border. If you need a clip or border to match the new default, use GlassDefaults.continuousShape.

Any shape you’ve explicitly set still applies. GlassDefaults.shape keeps its old circular corners but is now deprecated; use RoundedCornerShape(16.dp) if you want to keep them.

Custom styles inherit Regular’s new edges, so you’ll see the rim and outline appear after upgrading. You can tune them with rimHighlight and edgeOutline, or turn them off:

val withoutEdges = GlassStyle.regular.then {
    edgeOutline(Color.Transparent, 0.dp)
    rimHighlight(0f, 0.dp, 0f)
}

Regular and Clear
#

Find the word CHROMATIC behind the bottom card. On the left, it dissolves into the pink. On the right, you can read it through the glass.

The word CHROMATIC is obscured behind the Regular card on the left and legible through the Clear card on the right. Clear also has a brighter top and bottom rim.
Regular on the left and Clear on the right, both in the Haze 2.2 desktop Glass Playground.

Regular softens the backdrop more as the surface gets larger. That’s handy for a panel with text or controls over a busy background. Clear keeps the blur shallow even on a large card, so it’s a good fit for controls over photos or video you want to keep visible.

Switch between Regular and Clear in the Haze 2.2 demo and watch the top edge, too. Clear has a brighter rim there and along the bottom. Its dark outline runs along the sides, while Regular’s carries on faintly across the top and bottom.

Clear also now uses its light response in both system appearances, so it looks different in dark mode than it did in 2.1. If you need the old dark response back, the Glass docs have the overrides.

Grow on press
#

A Glass button can now swell a little under your finger. Opt in by setting a pressed scale above 1f, up to 1.2f. Here the glass grows by 10% while the button keeps its original size in the layout. The growth draws outside the layout bounds, but a parent that clips its children will clip it too.

val pressToGrow = remember {
    GlassStyle.regular.then {
        pressed { scale(1.1f) }
    }
}

Modifier.hazeGlass(
    input = HazeInput.Sources(hazeState),
    style = pressToGrow,
)

hazeState connects the Glass to content registered with hazeSource. Pair the visual response with your usual Compose click handling.

In a Glass container, that extra bit of width can bring a pressed surface close enough to a neighbour for the two to merge.

Android 12 and 12L
#

On Android 12 and 12L, the hardware fallback can now soften what’s behind the Glass. It blurs the captured content and approximates the tone and progressive blur of full Glass. Refraction drops out on the fallback path. Other fallback paths put an automatic scrim over the unblurred content, which you can replace with your own colour, or turn off with Color.Transparent, using fallbackColor.

There are performance improvements too. On Android, below HazePerformanceMode.Quality, wide Glass blurs now read a reduced copy of their source: nine Glass surfaces used about 21% less CPU frame time at P90 on a Pixel 6. Press responses and tint animations no longer re-record the surface’s layers, and nine pressed surfaces used 33–40% less CPU frame time at P90 on a Pixel 8a.

See the 2.2.0 changelog or the GitHub release notes for the full list of changes.