The second Android 11 Developer Preview is now available, test it out and share your feedback.

LayoutTag

@Immutable data class LayoutTag : ParentDataModifier, LayoutTagParentData
kotlin.Any
   ↳ androidx.ui.core.LayoutTag

A ParentDataModifier which tags the target with the given tag. The provided tag will act as parent data, and can be used for example by parent layouts to associate composable children to Measurables when doing layout, as shown below.

Example usage:

import androidx.ui.core.Layout
import androidx.ui.core.LayoutTag
import androidx.ui.layout.Container

Layout({
    // Here the Containers are only needed to apply the modifiers. You could use the
    // modifier on header and footer directly if they are composables accepting modifiers.
    Container(LayoutTag("header"), children = header)
    Container(LayoutTag("footer"), children = footer)
}) { measurables, constraints, _ ->
    val placeables = measurables.map { measurable ->
        when (measurable.tag) {
            // You should use appropriate constraints. Here we measure with dummy constraints.
            "header" -> measurable.measure(Constraints.fixed(100.ipx, 100.ipx))
            "footer" -> measurable.measure(constraints)
            else -> error("Unexpected tag")
        }
    }
    // Size should be derived from children measured sizes on placeables,
    // but this is simplified for the purposes of the example.
    layout(100.ipx, 100.ipx) {
        placeables.forEach { it.place(0.ipx, 0.ipx) }
    }
}

Summary

Public constructors

<init>(tag: Any)

A ParentDataModifier which tags the target with the given tag.

Public methods

Any?

Provides a parentData given the parentData already provided through the modifier's chain.

Properties

Any

Public constructors

<init>

LayoutTag(tag: Any)

A ParentDataModifier which tags the target with the given tag. The provided tag will act as parent data, and can be used for example by parent layouts to associate composable children to Measurables when doing layout, as shown below.

Example usage:

import androidx.ui.core.Layout
import androidx.ui.core.LayoutTag
import androidx.ui.layout.Container

Layout({
    // Here the Containers are only needed to apply the modifiers. You could use the
    // modifier on header and footer directly if they are composables accepting modifiers.
    Container(LayoutTag("header"), children = header)
    Container(LayoutTag("footer"), children = footer)
}) { measurables, constraints, _ ->
    val placeables = measurables.map { measurable ->
        when (measurable.tag) {
            // You should use appropriate constraints. Here we measure with dummy constraints.
            "header" -> measurable.measure(Constraints.fixed(100.ipx, 100.ipx))
            "footer" -> measurable.measure(constraints)
            else -> error("Unexpected tag")
        }
    }
    // Size should be derived from children measured sizes on placeables,
    // but this is simplified for the purposes of the example.
    layout(100.ipx, 100.ipx) {
        placeables.forEach { it.place(0.ipx, 0.ipx) }
    }
}

Public methods

modifyParentData

fun Density.modifyParentData(parentData: Any?): Any?

Provides a parentData given the parentData already provided through the modifier's chain.

Properties

tag

val tag: Any