BIT-2431 add condition to only update labelTextWidth on initial layout (#3399)

This commit is contained in:
Dave Severns 2024-07-05 14:48:49 -04:00 committed by GitHub
parent f13679cd2c
commit 870de652be
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -596,6 +596,20 @@ private fun PasswordLengthSliderItem(
val density = LocalDensity.current
val sliderRange = minValue.toFloat()..maxValue.toFloat()
val lengthLabel: @Composable () -> Unit = remember {
{
Text(
text = stringResource(id = R.string.length),
modifier = Modifier
.onGloballyPositioned { layoutCoordinates ->
if (labelTextWidth == Dp.Unspecified) {
labelTextWidth = layoutCoordinates.size.width.toDp(density)
}
},
)
}
}
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
@ -607,15 +621,7 @@ private fun PasswordLengthSliderItem(
value = sliderValue.toString(),
readOnly = true,
onValueChange = { },
label = {
Text(
text = stringResource(id = R.string.length),
modifier = Modifier
.onGloballyPositioned {
labelTextWidth = it.size.width.toDp(density)
},
)
},
label = lengthLabel,
singleLine = true,
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
modifier = Modifier
@ -636,7 +642,8 @@ private fun PasswordLengthSliderItem(
}
.testTag("PasswordLengthLabel")
.wrapContentWidth()
.width(labelTextWidth + 16.dp + 16.dp),
// We want the width to be no wider than the label + 16dp on either side
.width(16.dp + labelTextWidth + 16.dp),
)
Slider(