Replace ClickableText with LinkAnnotation

Change-Id: I18ba20f07db5a392890f7e568c9faa7a90af1054
pull/1837/head
Alex Vanyo 1 year ago
parent 6c8cbf235c
commit b574f5faa9

@ -41,7 +41,6 @@ import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridCells
import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridItemSpan import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridItemSpan
import androidx.compose.foundation.lazy.staggeredgrid.rememberLazyStaggeredGridState import androidx.compose.foundation.lazy.staggeredgrid.rememberLazyStaggeredGridState
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.ClickableText
import androidx.compose.foundation.text.KeyboardActions import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
@ -66,6 +65,7 @@ import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.platform.testTag import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.AnnotatedString import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.LinkAnnotation
import androidx.compose.ui.text.SpanStyle import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.buildAnnotatedString import androidx.compose.ui.text.buildAnnotatedString
@ -73,6 +73,7 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextDecoration import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.text.withLink
import androidx.compose.ui.text.withStyle import androidx.compose.ui.text.withStyle
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.tooling.preview.PreviewParameter
@ -227,23 +228,31 @@ fun EmptySearchResultBody(
textAlign = TextAlign.Center, textAlign = TextAlign.Center,
modifier = Modifier.padding(vertical = 24.dp), modifier = Modifier.padding(vertical = 24.dp),
) )
val interests = stringResource(id = searchR.string.feature_search_interests)
val tryAnotherSearchString = buildAnnotatedString { val tryAnotherSearchString = buildAnnotatedString {
append(stringResource(id = searchR.string.feature_search_try_another_search)) append(stringResource(id = searchR.string.feature_search_try_another_search))
append(" ") append(" ")
withStyle( withLink(
style = SpanStyle( LinkAnnotation.Clickable(
textDecoration = TextDecoration.Underline, tag = "",
fontWeight = FontWeight.Bold, linkInteractionListener = {
onInterestsClick()
},
), ),
) { ) {
pushStringAnnotation(tag = interests, annotation = interests) withStyle(
append(interests) style = SpanStyle(
textDecoration = TextDecoration.Underline,
fontWeight = FontWeight.Bold,
),
) {
append(stringResource(id = searchR.string.feature_search_interests))
}
} }
append(" ") append(" ")
append(stringResource(id = searchR.string.feature_search_to_browse_topics)) append(stringResource(id = searchR.string.feature_search_to_browse_topics))
} }
ClickableText( Text(
text = tryAnotherSearchString, text = tryAnotherSearchString,
style = MaterialTheme.typography.bodyLarge.merge( style = MaterialTheme.typography.bodyLarge.merge(
TextStyle( TextStyle(
@ -252,13 +261,8 @@ fun EmptySearchResultBody(
), ),
), ),
modifier = Modifier modifier = Modifier
.padding(start = 36.dp, end = 36.dp, bottom = 24.dp) .padding(start = 36.dp, end = 36.dp, bottom = 24.dp),
.clickable {}, )
) { offset ->
tryAnotherSearchString.getStringAnnotations(start = offset, end = offset)
.firstOrNull()
?.let { onInterestsClick() }
}
} }
} }

Loading…
Cancel
Save