|
|
|
@ -13,6 +13,7 @@ import androidx.compose.ui.Modifier
|
|
|
|
|
import androidx.compose.ui.graphics.Color
|
|
|
|
|
import androidx.compose.ui.text.SpanStyle
|
|
|
|
|
import androidx.compose.ui.text.buildAnnotatedString
|
|
|
|
|
import androidx.compose.ui.text.style.TextDecoration
|
|
|
|
|
import androidx.compose.ui.tooling.preview.Preview
|
|
|
|
|
import androidx.compose.ui.unit.sp
|
|
|
|
|
import org.mozilla.fenix.theme.FirefoxTheme
|
|
|
|
@ -23,6 +24,8 @@ import org.mozilla.fenix.theme.Theme
|
|
|
|
|
*
|
|
|
|
|
* @param text Full text that will be displayed
|
|
|
|
|
* @param textColor [Color] of the normal text. The URL substring will have a default URL style applied.
|
|
|
|
|
* @param linkTextColor [Color] of the link text.
|
|
|
|
|
* @param linkTextDecoration The decorations to paint on the link text (e.g., an underline).
|
|
|
|
|
* @param clickableStartIndex [text] index at which the URL substring starts.
|
|
|
|
|
* @param clickableEndIndex [text] index at which the URL substring ends.
|
|
|
|
|
* @param onClick Callback to be invoked only when the URL substring is clicked.
|
|
|
|
@ -30,7 +33,9 @@ import org.mozilla.fenix.theme.Theme
|
|
|
|
|
@Composable
|
|
|
|
|
fun ClickableSubstringLink(
|
|
|
|
|
text: String,
|
|
|
|
|
textColor: Color,
|
|
|
|
|
textColor: Color = FirefoxTheme.colors.textPrimary,
|
|
|
|
|
linkTextColor: Color = FirefoxTheme.colors.textAccent,
|
|
|
|
|
linkTextDecoration: TextDecoration? = null,
|
|
|
|
|
clickableStartIndex: Int,
|
|
|
|
|
clickableEndIndex: Int,
|
|
|
|
|
onClick: () -> Unit,
|
|
|
|
@ -45,7 +50,10 @@ fun ClickableSubstringLink(
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
addStyle(
|
|
|
|
|
SpanStyle(color = FirefoxTheme.colors.textAccent),
|
|
|
|
|
SpanStyle(
|
|
|
|
|
color = linkTextColor,
|
|
|
|
|
textDecoration = linkTextDecoration,
|
|
|
|
|
),
|
|
|
|
|
start = clickableStartIndex,
|
|
|
|
|
end = clickableEndIndex,
|
|
|
|
|
)
|
|
|
|
@ -91,7 +99,7 @@ private fun ClickableSubstringTextPreview() {
|
|
|
|
|
Box(modifier = Modifier.background(color = FirefoxTheme.colors.layer1)) {
|
|
|
|
|
ClickableSubstringLink(
|
|
|
|
|
text = text,
|
|
|
|
|
textColor = FirefoxTheme.colors.textPrimary,
|
|
|
|
|
linkTextDecoration = TextDecoration.Underline,
|
|
|
|
|
clickableStartIndex = text.indexOf("link"),
|
|
|
|
|
clickableEndIndex = text.length,
|
|
|
|
|
) { }
|
|
|
|
|