Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#535 kotlin 1.9.0, compose multiplatform 1.5.0 support #575

Merged
merged 240 commits into from
Apr 18, 2024

Conversation

Alex009
Copy link
Member

@Alex009 Alex009 commented Sep 11, 2023

Include changes from:

plugin reworked to Provider gradle's api to support dynamic changes of projects configuration.


If you have some not standard usecase - send PR with new sample project please. every sample project is our test case


This request contains breaking changes to better support dynamic changes of configurations and support new features in future (for example - configuration cache #311 ).

At first - resources directory moved from src/<resourceSourceSetName>/resources/MR to src/<sourceSetName>/moko-resources. I have multiple reasons for this:

  1. Kotlin improve own resources directory management and Compose Multiplatform at now use content of resources directory. Our resources in MR directory was not ready for directly usage as resource - our resources if "source" for generation of platform resources. For example - for iOS all resources should be packed in bundle, for android svg should be converted to vector-xml. in resources source set in future we can put output of our generators, but "source" resources should not be copied into result app.
  2. at gradle configuration stage we can't correctly decide what source set should be used for generation with current logic resourceSourceSetName that configured in plugin's extension - source sets can change at any time, and resourceSourceSetName in plugin extension can be changed in any time. So we should generate MR tasks for all sourcesets and decide what to do at EXECUTION stage. Also it allow to put resources in any sourceSet in hierarchy. For example in commonMain will be common resources and in iosMain will be ios specific resources added. It's was requested in Support for platform specific strings/resources #357

Second - MR object will be generated not only expect + actuals, but also for middle layer expects in different source sets. For example if we have next sourceSets hierarchy:

commonMain // here we have string common_hello
- androidMain // here no any additional strings
- appleMain  // here we have string apple_hello
-- iosMain  // here we have string ios_hello
--- iosX64Main  // here we have string iosx64_hello
--- iosSimulatorArm64Main // here no any additional strings
--- iosArm64Main // here no any additional strings

We can put resources in each source set. And as result we got this sources:
commonMain/MR.common.kt:

expect object MR {
    object strings: AppleMainStrings, IosMainStrings {
        val commonHello: StringResource
    }
}

expect interface AppleMainStrings // this naming not final. if you have idea about better name - please write comment
expect interface IosMainStrings // this naming not final. if you have idea about better name - please write comment

androidMain/MR.android.kt:

actual interface AppleMainStrings
actual interface IosMainStrings

actual object MR {
    actual object strings : AppleMainStrings, IosMainStrings {
        actual val commonHello: StringResource get() = TODO()
    }
}

appleMain/MR.apple.kt:

actual interface AppleMainStrings {
    val appleHello: StringResource
}

iosMain/MR.ios.kt:

actual interface IosMainStrings {
    val iosHello: StringResource
}

iosX64Main/MR.iosX64.kt:

actual object MR {
    actual object strings : AppleMainStrings, IosMainStrings {
        actual val commonHello: StringResource get() = TODO()
        override val appleHello: StringResource get() = TODO()
        override val iosHello: StringResource get() = TODO()
        val iosX64Hello: StringResource get() = TODO()
    }
}

iosArm64Main/MR.iosArm64.kt, iosSimulatorArm64Main/MR.iosSimulatorArm64.kt:

actual object MR {
    actual object strings : AppleMainStrings, IosMainStrings {
        actual val commonHello: StringResource get() = TODO()
        override val appleHello: StringResource get() = TODO()
        override val iosHello: StringResource get() = TODO()
    }
}

To decide what exactly should be generated each generateMR task will check own moko-resources directory and dependencies.
expect object MR will be located at lowest level of hierarchy (for example if we have not resources in commonMain but have in iosMain - expect will be in iosMain and commonMain will be empty. With this change we can remove resourcesSourceSet property from extension.


Current progress:

  • Common generator
  • Target generator
  • Android MR generator
  • JVM MR generator
  • JS MR generator
  • Apple MR generator
  • Define generated resources as sourceSet, assets, resources**
  • Copy resources of Apple and JS targets in KLibs**
  • Metadata:
    • Base
    • All generators work with metadata
  • Move resources from resources/MR to moko-resources
  • Strings generator: - Success run on sample
    • Common target
    • Android target
    • Jvm target
    • Js target
    • Apple target
  • Plurals generator: - Success run on sample
    • Common target
    • Android target
    • Jvm target
    • Js target
    • Apple target
  • Files generator:
    • Common target
    • Android target
    • Jvm target
    • Js target
    • Apple target
  • Fonts generator:
    • Common target
    • Android target
    • Jvm target
    • Js target
    • Apple target
  • Assets generator:
    • Common target
    • Android target
    • Jvm target
    • Js target
    • Apple target
  • Colors generator:
    • Common target
    • Android target
    • Jvm target
    • Js target
    • Apple target
  • Images generator:
    • Common target
    • Android target
    • Jvm target
    • Js target
    • Apple target
  • Testing on samples
  • Testing on real IceRock projects

known issues:

  • gradle task cache not invalidates when add resources in target sourceset, when project already compiled with resources exist on lower levels (when have resources in commonMain, compile, then create resources in desktopMain)
  • fonts generated object is changed (in past we have additional object with font family name and inside have properties with styles. now we have only properties like fontfamily-style) - i think we can not fix this at all
  • assets generated object is changed (in past was generated also inner objects like directory tree. now generated only flat properties and you can't see directory structure) - want to fix, but can't decide how (when we should generate interface for intermediate resources - we can't generated inner objects)
  • in some cases actual for iOS target not generated

todo:

Alex009 and others added 30 commits June 4, 2023 21:07
…530-fix-task-dependencies-for-Gradle-8.2.1

# Conflicts:
#	gradle/libs.versions.toml
#	resources-compose/src/appleMain/kotlin/dev/icerock/moko/resources/compose/internal/CGImageRef+Skia.kt
#	resources-compose/src/appleMain/kotlin/dev/icerock/moko/resources/compose/internal/NSDataExt.kt
#	resources-generator/build.gradle.kts
#	samples/compose-jvm-app/build.gradle.kts
#	samples/compose-resources-gallery/gradle.properties
#	samples/compose-resources-gallery/shared/build.gradle.kts
#	samples/ios-static-xcframework/build.gradle.kts
#	samples/kotlin-ios-app/build.gradle.kts
#	samples/resources-gallery/build.gradle.kts
…act class and fields replaced with Gradle's Property instances. Removed redundant multipaltform prefix for move convenient reading. Extension methods to access default values
…ield, because it's actually not correct by default. Users should configure package names for their projects due to their requirements
…ield, because it's actually not correct by default. Users should configure package names for their projects due to their requirements
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
.github/compilation-check-source.yml Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
samples/default-hierarchy-gallery-mobile/local-check.sh Outdated Show resolved Hide resolved
samples/ios-cocoapods-static-framework/local-check.sh Outdated Show resolved Hide resolved
samples/ios-static-xcframework/local-check.sh Outdated Show resolved Hide resolved
samples/kotlin-2-sample/local-check.sh Outdated Show resolved Hide resolved
samples/resources-gallery/local-check.sh Outdated Show resolved Hide resolved
@ExNDY ExNDY force-pushed the #535-kotlin-1.9.0-support branch from 8fd5837 to dca5e78 Compare April 16, 2024 11:47
@ExNDY ExNDY force-pushed the #535-kotlin-1.9.0-support branch from 7c06b4b to 4623998 Compare April 16, 2024 12:12
@Alex009 Alex009 merged commit 8b14375 into develop Apr 18, 2024
31 checks passed
@Alex009 Alex009 deleted the #535-kotlin-1.9.0-support branch April 18, 2024 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment