Skip to content

Commit

Permalink
Merge pull request #496 from icerockdev/develop
Browse files Browse the repository at this point in the history
Release 0.22.3
  • Loading branch information
Alex009 authored May 24, 2023
2 parents 25e4f29 + 8d35fe8 commit 2c14411
Show file tree
Hide file tree
Showing 10 changed files with 252 additions and 18 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ buildscript {
}
dependencies {
classpath "dev.icerock.moko:resources-generator:0.22.2"
classpath "dev.icerock.moko:resources-generator:0.22.3"
}
}
Expand All @@ -80,10 +80,10 @@ project build.gradle
apply plugin: "dev.icerock.mobile.multiplatform-resources"
dependencies {
commonMainApi("dev.icerock.moko:resources:0.22.2")
commonMainApi("dev.icerock.moko:resources-compose:0.22.2") // for compose multiplatform
commonMainApi("dev.icerock.moko:resources:0.22.3")
commonMainApi("dev.icerock.moko:resources-compose:0.22.3") // for compose multiplatform
commonTestImplementation("dev.icerock.moko:resources-test:0.22.2")
commonTestImplementation("dev.icerock.moko:resources-test:0.22.3")
}
multiplatformResources {
Expand All @@ -102,7 +102,7 @@ should [add `export` declarations](https://kotlinlang.org/docs/multiplatform-bui

```
framework {
export("dev.icerock.moko:resources:0.22.2")
export("dev.icerock.moko:resources:0.22.3")
export("dev.icerock.moko:graphics:0.9.0") // toUIColor here
}
```
Expand Down
2 changes: 1 addition & 1 deletion gradle/moko.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
resourcesVersion = "0.22.2"
resourcesVersion = "0.22.3"

[libraries]
resources = { module = "dev.icerock.moko:resources", version.ref = "resourcesVersion" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,23 @@ import androidx.compose.ui.graphics.Color
import dev.icerock.moko.resources.ColorResource
import dev.icerock.moko.resources.getNSColor
import platform.AppKit.NSColor
import platform.AppKit.NSColorSpace.Companion.deviceRGBColorSpace

@Composable
actual fun colorResource(resource: ColorResource): Color {
// TODO https://github.com/icerockdev/moko-resources/issues/443
// recompose when appearance changed (now not works in runtime!)
val darkMode: Boolean = isSystemInDarkTheme()
return remember(resource) {
val ciColor: NSColor = resource.getNSColor()
return remember(resource, darkMode) {
val nsColor: NSColor = resource.getNSColor()
val deviceColor: NSColor = nsColor.colorUsingColorSpace(deviceRGBColorSpace)
?: error("can't convert $nsColor to deviceRGBColorSpace")

Color(
red = ciColor.redComponent.toFloat(),
green = ciColor.greenComponent.toFloat(),
blue = ciColor.blueComponent.toFloat(),
alpha = ciColor.alphaComponent.toFloat()
red = deviceColor.redComponent.toFloat(),
green = deviceColor.greenComponent.toFloat(),
blue = deviceColor.blueComponent.toFloat(),
alpha = deviceColor.alphaComponent.toFloat()
)
}
}
2 changes: 2 additions & 0 deletions samples/compose-resources-gallery/androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ plugins {

kotlin {
android()

@Suppress("UNUSED_VARIABLE")
sourceSets {
val androidMain by getting {
dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
7555FF77242A565900829871 /* Sources */,
7555FF79242A565900829871 /* Resources */,
F85CB1118929364A9C6EFABC /* Frameworks */,
420F7168B5294CA0336A327D /* [CP] Embed Pods Frameworks */,
77F733FF1C0E0F137B1CD22F /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand Down Expand Up @@ -167,21 +167,21 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
420F7168B5294CA0336A327D /* [CP] Embed Pods Frameworks */ = {
77F733FF1C0E0F137B1CD22F /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-iosApp/Pods-iosApp-frameworks-${CONFIGURATION}-input-files.xcfilelist",
"${PODS_ROOT}/Target Support Files/Pods-iosApp/Pods-iosApp-resources-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Embed Pods Frameworks";
name = "[CP] Copy Pods Resources";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-iosApp/Pods-iosApp-frameworks-${CONFIGURATION}-output-files.xcfilelist",
"${PODS_ROOT}/Target Support Files/Pods-iosApp/Pods-iosApp-resources-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-iosApp/Pods-iosApp-frameworks.sh\"\n";
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-iosApp/Pods-iosApp-resources.sh\"\n";
showEnvVarsInLog = 0;
};
98D614C51D2DA07C614CC46E /* [CP] Check Pods Manifest.lock */ = {
Expand Down
146 changes: 146 additions & 0 deletions samples/compose-resources-gallery/macosApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink
import java.io.File
import kotlin.reflect.full.declaredMemberProperties

plugins {
kotlin("multiplatform")
id("org.jetbrains.compose")
id("dev.icerock.mobile.multiplatform-resources")
}

version = "0.1.0"

kotlin {
macosX64 {
binaries {
executable {
entryPoint = "main"
freeCompilerArgs += listOf(
"-linker-option", "-framework", "-linker-option", "Metal"
)
}
}
}

macosArm64 {
binaries {
executable {
entryPoint = "main"
freeCompilerArgs += listOf(
"-linker-option", "-framework", "-linker-option", "Metal"
)
}
}
}

@Suppress("UNUSED_VARIABLE")
sourceSets {
val commonMain by getting {
dependencies {
api(project(":shared"))
}
}
}
}

compose.desktop.nativeApplication {
targets(kotlin.targets.getByName("macosX64"), kotlin.targets.getByName("macosArm64"))
distributions {
targetFormats(org.jetbrains.compose.desktop.application.dsl.TargetFormat.Dmg)
packageName = "dev.icerock.moko.resources.sample"
packageVersion = "0.1.0"
}
}

kotlin {
targets.withType<org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget> {
binaries.all {
// TODO: the current compose binary surprises LLVM, so disable checks for now.
freeCompilerArgs += "-Xdisable-phases=VerifyBitcode"
}
}
}

multiplatformResources {
multiplatformResourcesPackage = "dev.icerock.moko.resources.sample"
}

// TODO move to moko-resources gradle plugin
// copy .bundle from all .klib to .kexe
tasks.withType<KotlinNativeLink>()
.configureEach {
val linkTask: KotlinNativeLink = this
val outputDir: File = this.outputFile.get().parentFile

@Suppress("ObjectLiteralToLambda") // lambda broke up-to-date
val action = object : Action<Task> {
override fun execute(t: Task) {
(linkTask.libraries + linkTask.sources)
.filter { library -> library.extension == "klib" }
.filter(File::exists)
.forEach { inputFile ->
val klibKonan = org.jetbrains.kotlin.konan.file.File(inputFile.path)
val klib = org.jetbrains.kotlin.library.impl.KotlinLibraryLayoutImpl(
klib = klibKonan,
component = "default"
)
val layout = klib.extractingToTemp

// extracting bundles
layout
.resourcesDir
.absolutePath
.let(::File)
.listFiles { file: File -> file.extension == "bundle" }
// copying bundles to app
?.forEach {
logger.info("${it.absolutePath} copying to $outputDir")
it.copyRecursively(
target = File(outputDir, it.name),
overwrite = true
)
}
}
}
}
doLast(action)
}

// TODO move to moko-resources gradle plugin
// copy .bundle from .kexe to .app
tasks.withType<org.jetbrains.compose.experimental.uikit.tasks.ExperimentalPackComposeApplicationForXCodeTask>()
.configureEach {
val packTask: org.jetbrains.compose.experimental.uikit.tasks.ExperimentalPackComposeApplicationForXCodeTask =
this

val kclass =
org.jetbrains.compose.experimental.uikit.tasks.ExperimentalPackComposeApplicationForXCodeTask::class
val kotlinBinaryField =
kclass.declaredMemberProperties.single { it.name == "kotlinBinary" }
val destinationDirField =
kclass.declaredMemberProperties.single { it.name == "destinationDir" }
val executablePathField =
kclass.declaredMemberProperties.single { it.name == "executablePath" }

@Suppress("ObjectLiteralToLambda") // lambda broke up-to-date
val action = object : Action<Task> {
override fun execute(t: Task) {
val kotlinBinary: RegularFile =
(kotlinBinaryField.get(packTask) as RegularFileProperty).get()
val destinationDir: Directory =
(destinationDirField.get(packTask) as DirectoryProperty).get()
val executablePath: String =
(executablePathField.get(packTask) as Provider<*>).get().toString()

val outputDir: File = File(destinationDir.asFile, executablePath).parentFile

val bundleSearchDir: File = kotlinBinary.asFile.parentFile
bundleSearchDir
.listFiles { file: File -> file.extension == "bundle" }
?.forEach { file ->
file.copyRecursively(File(outputDir, file.name), true)
}
}
}
doLast(action)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import androidx.compose.ui.window.Window
import com.icerockdev.library.MR
import dev.icerock.moko.resources.desc.desc
import kotlinx.cinterop.staticCFunction
import platform.AppKit.NSApplication
import platform.AppKit.NSApplicationActivationPolicy
import platform.AppKit.NSApplicationDelegateProtocol
import platform.darwin.NSObject
import platform.objc.objc_setUncaughtExceptionHandler

@Suppress("UNUSED_PARAMETER")
fun main(args: Array<String>) {
setUnhandledExceptionHook {
it.printStackTrace()
}

objc_setUncaughtExceptionHandler(staticCFunction<Any?, Unit> {
println(it)
})

val app = NSApplication.sharedApplication()
app.setActivationPolicy(NSApplicationActivationPolicy.NSApplicationActivationPolicyRegular)

app.delegate = object : NSObject(), NSApplicationDelegateProtocol {
override fun applicationShouldTerminateAfterLastWindowClosed(sender: NSApplication): Boolean {
return true
}
}

Window(MR.strings.hello_world.desc().localized()) {
MacosApp()
}

app.run()
}
1 change: 1 addition & 0 deletions samples/compose-resources-gallery/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ include(":androidApp")
include(":shared")
include(":desktopApp")
include(":webApp")
include(":macosApp")
38 changes: 38 additions & 0 deletions samples/compose-resources-gallery/shared/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.tasks.DummyFrameworkTask

plugins {
kotlin("multiplatform")
kotlin("native.cocoapods")
Expand All @@ -20,16 +22,23 @@ kotlin {
browser()
}

macosArm64()
macosX64()

cocoapods {
summary = "Some description for the Shared Module"
homepage = "Link to the Shared Module homepage"
ios.deploymentTarget = "14.1"
podfile = project.file("../iosApp/Podfile")
framework {
baseName = "shared"
isStatic = true
}
// TODO move to gradle plugin
extraSpecAttributes["resource"] = "'build/cocoapods/framework/shared.framework/*.bundle'"
}

@Suppress("UNUSED_VARIABLE")
sourceSets {
val commonMain by getting {
dependencies {
Expand Down Expand Up @@ -61,6 +70,15 @@ kotlin {
implementation(compose.html.core)
}
}
val macosMain by creating {
dependsOn(commonMain)
}
val macosX64Main by getting {
dependsOn(macosMain)
}
val macosArm64Main by getting {
dependsOn(macosMain)
}
}
}

Expand All @@ -83,3 +101,23 @@ android {
multiplatformResources {
multiplatformResourcesPackage = "com.icerockdev.library"
}

// TODO move to gradle plugin
tasks.withType<DummyFrameworkTask>().configureEach {
@Suppress("ObjectLiteralToLambda")
doLast(object : Action<Task> {
override fun execute(task: Task) {
task as DummyFrameworkTask

val frameworkDir = File(task.destinationDir, task.frameworkName.get() + ".framework")

listOf(
"compose-resources-gallery:shared.bundle"
).forEach { bundleName ->
val bundleDir = File(frameworkDir, bundleName)
bundleDir.mkdir()
File(bundleDir, "dummyFile").writeText("dummy")
}
}
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import androidx.compose.runtime.Composable

actual fun getPlatformName(): String = "macOS"

@Composable
fun MacosApp() {
App()
}

0 comments on commit 2c14411

Please sign in to comment.