• Stars
    star
    405
  • Rank 106,656 (Top 3 %)
  • Language
    Kotlin
  • License
    MIT License
  • Created about 4 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Converts SVG and Android Vector Drawable in Compose Multiplatform source code

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

More Repositories

1

compose-icons

Popular Open Source icon packs for Compose Multiplatform
Kotlin
544
star
2

KotlinBukkitAPI

KotlinBukkitAPI is an API for Bukkit/SpigotAPI using the cool and nifty features Kotlin has to make your life more easier.
Kotlin
154
star
3

Bukkript

Bukkript is a custom Kotlin Scripting Definition for customizing Minecraft Bukkit servers
Kotlin
74
star
4

EventKt

EventKt is a simple and lightweight kotlin multiplatform event bus library
Kotlin
53
star
5

kmp-swift-reveal

Gradle plugin that reveal the Swift code that you should expect from a Kotlin iOS module.
Kotlin
49
star
6

dropbox-focus-intellij-plugin

IntelliJ/Android Studio plugin that integrates Dropbox Focus gradle plugin directly in the IDE.
Kotlin
31
star
7

kt-mc-packet

A Minecraft Protocol library for Kotlin Multiplatform
Kotlin
30
star
8

Redissed

Redis Kotlin wrapper inspired on Exposed
Kotlin
28
star
9

KotlinBukkitAPI-Tooling

The KotlinBukkitAPI Tooling is a IntelliJ plugin that helps developers using KotlinBukkitAPI and scripts for Bukkript.
Kotlin
15
star
10

KotlinNBT

Named Binary Tag (NBT) library for Kotlin Multiplataform
Kotlin
11
star
11

kotlinx.serialization.uri

Kotlinx serialization URI parser Multiplatform
Kotlin
10
star
12

Marknote

A simple markdown note app built with flutter
Dart
10
star
13

chuck-norris-creates-android

Android app using api.chucknorris.io
Kotlin
5
star
14

jda-kotlin-command

A small Kotlin library to create Guild commands for Discord using JDA and Kotlin Coroutines.
Kotlin
5
star
15

MCHeads

An open source Minecraft Custom Heads Database REST API
Kotlin
5
star
16

docker-kotlin-multiplatform

Kotlin
4
star
17

KtorScriptRoute

Script route using Kotlinx.html for Ktor
Kotlin
4
star
18

Marknote-Compose

A simple note app built with Jetpack Compose
Kotlin
4
star
19

MCHeads-app

An android app client for MCHeads using Kotlin and Android Jetpack.
Kotlin
3
star
20

kmp-swift-interop-expect-declaration

Demo project testing a Expect/Actual with Swift implementation
Kotlin
3
star
21

coroutines-alarm-delay

Delay your task in android with alarmDelay that truly runs (using AlarmManager)
Kotlin
3
star
22

kotlinx.serialization-sql

SQL queries generator using Kotlinx.serialization
Kotlin
2
star
23

Config4Bukkit

Typesafe Config for Bukkit FileConfiguration
Java
2
star
24

Json4Bukkit

Json FileConfiguration support (Bukkit).
Java
2
star
25

SouzaEconomy

Bukkit multiple Economy plugin
Kotlin
1
star
26

SimpleFTPServer

Simple ftp server using MinimalFTP
Java
1
star
27

workflow-metrics

A Kotlin application that runs for a period of time collecting system information for a Github Workflow
Kotlin
1
star
28

compose-tree-test

Testing Jetpack Compose runtime in a simple node tree
Kotlin
1
star
29

pokedex-compose-multiplatform

[WIP] Pokedex app experiment using Compose Multiplatform
Kotlin
1
star