ParentLayoutParamsModifier

interface ParentLayoutParamsModifier


Interface for modifiers that can adjust the layout parameters of a composable that implements ParentLayoutParamsAdjustable.

This interface allows a parent composable to influence the layout of its children in a structured way. Implementations of this interface are responsible for determining if they can and should adjust the provided layout parameters.

When the layout system processes modifiers, if a modifier implements ParentLayoutParamsModifier, its adjustParams` method will be called with an object that implements ParentLayoutParamsAdjustable. This object typically represents the layout parameters of the child composable being laid out.

An example modifier node that sets a specific property on TargetLayoutParams.

private class ExamplePropertySetterNode(
private val newValue: Any? // The value to set, similar to 'alignment'
) : SomeModifierNode(), ParentLayoutParamsModifier { // Extends a base node and implements the interface

override fun adjustParams(params: ParentLayoutParamsAdjustable) {
// Check if 'params' is the specific type this modifier can handle.
if (params is TargetLayoutParams) {
// Smart cast: 'params' is now known to be TargetLayoutParams.
// Safely access and modify its 'someProperty'.
params.someProperty = newValue
}
}
}

Summary

Public functions

Unit

Adjusts the given ParentLayoutParamsAdjustable object.

Public functions

adjustParams

Added in 1.0.0-alpha05
fun adjustParams(params: ParentLayoutParamsAdjustable): Unit

Adjusts the given ParentLayoutParamsAdjustable object.

Implementations must first verify that params is of an expected type before casting and modifying. This prevents runtime errors and ensures the modifier only alters parameters it understands.

Parameters
params: ParentLayoutParamsAdjustable

The layout parameters to potentially adjust.