
Unified SVG rendering API offering a rememberSvgPainter composable and SvgImage wrapper, with platform-specific optimizations — native renderer integration and asynchronous caching for efficient, seamless SVG use.
A Kotlin Multiplatform library that provides a unified API for rendering SVG resources, with platform-specific optimizations.
painterResource for seamless integration.rememberSvgPainter Composable that works across all supported targets.Add the dependency to your build.gradle.kts (commonMain):
kotlin {
sourceSets {
commonMain.dependencies {
// Replace with latest version
implementation("io.github.loshine:multiplatform-resources-svg:{latest_version}")
}
}
}Use rememberSvgPainter to load and render your SVG resources. This function acts as a drop-in replacement for painterResource when working with SVGs, ensuring optimal handling on Android.
import androidx.compose.foundation.Image
import androidx.compose.runtime.Composable
import io.github.loshine.svg.rememberSvgPainter
import kotlinproject.composeapp.generated.resources.Res
import kotlinproject.composeapp.generated.resources.my_icon
@Composable
fun MyIcon() {
Image(
painter = rememberSvgPainter(Res.drawable.my_icon),
contentDescription = "My Icon"
)
}Alternatively, you can use the SvgImage composable directly, which wraps Image and rememberSvgPainter for convenience:
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import io.github.loshine.svg.SvgImage
import kotlinproject.composeapp.generated.resources.Res
import kotlinproject.composeapp.generated.resources.my_icon
@Composable
fun MyIcon() {
SvgImage(
resource = Res.drawable.my_icon,
contentDescription = "My Icon",
// Optional: Apply modifiers, scaling, etc.
modifier = Modifier.size(24.dp)
)
}This library wouldn't be possible without the following amazing open-source project:
A Kotlin Multiplatform library that provides a unified API for rendering SVG resources, with platform-specific optimizations.
painterResource for seamless integration.rememberSvgPainter Composable that works across all supported targets.Add the dependency to your build.gradle.kts (commonMain):
kotlin {
sourceSets {
commonMain.dependencies {
// Replace with latest version
implementation("io.github.loshine:multiplatform-resources-svg:{latest_version}")
}
}
}Use rememberSvgPainter to load and render your SVG resources. This function acts as a drop-in replacement for painterResource when working with SVGs, ensuring optimal handling on Android.
import androidx.compose.foundation.Image
import androidx.compose.runtime.Composable
import io.github.loshine.svg.rememberSvgPainter
import kotlinproject.composeapp.generated.resources.Res
import kotlinproject.composeapp.generated.resources.my_icon
@Composable
fun MyIcon() {
Image(
painter = rememberSvgPainter(Res.drawable.my_icon),
contentDescription = "My Icon"
)
}Alternatively, you can use the SvgImage composable directly, which wraps Image and rememberSvgPainter for convenience:
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import io.github.loshine.svg.SvgImage
import kotlinproject.composeapp.generated.resources.Res
import kotlinproject.composeapp.generated.resources.my_icon
@Composable
fun MyIcon() {
SvgImage(
resource = Res.drawable.my_icon,
contentDescription = "My Icon",
// Optional: Apply modifiers, scaling, etc.
modifier = Modifier.size(24.dp)
)
}This library wouldn't be possible without the following amazing open-source project: