Created
September 28, 2025 14:41
-
-
Save ajinkya5130/506a637502737b862813502bfd96530a to your computer and use it in GitHub Desktop.
String resource in composeable
This file contains hidden or 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
| import androidx.compose.runtime.Composable | |
| import org.jetbrains.compose.resources.StringResource | |
| import org.jetbrains.compose.resources.getString | |
| import org.jetbrains.compose.resources.stringResource | |
| sealed interface UiText { | |
| data class DynamicString(val value: String) : UiText | |
| class Resource( | |
| val id: StringResource, | |
| val args: Array<Any> = arrayOf() | |
| ): UiText | |
| @Composable | |
| fun asString(): String{ | |
| return when(this){ | |
| is DynamicString -> value | |
| is Resource -> stringResource(resource = id, *args) | |
| } | |
| } | |
| suspend fun asStringAsync(): String{ | |
| return when(this){ | |
| is DynamicString -> value | |
| is Resource -> getString(resource = id, *args) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment