pref: 使 `getEmoticonHeightPx` 稳定

This commit is contained in:
HuanCheng65 2023-07-11 14:48:33 +08:00
parent 0d1c565fdf
commit 2ef051f7fa
No known key found for this signature in database
GPG Key ID: 5EC9DD60A32C7360
2 changed files with 12 additions and 12 deletions

View File

@ -35,8 +35,8 @@ import com.huanchengfly.tieba.post.pxToDp
import com.huanchengfly.tieba.post.pxToSp import com.huanchengfly.tieba.post.pxToSp
import com.huanchengfly.tieba.post.ui.common.theme.compose.ExtendedTheme import com.huanchengfly.tieba.post.ui.common.theme.compose.ExtendedTheme
import com.huanchengfly.tieba.post.utils.EmoticonManager import com.huanchengfly.tieba.post.utils.EmoticonManager
import com.huanchengfly.tieba.post.utils.EmoticonManager.getEmoticonHeightPx
import com.huanchengfly.tieba.post.utils.EmoticonUtil.emoticonString import com.huanchengfly.tieba.post.utils.EmoticonUtil.emoticonString
import com.huanchengfly.tieba.post.utils.getEmoticonHeightPx
@Composable @Composable

View File

@ -37,6 +37,17 @@ import kotlinx.coroutines.launch
import java.io.File import java.io.File
import java.lang.ref.WeakReference import java.lang.ref.WeakReference
@OptIn(ExperimentalTextApi::class)
@Composable
fun getEmoticonHeightPx(style: TextStyle): Int {
val textMeasurer = rememberTextMeasurer()
val textLayoutResult = textMeasurer.measure(
AnnotatedString(stringResource(id = R.string.emoticon_default)),
style
)
return textLayoutResult.size.height
}
object EmoticonManager { object EmoticonManager {
private val DEFAULT_EMOTICON_MAPPING: Map<String, String> = mapOf( private val DEFAULT_EMOTICON_MAPPING: Map<String, String> = mapOf(
"呵呵" to "image_emoticon1", "呵呵" to "image_emoticon1",
@ -106,17 +117,6 @@ object EmoticonManager {
private val drawableCache: MutableMap<String, Drawable> = mutableMapOf() private val drawableCache: MutableMap<String, Drawable> = mutableMapOf()
private val coroutineScope: CoroutineScope = CoroutineScope(Dispatchers.IO) private val coroutineScope: CoroutineScope = CoroutineScope(Dispatchers.IO)
@OptIn(ExperimentalTextApi::class)
@Composable
fun getEmoticonHeightPx(style: TextStyle): Int {
val textMeasurer = rememberTextMeasurer()
val textLayoutResult = textMeasurer.measure(
AnnotatedString(stringResource(id = R.string.emoticon_default)),
style
)
return textLayoutResult.size.height
}
fun getEmoticonInlineContent( fun getEmoticonInlineContent(
sizePx: Int sizePx: Int
): Map<String, InlineTextContent> { ): Map<String, InlineTextContent> {