halilozercan / compose-richtext

A collection of Compose libraries for advanced text formatting and alternative display types.
https://halilibo.com/compose-richtext
Apache License 2.0
791 stars 65 forks source link

Support compose for desktop #25

Closed zach-klippenstein closed 3 years ago

zach-klippenstein commented 3 years ago

Probably requires making this library MPP, but that should be about it. The same implementation should work out of the box.

LouisCAD commented 3 years ago

Are there any steps that I could help with?

I'd be happy to try to contribute to this feature either via remote pairing, or PRs, or both.

halilozercan commented 3 years ago

Implementation for KMP support is completed. I have one major reservation about this though. Compose Desktop uses org.jetbrains.compose artifacts which are actually the same artifacts as androidx.compose ones. When this library is added as a dependency in an Android app, compose dependencies coming from this library and that exist in the app are collided. This problem creates Duplicate Class errors.

One simple solution is to use apply plugin: 'org.jetbrains.compose' and that's not desirable. I don't think anyone wants to add this plugin just to use Richtext. Another one is that we can introduce a lightweight plugin which would replace the artifacts. This task is very simple.

tasks.create("replaceAndroidxCompose") {
  project.dependencies.modules {
    module("org.jetbrains.compose.animation:animation") {it.replacedBy("androidx.compose.animation:animation") }
    module("org.jetbrains.compose.animation:animation") { it.replacedBy("androidx.compose.animation:animation") }
    module("org.jetbrains.compose.animation:animation-core") { it.replacedBy("androidx.compose.animation:animation-core") }
    module("org.jetbrains.compose.compiler:compiler") { it.replacedBy("androidx.compose.compiler:compiler") }
    module("org.jetbrains.compose.compiler:compiler-hosted") { it.replacedBy("androidx.compose.compiler:compiler-hosted") }
    module("org.jetbrains.compose.foundation:foundation") { it.replacedBy("androidx.compose.foundation:foundation") }
    module("org.jetbrains.compose.foundation:foundation-layout") { it.replacedBy("androidx.compose.foundation:foundation-layout") }
    module("org.jetbrains.compose.material:material") { it.replacedBy("androidx.compose.material:material") }
    module("org.jetbrains.compose.material:material-icons-core") { it.replacedBy("androidx.compose.material:material-icons-core") }
    module("org.jetbrains.compose.material:material-icons-extended") { it.replacedBy("androidx.compose.material:material-icons-extended") }
    module("org.jetbrains.compose.material:material-ripple") { it.replacedBy("androidx.compose.material:material-ripple") }
    module("org.jetbrains.compose.runtime:runtime") { it.replacedBy("androidx.compose.runtime:runtime") }
    module("org.jetbrains.compose.runtime:runtime-saveable") { it.replacedBy("androidx.compose.runtime:runtime-saveable") }
    module("org.jetbrains.compose.ui:ui") { it.replacedBy("androidx.compose.ui:ui") }
    module("org.jetbrains.compose.ui:ui-geometry") { it.replacedBy("androidx.compose.ui:ui-geometry") }
    module("org.jetbrains.compose.ui:ui-graphics") { it.replacedBy("androidx.compose.ui:ui-graphics") }
    module("org.jetbrains.compose.ui:ui-test") { it.replacedBy("androidx.compose.ui:ui-test") }
    module("org.jetbrains.compose.ui:ui-test-junit4") { it.replacedBy("androidx.compose.ui:ui-test-junit4") }
    module("org.jetbrains.compose.ui:ui-text") { it.replacedBy("androidx.compose.ui:ui-text") }
    module("org.jetbrains.compose.ui:ui-unit") { it.replacedBy("androidx.compose.ui:ui-unit") }
    module("org.jetbrains.compose.ui:ui-util") { it.replacedBy("androidx.compose.ui:ui-util") }
  }
}

tasks.named("build") {
  it.dependsOn("replaceAndroidxCompose")
}

I'm open for comments here because I'm very noob when it comes to gradle. @LouisCAD @zach-klippenstein