Skip to content

Commit beb3fb2

Browse files
authored
Merge pull request #508 from icerockdev/develop
Release 0.23.0
2 parents d86f4f5 + ed99f37 commit beb3fb2

26 files changed

Lines changed: 880 additions & 191 deletions

File tree

README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ buildscript {
6262
}
6363
6464
dependencies {
65-
classpath "dev.icerock.moko:resources-generator:0.22.3"
65+
classpath "dev.icerock.moko:resources-generator:0.23.0"
6666
}
6767
}
6868
@@ -80,10 +80,10 @@ project build.gradle
8080
apply plugin: "dev.icerock.mobile.multiplatform-resources"
8181
8282
dependencies {
83-
commonMainApi("dev.icerock.moko:resources:0.22.3")
84-
commonMainApi("dev.icerock.moko:resources-compose:0.22.3") // for compose multiplatform
83+
commonMainApi("dev.icerock.moko:resources:0.23.0")
84+
commonMainApi("dev.icerock.moko:resources-compose:0.23.0") // for compose multiplatform
8585
86-
commonTestImplementation("dev.icerock.moko:resources-test:0.22.3")
86+
commonTestImplementation("dev.icerock.moko:resources-test:0.23.0")
8787
}
8888
8989
multiplatformResources {
@@ -102,7 +102,7 @@ should [add `export` declarations](https://kotlinlang.org/docs/multiplatform-bui
102102

103103
```
104104
framework {
105-
export("dev.icerock.moko:resources:0.22.3")
105+
export("dev.icerock.moko:resources:0.23.0")
106106
export("dev.icerock.moko:graphics:0.9.0") // toUIColor here
107107
}
108108
```
@@ -629,6 +629,15 @@ with compose you can just call in `commonMain`
629629
val fontFamily: FontFamily = fontFamilyResource(MR.fonts.Raleway.italic)
630630
```
631631

632+
or you can get `Font`
633+
634+
```kotlin
635+
val font: Font = MR.fonts.Raleway.italic.asFont(
636+
weight = FontWeight.Normal, // optional
637+
style = FontStyle.Normal // optional
638+
)
639+
```
640+
632641
### Example 9 - pass colors
633642

634643
Colors resources directory is `commonMain/resources/MR/colors`.

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[versions]
2-
kotlinVersion = "1.8.10"
2+
kotlinVersion = "1.8.20"
33
androidGradleVersion = "7.4.2"
44
androidSdkCommonVersion = "31.0.0"
55

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.22.3"
2+
resourcesVersion = "0.23.0"
33

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

kotlin-js-store/yarn.lock

Lines changed: 364 additions & 20 deletions
Large diffs are not rendered by default.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2023 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package dev.icerock.moko.resources.compose
6+
7+
import androidx.compose.runtime.Composable
8+
import androidx.compose.runtime.remember
9+
import androidx.compose.ui.text.font.Font
10+
import androidx.compose.ui.text.font.FontStyle
11+
import androidx.compose.ui.text.font.FontWeight
12+
import dev.icerock.moko.resources.FontResource
13+
14+
@Composable
15+
actual fun FontResource.asFont(
16+
weight: FontWeight,
17+
style: FontStyle,
18+
): Font? = remember(fontResourceId) {
19+
Font(
20+
resId = fontResourceId,
21+
weight = weight,
22+
style = style,
23+
)
24+
}

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

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright 2023 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package dev.icerock.moko.resources.compose
6+
7+
import androidx.compose.runtime.Composable
8+
import androidx.compose.ui.text.font.Font
9+
import androidx.compose.ui.text.font.FontFamily
10+
import androidx.compose.ui.text.font.FontStyle
11+
import androidx.compose.ui.text.font.FontWeight
12+
import dev.icerock.moko.resources.FontResource
13+
14+
@Composable
15+
fun fontFamilyResource(fontResource: FontResource): FontFamily {
16+
return fontResource.asFont()
17+
?.let { FontFamily(it) }
18+
?: FontFamily.Default
19+
}
20+
21+
@Composable
22+
expect fun FontResource.asFont(
23+
weight: FontWeight = FontWeight.Normal,
24+
style: FontStyle = FontStyle.Normal,
25+
): Font?

resources-compose/src/commonMain/kotlin/dev/icerock/moko/resources/compose/FontResource.kt

Lines changed: 0 additions & 12 deletions
This file was deleted.

resources-compose/src/macosMain/kotlin/dev/icerock/moko/resources/compose/FontResource.kt renamed to resources-compose/src/iosMain/kotlin/dev/icerock/moko/resources/compose/FontResource.ios.kt

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,22 @@ package dev.icerock.moko.resources.compose
66

77
import androidx.compose.runtime.Composable
88
import androidx.compose.runtime.remember
9-
import androidx.compose.ui.text.font.FontFamily
9+
import androidx.compose.ui.text.font.Font
10+
import androidx.compose.ui.text.font.FontStyle
11+
import androidx.compose.ui.text.font.FontWeight
1012
import androidx.compose.ui.text.platform.Font
1113
import dev.icerock.moko.resources.FontResource
1214
import dev.icerock.moko.resources.compose.internal.toByteArray
1315

1416
@Composable
15-
actual fun fontFamilyResource(fontResource: FontResource): FontFamily {
16-
return remember(fontResource) {
17-
val font = Font(
18-
identity = fontResource.fontName,
19-
data = fontResource.data.toByteArray()
20-
)
21-
22-
FontFamily(font)
23-
}
17+
actual fun FontResource.asFont(
18+
weight: FontWeight,
19+
style: FontStyle,
20+
): Font? = remember(filePath) {
21+
Font(
22+
identity = fontName,
23+
data = data.toByteArray(),
24+
weight = weight,
25+
style = style,
26+
)
2427
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2023 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package dev.icerock.moko.resources.compose
6+
7+
import androidx.compose.runtime.Composable
8+
import androidx.compose.runtime.getValue
9+
import androidx.compose.runtime.remember
10+
import androidx.compose.ui.text.font.Font
11+
import androidx.compose.ui.text.font.FontStyle
12+
import androidx.compose.ui.text.font.FontWeight
13+
import androidx.compose.ui.text.platform.Font
14+
import dev.icerock.moko.resources.FontResource
15+
import dev.icerock.moko.resources.compose.internal.produceByteArray
16+
17+
@Composable
18+
actual fun FontResource.asFont(
19+
weight: FontWeight,
20+
style: FontStyle,
21+
): Font? {
22+
val bytes: ByteArray? by produceByteArray(url = fileUrl)
23+
24+
return remember(fileUrl, bytes?.size ?: 0) {
25+
bytes?.let { b ->
26+
Font(
27+
identity = fontFamily,
28+
data = b,
29+
weight = weight,
30+
style = style,
31+
)
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)