From aed48a902ba38c13890f47611940bfe94089a5bf Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Thu, 27 Jan 2022 11:08:20 +0300 Subject: [PATCH] To MPP --- components/App/demo/build.gradle.kts | 4 ++-- .../org/jetbrains/compose/app/demo/Main.kt | 4 ++-- .../kotlin/org/jetbrains/compose/app/App.kt | 14 ++++++++++++++ .../org/jetbrains/compose/app/App.desktop.kt | 16 ++++++++++++++++ .../kotlin/org/jetbrains/compose/app/App.kt | 10 ---------- 5 files changed, 34 insertions(+), 14 deletions(-) rename components/App/demo/src/{jvmMain => desktopMain}/kotlin/org/jetbrains/compose/app/demo/Main.kt (63%) create mode 100644 components/App/library/src/commonMain/kotlin/org/jetbrains/compose/app/App.kt create mode 100644 components/App/library/src/desktopMain/kotlin/org/jetbrains/compose/app/App.desktop.kt delete mode 100644 components/App/library/src/desktopMain/kotlin/org/jetbrains/compose/app/App.kt diff --git a/components/App/demo/build.gradle.kts b/components/App/demo/build.gradle.kts index c3595d23a8..ce3dd7421d 100644 --- a/components/App/demo/build.gradle.kts +++ b/components/App/demo/build.gradle.kts @@ -7,9 +7,9 @@ plugins { } kotlin { - jvm {} + jvm("desktop") {} sourceSets { - named("jvmMain") { + named("desktopMain") { dependencies { implementation(compose.desktop.currentOs) implementation(project(":App:library")) diff --git a/components/App/demo/src/jvmMain/kotlin/org/jetbrains/compose/app/demo/Main.kt b/components/App/demo/src/desktopMain/kotlin/org/jetbrains/compose/app/demo/Main.kt similarity index 63% rename from components/App/demo/src/jvmMain/kotlin/org/jetbrains/compose/app/demo/Main.kt rename to components/App/demo/src/desktopMain/kotlin/org/jetbrains/compose/app/demo/Main.kt index f5d5554206..ca1e8da7be 100644 --- a/components/App/demo/src/jvmMain/kotlin/org/jetbrains/compose/app/demo/Main.kt +++ b/components/App/demo/src/desktopMain/kotlin/org/jetbrains/compose/app/demo/Main.kt @@ -1,9 +1,9 @@ package org.jetbrains.compose.app.demo import androidx.compose.material.Text -import org.jetbrains.compose.app.application +import org.jetbrains.compose.app.app -fun main() = application( +fun main() = app( title = "App demo" ) { Text("Hi") diff --git a/components/App/library/src/commonMain/kotlin/org/jetbrains/compose/app/App.kt b/components/App/library/src/commonMain/kotlin/org/jetbrains/compose/app/App.kt new file mode 100644 index 0000000000..7b6283eb18 --- /dev/null +++ b/components/App/library/src/commonMain/kotlin/org/jetbrains/compose/app/App.kt @@ -0,0 +1,14 @@ +package org.jetbrains.compose.app + +import androidx.compose.runtime.Composable + +fun app(name: String = "application", title: String = "Compose Application", body: @Composable () -> Unit) { + appImpl(name, title, body) +} + +internal expect fun appImpl(name: String, title: String, body: @Composable () -> Unit) + +// TODO: not sure if having abstract here is a good idea +expect abstract class EmbedderContext + +expect fun embed(context: EmbedderContext, body: @Composable () -> Unit) \ No newline at end of file diff --git a/components/App/library/src/desktopMain/kotlin/org/jetbrains/compose/app/App.desktop.kt b/components/App/library/src/desktopMain/kotlin/org/jetbrains/compose/app/App.desktop.kt new file mode 100644 index 0000000000..a897759dfe --- /dev/null +++ b/components/App/library/src/desktopMain/kotlin/org/jetbrains/compose/app/App.desktop.kt @@ -0,0 +1,16 @@ +package org.jetbrains.compose.app + +import androidx.compose.runtime.Composable +import androidx.compose.ui.window.singleWindowApplication +import javax.swing.JComponent + +actual fun appImpl(name: String, title: String, body: @Composable () -> Unit) { + singleWindowApplication { + body() + } +} + +actual typealias EmbedderContext = JComponent +actual fun embed(context: EmbedderContext, body: @Composable () -> Unit) { + TODO("implement me") +} \ No newline at end of file diff --git a/components/App/library/src/desktopMain/kotlin/org/jetbrains/compose/app/App.kt b/components/App/library/src/desktopMain/kotlin/org/jetbrains/compose/app/App.kt deleted file mode 100644 index 4318f55bad..0000000000 --- a/components/App/library/src/desktopMain/kotlin/org/jetbrains/compose/app/App.kt +++ /dev/null @@ -1,10 +0,0 @@ -package org.jetbrains.compose.app - -import androidx.compose.runtime.Composable -import androidx.compose.ui.window.singleWindowApplication - -fun application(name: String = "application", title: String = "Compose Application", body: @Composable () -> Unit) { - singleWindowApplication { - body() - } -}