forked from touchlab/KaMPKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For touchlab#305 - Use Compose Multiplatform to show the UI from :sha…
…red on Android Added moko-resources as the community preferred approach to using strings in similar scenarios. Added the materialIconsExtended dependency for :shared instead of reusing the vector images shown previously from :app since those vectors are not in a format moko-resources supports at this moment (though it support SVGs). While this is a big package R8 will ensure unused resources are stripped from the generated builds at compile time.
- Loading branch information
Showing
11 changed files
with
92 additions
and
44 deletions.
There are no files selected for viewing
This file contains 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
24 changes: 24 additions & 0 deletions
24
shared/src/androidMain/kotlin/co/touchlab/kampkit/utils/Strings.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package co.touchlab.kampkit.utils | ||
|
||
import android.content.Context | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.platform.LocalContext | ||
import dev.icerock.moko.resources.StringResource | ||
import dev.icerock.moko.resources.desc.Resource | ||
import dev.icerock.moko.resources.desc.StringDesc | ||
import dev.icerock.moko.resources.format | ||
|
||
actual class Strings(private val context: Context) { | ||
actual fun get(id: StringResource, args: List<Any>): String { | ||
return when (args.isEmpty()) { | ||
true -> StringDesc.Resource(id).toString(context) | ||
false -> id.format(*args.toTypedArray()).toString(context) | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Get a string existing in the shared module. | ||
*/ | ||
@Composable | ||
fun getString(id: StringResource, vararg args: Any) = Strings(LocalContext.current).get(id, args.toList()) |
This file contains 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
7 changes: 7 additions & 0 deletions
7
shared/src/commonMain/kotlin/co/touchlab/kampkit/utils/Strings.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package co.touchlab.kampkit.utils | ||
|
||
import dev.icerock.moko.resources.StringResource | ||
|
||
expect class Strings { | ||
fun get(id: StringResource, args: List<Any>): String | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<resources> | ||
<string name="app_name">KaMP Kit</string> | ||
<string name="favorite_breed">Favorite %1$s</string> | ||
<string name="unfavorite_breed">Unfavorite %1$s</string> | ||
<string name="empty_breeds">Sorry, no doggos found</string> | ||
</resources> |
13 changes: 13 additions & 0 deletions
13
shared/src/iosMain/kotlin/co/touchlab/kampkit/utils/Strings.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package co.touchlab.kampkit.utils | ||
|
||
import dev.icerock.moko.resources.StringResource | ||
import dev.icerock.moko.resources.desc.Resource | ||
import dev.icerock.moko.resources.desc.StringDesc | ||
import dev.icerock.moko.resources.format | ||
|
||
actual class Strings { | ||
actual fun get(id: StringResource, args: List<Any>) = when (args.isEmpty()) { | ||
true -> StringDesc.Resource(id).localized() | ||
false -> id.format(*args.toTypedArray()).localized() | ||
} | ||
} |