compositionLocalWithComputedDefaultOf
public fun <T> compositionLocalWithComputedDefaultOf(
defaultComputation: CompositionLocalAccessorScope.() -> T
): ProvidableCompositionLocal<T>
Create a CompositionLocal that behaves like it was provided using ProvidableCompositionLocal.providesComputed by default. If a value is provided using ProvidableCompositionLocal.provides it behaves as if the CompositionLocal was produced by calling compositionLocalOf.
In other words, a CompositionLocal produced by can be provided identically to CompositionLocal created with compositionLocalOf with the only difference is how it behaves when the value is not provided. For a compositionLocalOf the default value is returned. If no default value has be computed for CompositionLocal the default computation is called.
The lambda passed to compositionLocalWithComputedDefaultOf will be invoked every time the CompositionLocal.current is evaluated for the composition local and computes its value based on the current value of the locals referenced in the lambda at the time CompositionLocal.current is evaluated. This allows providing values that can be derived from other locals. For example, if accent colors can be calculated from a single base color, the accent colors can be provided as computed composition locals. Providing a new base color would automatically update all the accent colors.
Parameters
| defaultComputation | the default computation to use when this CompositionLocal is not provided. |