Jetpack Compose onGloballyPositioned {} stops working when Modifier.heightIn() is applied in @Preview

112 views Asked by At

There is a problem in @Preview window with getting a view height whenever "Modified.heightIn()" is applied. The height is always 0, when heightIn() is removed it works normally.

The problem only pertains to Android Studio @Preview and works as expected on physical/virtual devices.

var height by remember { mutableStateOf(0) }
Image(
     painterResource(R.drawable.intro_view),
     contentDescription = "",
     contentScale = ContentScale.Fit,
     modifier = Modifier
       .heightIn(0.dp, 100.dp) // when this line is applied, var height always 0
       .onGloballyPositioned { height = it.size.height }
)
0

There are 0 answers