Skip to content

CodandoTV/jujubaSVG

Repository files navigation

Kotlin badge-android PRs Welcome Maven Central Version Unit tests MegaLinter

Welcome to the JujubaSVG library 👋

Welcome to the jujubaSVG library!

jujubaSVG library is a friendly library to handle SVG files in your Android app. The library allows you to manipulate piece by piece of your SVG. If you have an id for the element, you can access it to change background, stroke, and other things.

📚 Our documentation is available here.


How to use? 🤔

You need to add the following line in your desired module/build.gradle.kts:

// ...
dependencies {
    implementation("io.github.codandotv:jujubaSVG:<library version>")
    // ...
}
    // ...

After that, you need to define at the top level of your composable function the commander (a friend that will help you to send commands to the library):

@Composable
fun YourComposable() {
    val jujubaCommander = rememberJujubaCommander()
    // ...
}

Now you need to declare the Widget responsible to render the SVG file:

@Composable
fun YourComposable() {
    val jujubaCommander = rememberJujubaCommander()

    JujubaSVG(
        svgText = svgText,
        onElementClick = { nodeInfo ->
            println("NodeInfo $nodeInfo")
            coroutineScope.launch {
                // commander sample
                jujubaCommander.execute(
                    Command.RemoveNode(
                        nodeInfo.id
                    )
                )
            }
        },
        commander = jujubaCommander,
    )
}

Don't forget:

  • svgText should contain all content of your SVG file.

Sample project

More details you can check at our sample project

teaser showing the app working with SVG image, where onClick deletes a State from Brazil.

How to contribute?

  • Fork this repository;

  • Solve an issue, or do any improvement you want;

  • Open a PR to the origin repository.

As soon the PR is reviewed and merged, your update will be available.