https://kotlinlang.org logo
#compose
Title
# compose
s

Sheroz Nazhmudinov

09/04/2020, 6:25 PM
hey i’m trying out the constraint layout in jetpack compose. Here are my gradle dependencies:
Copy code
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.ui:ui-tooling:$compose_version"
implementation "androidx.compose.foundation:foundation:$compose_version"
implementation "androidx.compose.ui:ui:$compose_version"
And here’s the basic attempt on using ConstraintLayout:
Copy code
@Composable
@Preview
fun PreviewGreeting() {
    ConstraintLayout(constraintSet = ConstraintSet {
        tag("someTag")
    }) {
        Greeting(greeting = "Hello world")
    }
}
I get the error thou saying unresolved reference tag. can smbd please tell me which dependency am I missing?
r

romainguy

09/04/2020, 6:28 PM
Which version of Compose are you using?
s

Sheroz Nazhmudinov

09/04/2020, 6:28 PM
1.0.0-alpha02
r

romainguy

09/04/2020, 6:28 PM
The CL API has changed quite a bit since Developer Preview 2
The API now looks like this:
Copy code
ConstraintLayout(modifier = Modifier.padding(12.dp).fillMaxWidth()) {
        val (decreaseRef, increaseRef, labelRef, colorRef, amountRef) = createRefs()

        SmallButton(
            modifier = Modifier.constrainAs(decreaseRef) {
                start.linkTo(parent.start)
                centerVerticallyTo(parent)
            },
            onClick = { decrease(product) }
        ) {
            Image(Icons.Sharp.Remove)
        }
        // ...
}
s

Sheroz Nazhmudinov

09/04/2020, 6:29 PM
understood, thanks for the clarification.
r

romainguy

09/04/2020, 6:29 PM
You don’t use tags anymore but
createRef()
and
createRefs()
👍 1
s

Sheroz Nazhmudinov

09/04/2020, 6:37 PM
Thank you
2 Views