Reputation: 93
I can't import constrainAs in Jetpack Compose.
Text("Text", Modifier.constrainAs(text) {
top.linkTo(button.bottom, margin = 16.dp)
})
I added constraintlayout dependency:
implementation "androidx.constraintlayout:constraintlayout-compose:1.0.0-alpha08"
But it still says Unresolved reference: constrainAs
Upvotes: 3
Views: 2758
Reputation: 649
Better to use another version :
implementation "androidx.constraintlayout:constraintlayout-compose:1.0.0-beta02"
Upvotes: 0
Reputation: 87794
constrainAs
belongs to ConstraintLayoutScope
it means that in can be used for any view inside ConstraintLayout
, but only on a first level child.
ConstraintLayout {
val ref = createRef()
Box(
// OK
modifier = Modifier.constrainAs(ref) {
}
) {
Box(
// Not OK
modifier = Modifier.constrainAs(ref) {
}
)
}
}
Upvotes: 8
Reputation: 6835
Are you adding the following import?
androidx.constraintlayout.compose.ConstraintLayout
You don't need to import constraintsAs
separately.
Upvotes: 0