RomC
RomC

Reputation: 21

A trouble about Jetpack-Compose Column

It couldn't run successfully with the following error:

Cannot find a parameter with this name: crossAxisSize

How can I fix it? Here's my code:

@Composable
fun NewsStory() {
    Column(
            crossAxisSize = LayoutSize.Expand,
            modifier=Spacing(16.dp)
    )
    {
        Text("demo")
        Text("try")
        Text("somethings")
    }
}

Upvotes: 2

Views: 2192

Answers (2)

Dmitri
Dmitri

Reputation: 2972

Note - please see an update on this below.

It is available on FlexColumn. Use it inside Column, like this:

 @Preview
@Composable
fun NewsStory() {
    Column( modifier=Spacing(16.dp)) {
        FlexColumn(
            crossAxisSize = LayoutSize.Expand

        )
        {
            Text("demo")
            Text("try")
            Text("somethings")
        }
    }

}

I assume this is the result you want?

This is the result

FlexColumn:

@Composable fun FlexColumn(
    modifier: Modifier = Modifier.None, 
    mainAxisAlignment: MainAxisAlignment = MainAxisAlignment.Start, 
    crossAxisAlignment: CrossAxisAlignment = CrossAxisAlignment.Start, 
    crossAxisSize: LayoutSize = LayoutSize.Wrap, 
    block: FlexChildren.() -> Unit
): Unit

link here

EDIT - Important: Just came to know that Flex is going to be deprecated soon. Oh the joy of working with alpha releases (: So the correct way would be to use Column/Row and apply Flexible modifier to the children. Keeping this post instead of deleting as someone might still be tempted to use FlexColumn/FlexRow as they are still officially out there. Do not!

Upvotes: 1

raimund89
raimund89

Reputation: 231

The parameter crossAxisSize was removed from the Column composable, I think in favor of using modifiers. If you want the Column to expand to full size, you can add the Expanded modifier to it, so then your code becomes like this:

@Composable
fun NewsStory() {
    Column(
            modifier=Expanded.wraps(Spacing(16.dp))      <<<------ the change
    )
    {
        Text("demo")
        Text("try")
        Text("somethings")
    }
}

Swapping the two modifiers shouldn't give a different result. You can also use either ExpandedWidth or ExpandedHeight if you only want to expand in one direction (as crossAxisSize actually only expands the width in case of a FlexColumn).

Upvotes: 0

Related Questions