dazza5000
04/06/2022, 5:03 PMAdam Powell
04/06/2022, 5:21 PMdazza5000
04/06/2022, 5:29 PMAdam Powell
04/06/2022, 7:36 PMChris Sinco [G]
04/06/2022, 8:33 PMdazza5000
04/06/2022, 8:34 PMval largestTitleTextLength: BasicCardModel? =
carouselModel.maxByOrNull { it.title?.length ?: 0 }
val textLayout: (TextLayoutResult) -> Unit = {
Log.d("darran", "darran layout $it")
val textCharacterLength = it.layoutInput.text.length
val textLayoutWidth = it.multiParagraph.width
val widthPerCharacter = textLayoutWidth / textCharacterLength * it.lineCount
Log.d("darran", "width per character $widthPerCharacter")
Log.d("darran", "lineCount ${it.lineCount}")
val maxWidth = it.layoutInput.constraints.maxWidth
val heightPerLine = it.multiParagraph.height / it.lineCount
val totalWidthNeeded =
(largestTitleTextLength?.title?.length ?: 1) * widthPerCharacter
val linesRequired: Float = totalWidthNeeded / maxWidth
val lineCeiling = ceil(linesRequired)
Log.d("darran", "linesCeiling ${lineCeiling}")
val titleHeight = heightPerLine * linesRequired
Log.d(
"darran",
"height calculated by textLayoutResult needed ${it.multiParagraph.height}"
)
Log.d("darran", "height calculated by algo needed $titleHeight")
Log.d("darran", "height overflowhappened ${it.didOverflowHeight} ")
Log.d("darran", "width overflowhappened ${it.didOverflowWidth} ")
if (it.multiParagraph.height > titleHeightToSendDown ?: 0f) {
titleHeightToSendDown = it.multiParagraph.height
}
if (titleHeight > titleHeightToSendDown ?: 0f) {
titleHeightToSendDown = titleHeight
}
Log.d("darran", "title height to send down $titleHeightToSendDown")
}
Zoltan Demant
04/07/2022, 4:14 AM224.dp
as the initial one - you can do whatever you like there, this works great for my use case!
var minHeight by remember {
mutableStateOf(224.dp)
}
Modifier
.onSizeChanged { size ->
val itemHeight = with(density) {
val height = size.height
height.toDp()
}
if (itemHeight > minHeight) {
minHeight = itemHeight
}
}
.heightIn(
min = minHeight
)
dazza5000
04/07/2022, 5:02 PMvar minHeight: Dp? by remember { mutableStateOf(null) }
val density = LocalDensity.current
val cardSizeModifier = Modifier.onSizeChanged { size ->
val itemHeight = with(density) {
val height = size.height
height.toDp()
}
if (itemHeight > minHeight ?: 0.dp) {
minHeight = itemHeight
}
}.defaultMinSize(minHeight = minHeight ?: Dp.Unspecified)