-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improvement: change goal card empty text
- Loading branch information
Showing
4 changed files
with
91 additions
and
22 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
core/ui/src/main/java/com/br/weightcontrol/ui/text/CustomAnnotadeString.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,52 @@ | ||
package com.br.weightcontrol.ui.text | ||
|
||
import androidx.annotation.StringRes | ||
import androidx.compose.foundation.text.InlineTextContent | ||
import androidx.compose.foundation.text.appendInlineContent | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.graphics.vector.ImageVector | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.AnnotatedString | ||
import androidx.compose.ui.text.Placeholder | ||
import androidx.compose.ui.text.PlaceholderVerticalAlign | ||
import androidx.compose.ui.text.buildAnnotatedString | ||
import androidx.compose.ui.unit.sp | ||
|
||
typealias EntryInlineTextContent = Map<String, InlineTextContent> | ||
|
||
private const val ICON_ID = "inlineContent" | ||
private const val ICON_PLACE_HOLDER = "[icon]" | ||
|
||
@Composable | ||
fun stringResourceWithIcon( | ||
@StringRes text: Int, | ||
icon: ImageVector, | ||
delimiter: String | ||
): Pair<AnnotatedString, EntryInlineTextContent> { | ||
val stringResources = stringResource(id = text).split(delimiter) | ||
val inlineContent = createInlineContent(icon) | ||
val annotatedString = buildAnnotatedString { | ||
stringResources.getOrNull(0)?.let(::append) | ||
appendInlineContent(ICON_ID, ICON_PLACE_HOLDER) | ||
stringResources.getOrNull(1)?.let(::append) | ||
} | ||
|
||
return Pair(annotatedString, inlineContent) | ||
} | ||
|
||
@Composable | ||
private fun createInlineContent(icon: ImageVector) = mapOf( | ||
Pair( | ||
ICON_ID, | ||
InlineTextContent( | ||
Placeholder( | ||
width = 20.sp, | ||
height = 20.sp, | ||
placeholderVerticalAlign = PlaceholderVerticalAlign.Center | ||
) | ||
) { | ||
Icon(icon, null) | ||
} | ||
) | ||
) |
24 changes: 24 additions & 0 deletions
24
core/ui/src/main/java/com/br/weightcontrol/ui/text/TextWithIcon.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,24 @@ | ||
package com.br.weightcontrol.ui.text | ||
|
||
import androidx.annotation.StringRes | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.vector.ImageVector | ||
import androidx.compose.ui.unit.dp | ||
|
||
private const val DELIMITER = "#" | ||
|
||
/** | ||
* Provide a text with a delimiter for replacing to an icon | ||
*/ | ||
@Composable | ||
fun TextWithIcon(@StringRes text: Int, icon: ImageVector, delimiter: String = DELIMITER) { | ||
val stringResourceWithIcon = stringResourceWithIcon(text, icon, delimiter) | ||
Text( | ||
text = stringResourceWithIcon.first, | ||
inlineContent = stringResourceWithIcon.second, | ||
modifier = Modifier.padding(top = 16.dp), | ||
) | ||
} |
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