{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

CompositionLocalMap

public sealed interface CompositionLocalMap


A read-only, immutable snapshot of the CompositionLocals that are set at a specific position in the composition hierarchy.

Summary

Nested types

public static class CompositionLocalMap.Companion

Public methods

abstract @NonNull T
<T extends Object> get(@NonNull CompositionLocal<@NonNull T> key)

Returns the value of the provided composition local at the position in the composition hierarchy represented by this CompositionLocalMap instance.

Public methods

get

abstract @NonNull T <T extends Object> get(@NonNull CompositionLocal<@NonNull T> key)

Returns the value of the provided composition local at the position in the composition hierarchy represented by this CompositionLocalMap instance. If the provided key is not set at this point in the hierarchy, its default value will be used.

For non-static CompositionLocals, this function will return the latest value of the CompositionLocal, which might change over time across the same instance of the CompositionLocalMap. Reads done in this way are not tracked in the snapshot system.

For static CompositionLocals, this function returns the value at the time of creation of the CompositionLocalMap. When a static CompositionLocal is reassigned, the entire composition hierarchy is recomposed and a new CompositionLocalMap is created with the updated value of the static CompositionLocal.