hazeGlassContainer

fun Modifier.hazeGlassContainer(mergeDistance: Dp = GlassDefaults.mergeDistance, scrollState: ScrollableState? = null, transitionSpec: FiniteAnimationSpec<Float> = spring(), reducedMotionPolicy: GlassReducedMotionPolicy = GlassReducedMotionPolicy.System): Modifier

Groups nearby, compatible Glass members belonging to this nearest container.

All Glass output draws behind every container child. Backdrop input samples only drawing before the container. Members use the largest member's shortest side for optics, retaining their own styles and shape/colour values, except members of a group (see hazeGlass's groupKey), which draw with the first member's shape and appearance and count as one member for optics.

mergeDistance has two roles. It decides which compatible members merge: members whose edge-to-edge gap is less than mergeDistance join one Glass cluster. It also shapes the merge. As the gap closes from mergeDistance to half of it, facing edges stretch towards each other and each member's optics blend into the cluster's; below half, a bridge joins them. It does not position or space the container's children. mergeDistance must be finite and non-negative, and zero disables merging by proximity. Defaults to GlassDefaults.mergeDistance.

Without RuntimeShader support, or when a cluster exceeds the render budget, each cluster draws as one surface clipped to the hard union of its members, with no bridge. Members keep their own tint and background, except that a group draws as its single shape with its first member's tint and background. Where members overlap, the earlier registered member's colours apply.

Members that attach or detach after the container's first draw animate their glass as each member's GlassMemberTransition declares, timed by transitionSpec, which defaults to spring(). GlassReducedMotionPolicy.Reduced keeps the morph with a critically damped spring at full duration, whatever the platform scale is. GlassReducedMotionPolicy.System snaps, as with GlassMemberTransition.None, when the platform motion-duration scale is zero.

A detached member's glass is drawn by the container through a live member with the same input, resolving the same sources, until its animation ends. When no such member remains, for example when the last member leaves, the glass disappears immediately. So does the glass of a member that is rotated or scaled, or that uses HazeInput.Content, whose content leaves with it.

A running transition ends without animating when the member it grows from, retracts into or is drawn through leaves, or when its member is no longer within mergeDistance of that member, unless both are members of the same group, which stay neighbours at any distance. A member whose nearest container changes while it stays in the layout, for example when a nested container is added or removed around it, appears in the new container immediately. Moving a member with movableContentOf detaches and reattaches it, so it detaches from the old container and attaches to the new one, each with the transition described above. transitionSpec and reducedMotionPolicy changes apply from the next transition. Leaving members never count towards the shared optical size. Haze animates only the glass, so callers animate member content themselves, for example with AnimatedVisibility. Cap diagnostics follow HazeLogger.enabled.

For the items of a scrollable layout, such as a LazyRow or LazyColumn, pass its scrollState. While is scrollingScrollableState.isScrollInProgress, including the frame in which it stops, members that attach appear immediately and members that detach disappear immediately, whatever their GlassMemberTransition, so items do not animate as they scroll into or out of view. Members that attach or detach while the layout is idle animate as usual. A scroll that starts while a member's glass is still animating out ends that animation immediately. Position changes made outside a scroll, such as LazyListState.requestScrollToItem, are not scrolls. Without a scrollState, items of a lazy layout that scroll into view animate like any member that attaches after the first draw.