Modifier

@Target(allowedTargets = [AnnotationTarget.CLASS])
annotation class Modifier(val tag: Int, val scopes: KClass<*>)

Annotates a data class which represents a modifier for a Widget.

Each modifier in a Schema must have a unique tag among all Modifier annotations in the Schema.

@Modifier(1)
data class BackgroundColor(
val value: Color,
)

To create a modifier that applies a specific parent widget, supply one or more scope types.

@Modifier(1, RowScope::class)
data class RowAlignment(
val value: VerticalAlignment,
)

When defining the Widget, use the same scope type as a receiver on Children property.

@Widget(1)
data class Row(
@Children(1) val children: RowScope.() -> Unit,
)

When a modifier is applied to a widget it will be processed in one of two ways:

  1. If scoped, the parent widget which provides the scope will query the value. For example, each implementation of a Row will handle HorizontalAlignment set on its children.

  2. If unscoped, the widget factory interface will expose callback functions that are invoked when a value is used. For example, a BackgroundColor(value: V, modifier: BackgroundColor) function will be generated on the widget factory for each implementation to provide. The implementation should be idempotent, as it will be invoked each time a new modifier chain is set, even if the specific unscoped modifier has not changed.

Properties

Link copied to clipboard
val scopes: Array<out KClass<*>>
Link copied to clipboard
val tag: Int