Pablo
01/12/2025, 7:40 PMChrimaeon
01/12/2025, 7:56 PMdata class StringResource(
val id: Int,
val args: Array<Any>?
)
and use it like this
@Composable
fun MyComposable() {
val stringResource =
StringResource(
id = R.string.ok,
args = arrayOf("Foo", 1),
)
Text(
stringResource(stringResource.id, *stringResource.args.orEmpty()),
)
}
Pablo
01/12/2025, 7:59 PMPablo
01/12/2025, 7:59 PMdata class LinesDBScreenUiState(
val loading: Boolean = false,
val message: StringResourceWithParameters? = null,
val data: List<Line> = emptyList()
)
data class StringResourceWithParameters(
val resource: StringResource,
val parameters: Any = emptyList<Any>()
)
Chrimaeon
01/12/2025, 8:00 PMList
will not work though if you need to send id as varags
to the stringResource
Chrimaeon
01/12/2025, 8:01 PM***stringResource.args
Pablo
01/12/2025, 8:01 PMstringResource(message.resource, message.parameters),
Chrimaeon
01/12/2025, 8:02 PMChrimaeon
01/12/2025, 8:04 PMstringResource(id, listOf("2", "3"))
instead of stringResource(id, "2", "3")
Chrimaeon
01/12/2025, 8:08 PMChrimaeon
01/12/2025, 8:09 PMYou can pass a variable number of arguments (`vararg`) with names using theoperator:spread
```fun foo(vararg strings: String) { /*...*/ }
foo(strings = *arrayOf("a", "b", "c"))```
hfhbd
01/12/2025, 8:36 PMChrimaeon
01/12/2025, 8:41 PMPablo
01/12/2025, 8:48 PMChrimaeon
01/12/2025, 8:50 PMPablo
01/12/2025, 8:55 PMPablo
01/12/2025, 9:31 PMPablo
01/12/2025, 9:31 PMSanlorng
01/14/2025, 11:28 PMsuspend fun getString(res: StringRes)
if you are using Compose Components Resources as Resources library.Pablo
01/15/2025, 8:15 AMSanlorng
01/15/2025, 1:37 PMPablo
01/15/2025, 2:18 PMSanlorng
01/15/2025, 3:37 PM