Skip to content

Commit 374b8fa

Browse files
authored
Merge pull request #448 from icerockdev/develop
Release 0.21.1
2 parents 6d9d055 + 17c89d7 commit 374b8fa

12 files changed

Lines changed: 46 additions & 24 deletions

File tree

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ buildscript {
5858
}
5959
6060
dependencies {
61-
classpath "dev.icerock.moko:resources-generator:0.21.0"
61+
classpath "dev.icerock.moko:resources-generator:0.21.1"
6262
}
6363
}
6464
@@ -76,10 +76,10 @@ project build.gradle
7676
apply plugin: "dev.icerock.mobile.multiplatform-resources"
7777
7878
dependencies {
79-
commonMainApi("dev.icerock.moko:resources:0.21.0")
80-
commonMainApi("dev.icerock.moko:resources-compose:0.21.0") // for compose multiplatform
79+
commonMainApi("dev.icerock.moko:resources:0.21.1")
80+
commonMainApi("dev.icerock.moko:resources-compose:0.21.1") // for compose multiplatform
8181
82-
commonTestImplementation("dev.icerock.moko:resources-test:0.21.0")
82+
commonTestImplementation("dev.icerock.moko:resources-test:0.21.1")
8383
}
8484
8585
multiplatformResources {
@@ -98,7 +98,7 @@ should [add `export` declarations](https://kotlinlang.org/docs/multiplatform-bui
9898

9999
```
100100
framework {
101-
export("dev.icerock.moko:resources:0.21.0")
101+
export("dev.icerock.moko:resources:0.21.1")
102102
export("dev.icerock.moko:graphics:0.9.0") // toUIColor here
103103
}
104104
```

gradle/moko.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[versions]
2-
resourcesVersion = "0.21.0"
2+
resourcesVersion = "0.21.1"
33

44
[libraries]
55
resources = { module = "dev.icerock.moko:resources", version.ref = "resourcesVersion" }

resources-compose/src/androidMain/kotlin/dev/icerock/moko/resources/compose/AssetResource.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import dev.icerock.moko.resources.AssetResource
1414
@Composable
1515
actual fun AssetResource.readTextAsState(): State<String?> {
1616
val context: Context = LocalContext.current
17-
return produceState<String?>(null) {
17+
return produceState<String?>(null, this, context) {
1818
value = readText(context)
1919
}
2020
}

resources-compose/src/androidMain/kotlin/dev/icerock/moko/resources/compose/FileResource.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import dev.icerock.moko.resources.FileResource
1414
@Composable
1515
actual fun FileResource.readTextAsState(): State<String?> {
1616
val context: Context = LocalContext.current
17-
return produceState<String?>(null) {
17+
return produceState<String?>(null, this, context) {
1818
value = readText(context)
1919
}
2020
}

resources-compose/src/appleMain/kotlin/dev/icerock/moko/resources/compose/FileResource.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import dev.icerock.moko.resources.FileResource
1111

1212
@Composable
1313
actual fun FileResource.readTextAsState(): State<String?> {
14-
return produceState<String?>(null) {
14+
return produceState<String?>(null, this) {
1515
value = readText()
1616
}
1717
}

resources-compose/src/jsMain/kotlin/dev/icerock/moko/resources/compose/AssetResource.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import dev.icerock.moko.resources.AssetResource
1111

1212
@Composable
1313
actual fun AssetResource.readTextAsState(): State<String?> {
14-
return produceState<String?>(null) {
14+
return produceState<String?>(null, this) {
1515
value = getText()
1616
}
1717
}

resources-compose/src/jsMain/kotlin/dev/icerock/moko/resources/compose/FileResource.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import dev.icerock.moko.resources.FileResource
1111

1212
@Composable
1313
actual fun FileResource.readTextAsState(): State<String?> {
14-
return produceState<String?>(null) {
14+
return produceState<String?>(initialValue = null, this) {
1515
value = getText()
1616
}
1717
}

resources-compose/src/jsMain/kotlin/dev/icerock/moko/resources/compose/StringDescExt.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import dev.icerock.moko.resources.desc.StringDesc
1010

1111
@Composable
1212
actual fun StringDesc.localized(): String {
13-
return produceState("") {
13+
return produceState("", this) {
1414
value = localized()
1515
}.value
1616
}

resources-compose/src/jsMain/kotlin/dev/icerock/moko/resources/compose/StringResource.kt

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package dev.icerock.moko.resources.compose
66

77
import androidx.compose.runtime.Composable
88
import androidx.compose.runtime.produceState
9+
import androidx.compose.runtime.remember
910
import dev.icerock.moko.resources.PluralsResource
1011
import dev.icerock.moko.resources.StringResource
1112
import dev.icerock.moko.resources.desc.Plural
@@ -15,19 +16,40 @@ import dev.icerock.moko.resources.desc.ResourceFormatted
1516
import 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+
}

resources-compose/src/jsMain/kotlin/dev/icerock/moko/resources/compose/internal/produceByteArray.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import org.w3c.fetch.Response
1515

1616
@Composable
1717
internal fun produceByteArray(url: String): State<ByteArray?> {
18-
return produceState<ByteArray?>(null) {
18+
return produceState<ByteArray?>(null, url) {
1919
val response: Response = window.fetch(url).await()
2020

2121
if (response.ok.not()) {

0 commit comments

Comments
 (0)