Giter Club home page Giter Club logo

svg-to-compose's Introduction

SVG to Compose [Experimental]

Converts SVG or Android Vector Drawable to Compose code.

Why this project

On the start of the Compose for Desktop it does not support SVG files and Android Vector Drawables. This also difficulties a migration of the App to Multiplatform (Desktop and Android). Currently, it does support Android Vector Drawables in the Desktop allowing share your vectors.

Use cases

Now Compose for Desktop supports android vector drawables, this means that the first reason that the project was created does not apply anymore, this does not mean that it is not useful anymore.

Use cases:

  • Manipulate dynamic an SVG file in code, you can generate and do source code modifications.
  • Create an Icon pack similar to how Material Icons works on Compose (compose-icons is build with SVG to Compose)

How its work

The project uses Android's Svg2Vector to convert SVG to Android Drawables and uses a customized material icon code generator from the Jetpack Compose source code to generate the source code of the SVG file.

Example 1: Running with Kotlin Scripting

file: jetnews-drawables-to-compose.main.kts

@file:Repository("https://jitpack.io")
@file:Repository("https://maven.google.com")
@file:Repository("https://jetbrains.bintray.com/trove4j")

@file:DependsOn("com.github.DevSrSouza:svg-to-compose:-SNAPSHOT")
@file:DependsOn("com.google.guava:guava:23.0")
@file:DependsOn("com.android.tools:sdk-common:27.2.0-alpha16")
@file:DependsOn("com.android.tools:common:27.2.0-alpha16")
@file:DependsOn("com.squareup:kotlinpoet:1.7.2")
@file:DependsOn("org.ogce:xpp3:1.1.6")

import br.com.devsrsouza.svg2compose.Svg2Compose
import br.com.devsrsouza.svg2compose.VectorType
import java.io.File

val assetsDir = File("assets")
val srcDir = File("src/main/kotlin")

Svg2Compose.parse(
    applicationIconPackage = "assets",
    accessorName = "JetnewsAssets",
    outputSourceDirectory = srcDir,
    vectorsDirectory = assetsDir,
    type = VectorType.DRAWABLE,
    allAssetsPropertyName = "AllAssets"
)

Generating code by using executing kotlin jetnews-drawables-to-compose

Using in code: JetnewsAssets.JetnewsLogo

Svg

The only difference for SVG files is the VectorType.SVG.

Example 2: Generating a whole Icon pack

For Icon Packs, subgroups is supported: IconPack/group/icon.svg

val assetsDir = File("linea-icons")
val srcDir = File("src/main/kotlin")

Svg2Compose.parse(
    applicationIconPackage = "assets",
    accessorName = "LineaIcons",
    outputSourceDirectory = srcDir,
    vectorsDirectory = assetsDir,
    type = VectorType.SVG,
    iconNameTransformer = { name, group -> name.removePrefix(group) },
    allAssetsPropertyName = "AllIcons"
)

Using in code: LineaIcons.Arrows.Buhttps://github.com/overpas/svg-to-compose-intellijttonUp

The project also generate an accessor for all yours assets, for the given example, it should be LineaIcons.AllIcons and it also generated for child groups LineaIcons.Arrows.AllIcons

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.