From 70764a06d1abe01c30d7726f341031c742103d2f Mon Sep 17 00:00:00 2001 From: Eugene Date: Wed, 29 Jul 2026 19:02:12 +0300 Subject: [PATCH] remove text from nav --- .../chat/presentation/ChatScreen.kt | 50 +++++++++---------- .../kotlin/ru/shadowsparky/ui/BaseScreen.kt | 7 +-- 2 files changed, 27 insertions(+), 30 deletions(-) diff --git a/feature/chat/chat-client/src/commonMain/kotlin/ru/shadowsparky/chat/presentation/ChatScreen.kt b/feature/chat/chat-client/src/commonMain/kotlin/ru/shadowsparky/chat/presentation/ChatScreen.kt index 867e659..f7b7972 100644 --- a/feature/chat/chat-client/src/commonMain/kotlin/ru/shadowsparky/chat/presentation/ChatScreen.kt +++ b/feature/chat/chat-client/src/commonMain/kotlin/ru/shadowsparky/chat/presentation/ChatScreen.kt @@ -20,9 +20,9 @@ import androidx.compose.foundation.layout.widthIn import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.foundation.text.ClickableText import androidx.compose.foundation.text.KeyboardActions import androidx.compose.foundation.text.KeyboardOptions +import androidx.compose.foundation.text.selection.SelectionContainer import androidx.compose.material3.Button import androidx.compose.material3.Card import androidx.compose.material3.CardDefaults @@ -41,12 +41,14 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester +import androidx.compose.ui.text.LinkAnnotation import androidx.compose.ui.text.SpanStyle +import androidx.compose.ui.text.TextLinkStyles import androidx.compose.ui.text.buildAnnotatedString import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.style.TextDecoration -import androidx.compose.ui.text.withStyle +import androidx.compose.ui.text.withLink import androidx.compose.ui.unit.LayoutDirection import androidx.compose.ui.unit.dp import org.jetbrains.compose.resources.stringResource @@ -198,42 +200,40 @@ private fun MessageBubble( val contentColor = if (isUser) MaterialTheme.colorScheme.onPrimaryContainer else MaterialTheme.colorScheme.onSurfaceVariant val tokens = remember(message.content) { onParseMessage(message.content) } val annotatedString = buildAnnotatedString { - tokens.forEachIndexed { index, token -> + tokens.forEach { token -> when (token) { is TextToken.Plain -> { append(token.text) } is TextToken.Link -> { - pushStringAnnotation(tag = "LINK_INDEX", annotation = index.toString()) - withStyle( - style = SpanStyle( - color = MaterialTheme.colorScheme.primary, - fontWeight = FontWeight.Bold, - textDecoration = TextDecoration.Underline - ) - ) { append(token.text) } - pop() + val linkAnnotation = LinkAnnotation.Clickable( + tag = "LINK", + styles = TextLinkStyles( + style = SpanStyle( + color = MaterialTheme.colorScheme.primary, + fontWeight = FontWeight.Bold, + textDecoration = TextDecoration.Underline + ) + ), + linkInteractionListener = { + onClickLink(token.text) + } + ) + withLink(linkAnnotation) { append(token.text) } } } } } - Box(modifier = Modifier.fillMaxWidth(), contentAlignment = alignment) { Card( colors = CardDefaults.cardColors(containerColor = containerColor, contentColor = contentColor), modifier = Modifier.widthIn(max = 280.dp) ) { Column(modifier = Modifier.padding(12.dp)) { - ClickableText( - text = annotatedString, - style = MaterialTheme.typography.bodyLarge.copy(color = contentColor), - onClick = { offset -> - annotatedString.getStringAnnotations(tag = "LINK_INDEX", start = offset, end = offset) - .firstOrNull()?.let { annotation -> - val tokenIndex = annotation.item.toIntOrNull() ?: return@ClickableText - val clickedToken = tokens.getOrNull(tokenIndex) as? TextToken.Link ?: return@ClickableText - onClickLink(clickedToken.text) - } - } - ) + SelectionContainer { + Text( + text = annotatedString, + style = MaterialTheme.typography.bodyLarge.copy(color = contentColor) + ) + } } } } diff --git a/libs/ui/src/commonMain/kotlin/ru/shadowsparky/ui/BaseScreen.kt b/libs/ui/src/commonMain/kotlin/ru/shadowsparky/ui/BaseScreen.kt index 5d60726..ccb81af 100644 --- a/libs/ui/src/commonMain/kotlin/ru/shadowsparky/ui/BaseScreen.kt +++ b/libs/ui/src/commonMain/kotlin/ru/shadowsparky/ui/BaseScreen.kt @@ -24,7 +24,6 @@ import androidx.compose.material3.NavigationRailItem import androidx.compose.material3.Scaffold import androidx.compose.material3.SnackbarHost import androidx.compose.material3.SnackbarHostState -import androidx.compose.material3.Text import androidx.compose.material3.TopAppBarDefaults import androidx.compose.material3.TopAppBarScrollBehavior import androidx.compose.runtime.Composable @@ -137,8 +136,7 @@ private fun BottomBar( NavigationBarItem( selected = currentRoute == entry.route, onClick = { onSelectNavigation?.invoke(entry.route) }, - icon = { Icon(entry.painter, contentDescription = entry.title) }, - label = { Text(entry.title) } + icon = { Icon(entry.painter, contentDescription = entry.title) } ) } } @@ -165,8 +163,7 @@ private fun ExpandedContent( NavigationRailItem( selected = currentRoute == entry.route, onClick = { onSelectNavigation?.invoke(entry.route) }, - icon = { Icon(entry.painter, contentDescription = entry.title) }, - label = { Text(entry.title) } + icon = { Icon(entry.painter, contentDescription = entry.title) } ) } }