FlowColumnOverflow


Overflow Handling Options

This enumeration defines the available options for handling content that exceeds the boundaries of its container for FlowColumn and ContextualFlowColumn.

Options:

  • Visible: The overflowing content remains visible outside its container. This can lead to overlapping with other elements. Use this option when it's crucial to display all content, regardless of the container's size.

  • Clip: The overflowing content is clipped and not visible beyond the boundary of its container. Ideal for maintaining a clean and uncluttered UI, where overlapping elements are undesirable.

  • expandIndicator: Behaves similar to Clip, however shows an indicator or button indicating that more items can be loaded.

  • expandOrCollapseIndicator: Extends the expandIndicator functionality by adding a 'Collapse' option. After expanding the content, users can choose to collapse it back to the summary view.

Summary

Public companion functions

FlowColumnOverflow

Registers an "expand indicator" composable for handling overflow in a FlowColumn.

Cmn
FlowColumnOverflow
@ExperimentalLayoutApi
@Composable
expandOrCollapseIndicator(
    expandIndicator: @Composable FlowColumnOverflowScope.() -> Unit,
    collapseIndicator: @Composable FlowColumnOverflowScope.() -> Unit,
    minColumnsToShowCollapse: Int,
    minWidthToShowCollapse: Dp
)

Registers an "expand or collapse indicator" composable for handling overflow in a FlowColumn.

Cmn

Public companion properties

FlowColumnOverflow

Clip the overflowing content to fix its container.

Cmn
FlowColumnOverflow

Display all content, even if there is not enough space in the specified bounds.

Cmn

Public companion functions

expandIndicator

@ExperimentalLayoutApi
fun expandIndicator(content: @Composable FlowColumnOverflowScope.() -> Unit): FlowColumnOverflow

Registers an "expand indicator" composable for handling overflow in a FlowColumn.

This function allows the creation of a custom composable that can be displayed when there are more items in the FlowColumn than can be displayed in the available space. The "expandable indicator" composable can be tailored to show a summary, a button, or any other composable element that indicates the presence of additional items.

import androidx.compose.foundation.background
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.FlowColumn
import androidx.compose.foundation.layout.FlowColumnOverflow
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.foundation.rememberScrollState
import androidx.compose.material.Text
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

val totalCount = 20
var maxLines by remember { mutableStateOf(2) }

Text(
    modifier =
        Modifier.fillMaxWidth(1f).padding(20.dp).wrapContentHeight(align = Alignment.Top),
    text = "Flow Column with Max Lines and See More",
    fontWeight = FontWeight.Bold
)

FlowColumn(
    modifier =
        Modifier.height(200.dp)
            .horizontalScroll(rememberScrollState())
            .padding(20.dp)
            .wrapContentWidth(align = Alignment.Start),
    verticalArrangement = Arrangement.spacedBy(10.dp),
    horizontalArrangement = Arrangement.spacedBy(20.dp),
    maxLines = maxLines,
    overflow = FlowColumnOverflow.expandIndicator { Ellipsis(text = "...") { maxLines += 2 } }
) {
    repeat(totalCount) {
        Box(
            modifier =
                Modifier.align(Alignment.CenterHorizontally)
                    .height(50.dp)
                    .width(50.dp)
                    .background(Color.Green)
        ) {
            Text(
                text = it.toString(),
                fontSize = 18.sp,
                modifier = Modifier.padding(3.dp).align(Alignment.Center)
            )
        }
    }
}
Parameters
content: @Composable FlowColumnOverflowScope.() -> Unit

composable that visually indicates more items can be loaded.

expandOrCollapseIndicator

@ExperimentalLayoutApi
@Composable
fun expandOrCollapseIndicator(
    expandIndicator: @Composable FlowColumnOverflowScope.() -> Unit,
    collapseIndicator: @Composable FlowColumnOverflowScope.() -> Unit,
    minColumnsToShowCollapse: Int = 1,
    minWidthToShowCollapse: Dp = 0.dp
): FlowColumnOverflow

Registers an "expand or collapse indicator" composable for handling overflow in a FlowColumn.

This function is designed to switch between two states: a "Expandable" state when there are more items to show, and a "Collapsable" state when all items are being displayed and can be collapsed.

Prior to layout, the function evaluates both composables indicators to determine their maximum intrinsic size. Depending on the space available and the number of items, either the expandIndicator or the collapseIndicator is rendered.

import androidx.compose.foundation.background
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.FlowColumn
import androidx.compose.foundation.layout.FlowColumnOverflow
import androidx.compose.foundation.layout.FlowColumnOverflowScope
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.foundation.rememberScrollState
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

val totalCount = 20
var maxLines by remember { mutableStateOf(2) }

Text(
    modifier =
        Modifier.fillMaxWidth(1f).padding(20.dp).wrapContentHeight(align = Alignment.Top),
    text = "FlowColumn with MaxLines and +N button",
    fontWeight = FontWeight.Bold
)
val moreOrCollapseIndicator =
    @Composable { scope: FlowColumnOverflowScope ->
        DynamicSeeMoreForDrawText(
            isHorizontal = false,
            totalCount = totalCount,
            { scope.shownItemCount },
            onExpand = { maxLines += 2 },
            onShrink = { maxLines = 2 }
        )
    }
FlowColumn(
    modifier =
        Modifier.height(200.dp)
            .padding(20.dp)
            .horizontalScroll(rememberScrollState())
            .wrapContentWidth(align = Alignment.Start),
    verticalArrangement = Arrangement.spacedBy(10.dp),
    horizontalArrangement = Arrangement.spacedBy(20.dp),
    maxLines = maxLines,
    overflow =
        FlowColumnOverflow.expandOrCollapseIndicator(
            minColumnsToShowCollapse = 4,
            expandIndicator = moreOrCollapseIndicator,
            collapseIndicator = moreOrCollapseIndicator
        )
) {
    repeat(totalCount) {
        Box(
            modifier =
                Modifier.align(Alignment.CenterHorizontally)
                    .height(50.dp)
                    .width(50.dp)
                    .background(Color.Green)
        ) {
            Text(
                text = it.toString(),
                fontSize = 18.sp,
                modifier = Modifier.padding(3.dp).align(Alignment.Center)
            )
        }
    }
}
Parameters
expandIndicator: @Composable FlowColumnOverflowScope.() -> Unit

composable that visually indicates more items can be loaded.

collapseIndicator: @Composable FlowColumnOverflowScope.() -> Unit

composable that visually indicates less items can be loaded.

minColumnsToShowCollapse: Int = 1

Specifies the minimum number of columns that should be visible before showing the collapse option. This parameter is useful when the number of columns is too small to be reduced further.

minWidthToShowCollapse: Dp = 0.dp

Specifies the minimum width at which the collapse option should be displayed. This parameter is useful for preventing the collapse option from appearing when the width is too narrow.

Public companion properties

Clip

@ExperimentalLayoutApi
val ClipFlowColumnOverflow

Clip the overflowing content to fix its container.

Visible

@ExperimentalLayoutApi
val VisibleFlowColumnOverflow

Display all content, even if there is not enough space in the specified bounds.