A fully functional Android app built entirely with Kotlin and Jetpack Compose
Replace ClickableText with LinkAnnotation
Alex Vanyoe135b497368e
diff --git a/feature/search/src/main/kotlin/com/google/samples/apps/nowinandroid/feature/search/SearchScreen.kt b/feature/search/src/main/kotlin/com/google/samples/apps/nowinandroid/feature/search/SearchScreen.ktindex 86b1eb717..ff91941a8 100644--- a/feature/search/src/main/kotlin/com/google/samples/apps/nowinandroid/feature/search/SearchScreen.kt+++ b/feature/search/src/main/kotlin/com/google/samples/apps/nowinandroid/feature/search/SearchScreen.kt@@ -41,7 +41,6 @@ import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridCellsimport androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridItemSpanimport androidx.compose.foundation.lazy.staggeredgrid.rememberLazyStaggeredGridStateimport androidx.compose.foundation.shape.RoundedCornerShape-import androidx.compose.foundation.text.ClickableTextimport androidx.compose.foundation.text.KeyboardActionsimport androidx.compose.foundation.text.KeyboardOptionsimport androidx.compose.material3.Icon@@ -66,6 +65,7 @@ import androidx.compose.ui.platform.LocalSoftwareKeyboardControllerimport androidx.compose.ui.platform.testTagimport androidx.compose.ui.res.stringResourceimport androidx.compose.ui.text.AnnotatedString+import androidx.compose.ui.text.LinkAnnotationimport androidx.compose.ui.text.SpanStyleimport androidx.compose.ui.text.TextStyleimport androidx.compose.ui.text.buildAnnotatedString@@ -73,6 +73,7 @@ import androidx.compose.ui.text.font.FontWeightimport androidx.compose.ui.text.input.ImeActionimport androidx.compose.ui.text.style.TextAlignimport androidx.compose.ui.text.style.TextDecoration+import androidx.compose.ui.text.withLinkimport androidx.compose.ui.text.withStyleimport androidx.compose.ui.tooling.preview.Previewimport androidx.compose.ui.tooling.preview.PreviewParameter@@ -227,23 +228,31 @@ fun EmptySearchResultBody(textAlign = TextAlign.Center,modifier = Modifier.padding(vertical = 24.dp),)- val interests = stringResource(id = searchR.string.feature_search_interests)val tryAnotherSearchString = buildAnnotatedString {append(stringResource(id = searchR.string.feature_search_try_another_search))append(" ")- withStyle(- style = SpanStyle(- textDecoration = TextDecoration.Underline,- fontWeight = FontWeight.Bold,+ withLink(+ LinkAnnotation.Clickable(+ tag = "",+ linkInteractionListener = {+ onInterestsClick()+ },),) {- pushStringAnnotation(tag = interests, annotation = interests)- append(interests)+ withStyle(+ style = SpanStyle(+ textDecoration = TextDecoration.Underline,+ fontWeight = FontWeight.Bold,+ ),+ ) {+ append(stringResource(id = searchR.string.feature_search_interests))+ }}+append(" ")append(stringResource(id = searchR.string.feature_search_to_browse_topics))}- ClickableText(+ Text(text = tryAnotherSearchString,style = MaterialTheme.typography.bodyLarge.merge(TextStyle(@@ -252,13 +261,8 @@ fun EmptySearchResultBody(),),modifier = Modifier- .padding(start = 36.dp, end = 36.dp, bottom = 24.dp)- .clickable {},- ) { offset ->- tryAnotherSearchString.getStringAnnotations(start = offset, end = offset)- .firstOrNull()- ?.let { onInterestsClick() }- }+ .padding(start = 36.dp, end = 36.dp, bottom = 24.dp),+ )}}