@@ -6,6 +6,7 @@ package dev.icerock.moko.resources.compose
66
77import androidx.compose.runtime.Composable
88import androidx.compose.runtime.produceState
9+ import androidx.compose.runtime.remember
910import dev.icerock.moko.resources.PluralsResource
1011import dev.icerock.moko.resources.StringResource
1112import dev.icerock.moko.resources.desc.Plural
@@ -15,19 +16,40 @@ import dev.icerock.moko.resources.desc.ResourceFormatted
1516import dev.icerock.moko.resources.desc.StringDesc
1617
1718@Composable
18- actual fun stringResource (resource : StringResource ): String =
19- produceState(" " ) { value = StringDesc .Resource (resource).localized() }.value
19+ actual fun stringResource (resource : StringResource ): String {
20+ val stringDesc: StringDesc = remember(resource) {
21+ StringDesc .Resource (resource)
22+ }
23+ return localized(stringDesc)
24+ }
2025
2126@Composable
22- actual fun stringResource (resource : StringResource , vararg args : Any ): String =
23- produceState(" " ) { value = StringDesc .ResourceFormatted (resource, * args).localized() }.value
27+ actual fun stringResource (resource : StringResource , vararg args : Any ): String {
28+ val stringDesc: StringDesc = remember(resource, args) {
29+ StringDesc .ResourceFormatted (resource, * args)
30+ }
31+ return localized(stringDesc)
32+ }
2433
2534@Composable
26- actual fun stringResource (resource : PluralsResource , quantity : Int ): String =
27- produceState(" " ) { value = StringDesc .Plural (resource, quantity).localized() }.value
35+ actual fun stringResource (resource : PluralsResource , quantity : Int ): String {
36+ val stringDesc: StringDesc = remember(resource, quantity) {
37+ StringDesc .Plural (resource, quantity)
38+ }
39+ return localized(stringDesc)
40+ }
2841
2942@Composable
30- actual fun stringResource (resource : PluralsResource , quantity : Int , vararg args : Any ): String =
31- produceState(" " ) {
32- value = StringDesc .PluralFormatted (resource, quantity, * args).localized()
43+ actual fun stringResource (resource : PluralsResource , quantity : Int , vararg args : Any ): String {
44+ val stringDesc: StringDesc = remember(resource, quantity, args) {
45+ StringDesc .PluralFormatted (resource, quantity, * args)
46+ }
47+ return localized(stringDesc)
48+ }
49+
50+ @Composable
51+ private fun localized (stringDesc : StringDesc ): String {
52+ return produceState(initialValue = " " , stringDesc) {
53+ value = stringDesc.localized()
3354 }.value
55+ }
0 commit comments