-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: make learn more links clickable for automation [WPB-5888] (#…
…2923) Co-authored-by: Michał Saleniuk <[email protected]> Co-authored-by: Michał Saleniuk <[email protected]>
- Loading branch information
1 parent
114d60a
commit 0acad2f
Showing
7 changed files
with
267 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
app/src/main/kotlin/com/wire/android/ui/common/PreviewTextWithLinkSuffix.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2024 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
package com.wire.android.ui.common | ||
|
||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.LocalDensity | ||
import androidx.compose.ui.text.AnnotatedString | ||
import androidx.compose.ui.text.rememberTextMeasurer | ||
import androidx.compose.ui.text.style.TextDecoration | ||
import androidx.compose.ui.unit.Dp | ||
import com.wire.android.ui.theme.WireTheme | ||
import com.wire.android.ui.theme.wireTypography | ||
import com.wire.android.util.ui.PreviewMultipleThemes | ||
|
||
@Composable | ||
private fun PreviewTextWithLinkSuffixBuilder( | ||
textLines: List<String> = listOf("This is a text with a link"), | ||
linkText: String = "link", | ||
calculateWidth: (lastTextLineWidthDp: Dp, linkWidthDp: Dp) -> Dp | ||
) { | ||
val textStyle = MaterialTheme.wireTypography.body01 | ||
val linkStyle = MaterialTheme.wireTypography.body02.copy(textDecoration = TextDecoration.Underline) | ||
val textMeasurer = rememberTextMeasurer() | ||
val lastTextLineLayoutResult = textMeasurer.measure(text = "${textLines.last()} ", style = textStyle) | ||
val linkLayoutResult = textMeasurer.measure(text = linkText, style = linkStyle) | ||
val density = LocalDensity.current | ||
val lastTextLineWidthDp = with(density) { lastTextLineLayoutResult.size.width.toDp() } | ||
val linkWidthDp = with(density) { linkLayoutResult.size.width.toDp() } | ||
TextWithLinkSuffix( | ||
text = AnnotatedString(textLines.joinToString(separator = "\n")), | ||
linkText = linkText, | ||
onLinkClick = {}, | ||
modifier = Modifier.width(calculateWidth(lastTextLineWidthDp, linkWidthDp)) | ||
) | ||
} | ||
|
||
@PreviewMultipleThemes | ||
@Composable | ||
fun PreviewTextWithLinkSuffixWithoutALink() = WireTheme { | ||
TextWithLinkSuffix(text = AnnotatedString("This is a text without a link")) | ||
} | ||
|
||
@PreviewMultipleThemes | ||
@Composable | ||
fun PreviewTextWithLinkSuffixFittingInSameLine() = WireTheme { | ||
PreviewTextWithLinkSuffixBuilder { lastTextLineWidthDp, linkWidthDp -> lastTextLineWidthDp + linkWidthDp } | ||
} | ||
|
||
@PreviewMultipleThemes | ||
@Composable | ||
fun PreviewTextWithLinkSuffixNotFittingInSameLine() = WireTheme { | ||
PreviewTextWithLinkSuffixBuilder { lastTextLineWidthDp, linkWidthDp -> lastTextLineWidthDp + (linkWidthDp / 2) } | ||
} | ||
|
||
@PreviewMultipleThemes | ||
@Composable | ||
fun PreviewTextWithLinkSuffixMultilineFittingInLastLine() = WireTheme { | ||
PreviewTextWithLinkSuffixBuilder( | ||
textLines = listOf("This is a text with a link", "This is a text with a"), | ||
linkText = "link", | ||
) { lastTextLineWidthDp, linkWidthDp -> lastTextLineWidthDp + linkWidthDp } | ||
} | ||
|
||
@PreviewMultipleThemes | ||
@Composable | ||
fun PreviewTextWithLinkSuffixMultilineNotFittingInLastLine() = WireTheme { | ||
PreviewTextWithLinkSuffixBuilder( | ||
textLines = listOf("This is a text with a", "This is a text with a"), | ||
linkText = "link" | ||
) { lastTextLineWidthDp, linkWidthDp -> lastTextLineWidthDp + (linkWidthDp / 2) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.