Micko Cabacungan
03/05/2022, 12:14 AManimateDpAsState is going way past the targetValue (I checked by logging in onSizeChange modifier)? I've also specified a widthIn max width but that also just gets totally ignored..
Source code example in thread for more contextMicko Cabacungan
03/05/2022, 12:14 AMBoxWithConstraints(modifier = Modifier.widthIn(max = parentMaxSize.width.dp)) {
//maxWidth is about 360dp from BoxWithConstraints
val targetDp = 360.dp
val size by animateDpAsState(
targetValue = targetDp,
animationSpec = tween(
durationMillis = 2000,
easing = FastOutLinearInEasing
)
)
Box(
modifier = Modifier
.heightIn(min = 8.dp, max = 8.dp)
.widthIn(min = 10.dp, max = maxWidth) //we use maxWidth of BoxWithConstraints
.width(size)
.background(linearProgressGradientColor, RectangleShape)
.onSizeChanged {
Log.d("@@@", "Bar size: ${it.width.dp}") //somehow this is logging way more than 360dp where it should of stopped resizing itself at targetValue which is 360dp..
}
) {
}
}tad
03/05/2022, 2:31 AMfillMaxWidth() on the nested BoxDoris Liu
03/05/2022, 5:50 AMModifier.width rather than animateDpAsState going beyond target. Modifier.width declares a preferred width, which can be overwritten by the incoming constraints from the parent modifier. If you need the width to be exact, consider using Modifier.requiredWidth 🙂Micko Cabacungan
03/05/2022, 4:20 PMMicko Cabacungan
03/05/2022, 4:22 PM