Fix conversation bubbles becoming too long.

Co-authored-by: Cody Henthorne <cody@signal.org>
This commit is contained in:
Alex Hart
2024-01-23 15:55:54 -04:00
committed by Nicholas Tinsley
parent 4ada7c9be9
commit e71bb33b23
5 changed files with 65 additions and 4 deletions

View File

@@ -0,0 +1,36 @@
/*
* Copyright 2024 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.thoughtcrime.securesms.conversation.v2.items
import android.content.Context
import android.util.AttributeSet
import androidx.appcompat.widget.LinearLayoutCompat
/**
* Custom LinearLayoutCompat that will intercept EXACTLY measure-specs and
* overwrite them with AT_MOST. This guarantees that wrap_content is respected
* when the Layout is within a constraintlayout.
*/
class ShrinkWrapLinearLayout @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null
) : LinearLayoutCompat(context, attrs) {
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
val shrinkWrapWidthSpec = shrinkWrapWidthMeasureSpec(widthMeasureSpec)
super.onMeasure(shrinkWrapWidthSpec, heightMeasureSpec)
}
private fun shrinkWrapWidthMeasureSpec(widthMeasureSpec: Int): Int {
val mode = MeasureSpec.getMode(widthMeasureSpec)
val size = MeasureSpec.getSize(widthMeasureSpec)
return if (mode == MeasureSpec.EXACTLY) {
MeasureSpec.makeMeasureSpec(size, MeasureSpec.AT_MOST)
} else {
widthMeasureSpec
}
}
}