diff --git a/app/src/main/java/com/example/research/ui/article/ArticleScreen.kt b/app/src/main/java/com/example/research/ui/article/ArticleScreen.kt index 22be825..2b331c1 100644 --- a/app/src/main/java/com/example/research/ui/article/ArticleScreen.kt +++ b/app/src/main/java/com/example/research/ui/article/ArticleScreen.kt @@ -1,6 +1,7 @@ package com.example.research.ui.article import androidx.compose.foundation.clickable +import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.* import androidx.compose.foundation.text.selection.SelectionContainer import androidx.compose.foundation.lazy.LazyColumn @@ -276,6 +277,7 @@ fun ArticleTitleBar( onNavigateBack: () -> Unit, modifier: Modifier = Modifier, compact: Boolean = false, + selectionReset: Int = 0, ) { val title = when (articleState) { is ArticleState.Loading -> articleState.title @@ -321,18 +323,20 @@ fun ArticleTitleBar( } } - SelectionContainer { - Text( - text = title, - style = MaterialTheme.typography.dictionaryTitleLarge, - color = MaterialTheme.colorScheme.onSurface, - maxLines = 1, - overflow = TextOverflow.Ellipsis, - modifier = Modifier - .padding(start = if (showBackButton) Spacing.searchTextStart - Spacing.iconStart - 24.dp else 16.dp) - .testTag("article_title") - .semantics { testTagsAsResourceId = true } - ) + key(selectionReset) { + SelectionContainer { + Text( + text = title, + style = MaterialTheme.typography.dictionaryTitleLarge, + color = MaterialTheme.colorScheme.onSurface, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + modifier = Modifier + .padding(start = if (showBackButton) Spacing.searchTextStart - Spacing.iconStart - 24.dp else 16.dp) + .testTag("article_title") + .semantics { testTagsAsResourceId = true } + ) + } } } } @@ -346,22 +350,31 @@ internal fun ArticleScreen( onRefClick: ((String) -> Unit)? = null, onScrollPositionChanged: ((Int, Int) -> Unit)? = null, ) { - Scaffold( - topBar = { - ArticleTitleBar( + val titleSelectionReset = remember { mutableIntStateOf(0) } + Box( + modifier = Modifier.clickable( + interactionSource = remember { MutableInteractionSource() }, + indication = null + ) { titleSelectionReset.intValue++ } + ) { + Scaffold( + topBar = { + ArticleTitleBar( + articleState = articleState, + showBackButton = true, + onNavigateBack = onNavigateBack, + selectionReset = titleSelectionReset.intValue + ) + }, + contentWindowInsets = AppWindowInsets.contentWithNavigation + ) { padding -> + ArticleContent( articleState = articleState, - showBackButton = true, - onNavigateBack = onNavigateBack + onNavigateBack = onNavigateBack, + onRefClick = onRefClick, + onScrollPositionChanged = onScrollPositionChanged, + modifier = Modifier.padding(padding) ) - }, - contentWindowInsets = AppWindowInsets.contentWithNavigation - ) { padding -> - ArticleContent( - articleState = articleState, - onNavigateBack = onNavigateBack, - onRefClick = onRefClick, - onScrollPositionChanged = onScrollPositionChanged, - modifier = Modifier.padding(padding) - ) + } } } diff --git a/app/src/main/java/com/example/research/ui/main/AdaptiveMainScreen.kt b/app/src/main/java/com/example/research/ui/main/AdaptiveMainScreen.kt index 0408705..9ca1687 100644 --- a/app/src/main/java/com/example/research/ui/main/AdaptiveMainScreen.kt +++ b/app/src/main/java/com/example/research/ui/main/AdaptiveMainScreen.kt @@ -1,5 +1,7 @@ package com.example.research.ui.main +import androidx.compose.foundation.clickable +import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.* import androidx.compose.runtime.* import androidx.compose.ui.Modifier @@ -90,9 +92,14 @@ fun AdaptiveMainScreen( ) }, detailPane = { + val titleSelectionReset = remember { mutableIntStateOf(0) } Column( modifier = Modifier .fillMaxSize() + .clickable( + interactionSource = remember { MutableInteractionSource() }, + indication = null + ) { titleSelectionReset.intValue++ } .padding(bottom = 16.dp) ) { ArticleTitleBar( @@ -100,6 +107,7 @@ fun AdaptiveMainScreen( showBackButton = isShowingDetail && articleState != null, onNavigateBack = onNavigateBackFromArticle, compact = true, + selectionReset = titleSelectionReset.intValue, modifier = Modifier.windowInsetsPadding( WindowInsets.safeDrawing.only(WindowInsetsSides.Top) )