diff --git a/androidApp/build.gradle.kts b/androidApp/build.gradle.kts new file mode 100644 index 0000000..cebc38e --- /dev/null +++ b/androidApp/build.gradle.kts @@ -0,0 +1,54 @@ +import org.jetbrains.kotlin.gradle.dsl.JvmTarget + +plugins { + alias(libs.plugins.androidApplication) + alias(libs.plugins.composeMultiplatform) + alias(libs.plugins.composeCompiler) +} + +kotlin { + target { + compilerOptions { + jvmTarget.set(JvmTarget.JVM_11) + } + } + + dependencies { + implementation(projects.shared) + + implementation(libs.androidx.activity.compose) + + debugImplementation(libs.compose.ui.tooling.preview) + } +} + +android { + namespace = "compose.project.demo.composedemo" + compileSdk = libs.versions.android.compileSdk.get().toInt() + + defaultConfig { + applicationId = "compose.project.demo.composedemo" + minSdk = libs.versions.android.minSdk.get().toInt() + targetSdk = libs.versions.android.targetSdk.get().toInt() + versionCode = 1 + versionName = "1.0" + } + packaging { + resources { + excludes += "/META-INF/{AL2.0,LGPL2.1}" + } + } + buildTypes { + getByName("release") { + isMinifyEnabled = false + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + } +} + +dependencies { + debugImplementation(libs.compose.ui.tooling) +} \ No newline at end of file diff --git a/composeApp/src/androidMain/AndroidManifest.xml b/androidApp/src/main/AndroidManifest.xml similarity index 100% rename from composeApp/src/androidMain/AndroidManifest.xml rename to androidApp/src/main/AndroidManifest.xml diff --git a/composeApp/src/androidMain/kotlin/compose/project/demo/composedemo/MainActivity.kt b/androidApp/src/main/kotlin/compose/project/demo/composedemo/MainActivity.kt similarity index 100% rename from composeApp/src/androidMain/kotlin/compose/project/demo/composedemo/MainActivity.kt rename to androidApp/src/main/kotlin/compose/project/demo/composedemo/MainActivity.kt diff --git a/composeApp/src/androidMain/res/drawable-v24/ic_launcher_foreground.xml b/androidApp/src/main/res/drawable-v24/ic_launcher_foreground.xml similarity index 100% rename from composeApp/src/androidMain/res/drawable-v24/ic_launcher_foreground.xml rename to androidApp/src/main/res/drawable-v24/ic_launcher_foreground.xml diff --git a/composeApp/src/androidMain/res/drawable/ic_launcher_background.xml b/androidApp/src/main/res/drawable/ic_launcher_background.xml similarity index 100% rename from composeApp/src/androidMain/res/drawable/ic_launcher_background.xml rename to androidApp/src/main/res/drawable/ic_launcher_background.xml diff --git a/composeApp/src/androidMain/res/mipmap-anydpi-v26/ic_launcher.xml b/androidApp/src/main/res/mipmap-anydpi-v26/ic_launcher.xml similarity index 100% rename from composeApp/src/androidMain/res/mipmap-anydpi-v26/ic_launcher.xml rename to androidApp/src/main/res/mipmap-anydpi-v26/ic_launcher.xml diff --git a/composeApp/src/androidMain/res/mipmap-anydpi-v26/ic_launcher_round.xml b/androidApp/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml similarity index 100% rename from composeApp/src/androidMain/res/mipmap-anydpi-v26/ic_launcher_round.xml rename to androidApp/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml diff --git a/composeApp/src/androidMain/res/mipmap-hdpi/ic_launcher.png b/androidApp/src/main/res/mipmap-hdpi/ic_launcher.png similarity index 100% rename from composeApp/src/androidMain/res/mipmap-hdpi/ic_launcher.png rename to androidApp/src/main/res/mipmap-hdpi/ic_launcher.png diff --git a/composeApp/src/androidMain/res/mipmap-hdpi/ic_launcher_round.png b/androidApp/src/main/res/mipmap-hdpi/ic_launcher_round.png similarity index 100% rename from composeApp/src/androidMain/res/mipmap-hdpi/ic_launcher_round.png rename to androidApp/src/main/res/mipmap-hdpi/ic_launcher_round.png diff --git a/composeApp/src/androidMain/res/mipmap-mdpi/ic_launcher.png b/androidApp/src/main/res/mipmap-mdpi/ic_launcher.png similarity index 100% rename from composeApp/src/androidMain/res/mipmap-mdpi/ic_launcher.png rename to androidApp/src/main/res/mipmap-mdpi/ic_launcher.png diff --git a/composeApp/src/androidMain/res/mipmap-mdpi/ic_launcher_round.png b/androidApp/src/main/res/mipmap-mdpi/ic_launcher_round.png similarity index 100% rename from composeApp/src/androidMain/res/mipmap-mdpi/ic_launcher_round.png rename to androidApp/src/main/res/mipmap-mdpi/ic_launcher_round.png diff --git a/composeApp/src/androidMain/res/mipmap-xhdpi/ic_launcher.png b/androidApp/src/main/res/mipmap-xhdpi/ic_launcher.png similarity index 100% rename from composeApp/src/androidMain/res/mipmap-xhdpi/ic_launcher.png rename to androidApp/src/main/res/mipmap-xhdpi/ic_launcher.png diff --git a/composeApp/src/androidMain/res/mipmap-xhdpi/ic_launcher_round.png b/androidApp/src/main/res/mipmap-xhdpi/ic_launcher_round.png similarity index 100% rename from composeApp/src/androidMain/res/mipmap-xhdpi/ic_launcher_round.png rename to androidApp/src/main/res/mipmap-xhdpi/ic_launcher_round.png diff --git a/composeApp/src/androidMain/res/mipmap-xxhdpi/ic_launcher.png b/androidApp/src/main/res/mipmap-xxhdpi/ic_launcher.png similarity index 100% rename from composeApp/src/androidMain/res/mipmap-xxhdpi/ic_launcher.png rename to androidApp/src/main/res/mipmap-xxhdpi/ic_launcher.png diff --git a/composeApp/src/androidMain/res/mipmap-xxhdpi/ic_launcher_round.png b/androidApp/src/main/res/mipmap-xxhdpi/ic_launcher_round.png similarity index 100% rename from composeApp/src/androidMain/res/mipmap-xxhdpi/ic_launcher_round.png rename to androidApp/src/main/res/mipmap-xxhdpi/ic_launcher_round.png diff --git a/composeApp/src/androidMain/res/mipmap-xxxhdpi/ic_launcher.png b/androidApp/src/main/res/mipmap-xxxhdpi/ic_launcher.png similarity index 100% rename from composeApp/src/androidMain/res/mipmap-xxxhdpi/ic_launcher.png rename to androidApp/src/main/res/mipmap-xxxhdpi/ic_launcher.png diff --git a/composeApp/src/androidMain/res/mipmap-xxxhdpi/ic_launcher_round.png b/androidApp/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png similarity index 100% rename from composeApp/src/androidMain/res/mipmap-xxxhdpi/ic_launcher_round.png rename to androidApp/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png diff --git a/composeApp/src/androidMain/res/values/strings.xml b/androidApp/src/main/res/values/strings.xml similarity index 100% rename from composeApp/src/androidMain/res/values/strings.xml rename to androidApp/src/main/res/values/strings.xml diff --git a/build.gradle.kts b/build.gradle.kts index 98ddb8c..6bf6b46 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,9 +2,10 @@ plugins { // this is necessary to avoid the plugins to be loaded multiple times // in each subproject's classloader alias(libs.plugins.androidApplication) apply false - alias(libs.plugins.androidLibrary) apply false + alias(libs.plugins.androidMultiplatformLibrary) apply false alias(libs.plugins.composeHotReload) apply false alias(libs.plugins.composeMultiplatform) apply false alias(libs.plugins.composeCompiler) apply false alias(libs.plugins.kotlinMultiplatform) apply false + alias(libs.plugins.kotlinJvm) apply false } \ No newline at end of file diff --git a/composeApp/build.gradle.kts b/composeApp/build.gradle.kts deleted file mode 100644 index 775ab1e..0000000 --- a/composeApp/build.gradle.kts +++ /dev/null @@ -1,121 +0,0 @@ -import org.jetbrains.compose.desktop.application.dsl.TargetFormat -import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi -import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl -import org.jetbrains.kotlin.gradle.dsl.JvmTarget -import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig - -plugins { - alias(libs.plugins.kotlinMultiplatform) - alias(libs.plugins.androidApplication) - alias(libs.plugins.composeMultiplatform) - alias(libs.plugins.composeCompiler) - alias(libs.plugins.composeHotReload) -} - -kotlin { - androidTarget { - compilerOptions { - jvmTarget.set(JvmTarget.JVM_11) - } - } - - listOf( - iosArm64(), - iosSimulatorArm64() - ).forEach { iosTarget -> - iosTarget.binaries.framework { - baseName = "ComposeApp" - isStatic = true - } - } - - jvm() - - js { - browser() - binaries.executable() - } - - @OptIn(ExperimentalWasmDsl::class) - wasmJs { - browser() - binaries.executable() - } - - sourceSets { - all { - languageSettings { - optIn("kotlin.time.ExperimentalTime") - } - } - - androidMain.dependencies { - implementation(compose.preview) - implementation(libs.androidx.activity.compose) - } - commonMain.dependencies { - implementation(compose.runtime) - implementation(compose.foundation) - implementation(compose.material3) - implementation(compose.ui) - implementation(compose.components.resources) - implementation(compose.components.uiToolingPreview) - implementation(libs.androidx.lifecycle.viewmodelCompose) - implementation(libs.androidx.lifecycle.runtimeCompose) - implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.7.1") - } - commonTest.dependencies { - implementation(libs.kotlin.test) - } - jvmMain.dependencies { - implementation(compose.desktop.currentOs) - implementation(libs.kotlinx.coroutinesSwing) - } - webMain.dependencies { - implementation(npm("@js-joda/timezone", "2.22.0")) - } - } -} - -android { - namespace = "compose.project.demo.composedemo" - compileSdk = libs.versions.android.compileSdk.get().toInt() - - defaultConfig { - applicationId = "compose.project.demo.composedemo" - minSdk = libs.versions.android.minSdk.get().toInt() - targetSdk = libs.versions.android.targetSdk.get().toInt() - versionCode = 1 - versionName = "1.0" - } - packaging { - resources { - excludes += "/META-INF/{AL2.0,LGPL2.1}" - } - } - buildTypes { - getByName("release") { - isMinifyEnabled = false - } - } - compileOptions { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 - } -} - -dependencies { - debugImplementation(compose.uiTooling) -} - -compose.desktop { - application { - mainClass = "compose.project.demo.composedemo.MainKt" - - nativeDistributions { - targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb) - packageName = "compose.project.demo.composedemo" - packageVersion = "1.0.0" - } - } -} diff --git a/desktopApp/build.gradle.kts b/desktopApp/build.gradle.kts new file mode 100644 index 0000000..d516119 --- /dev/null +++ b/desktopApp/build.gradle.kts @@ -0,0 +1,29 @@ +import org.jetbrains.compose.desktop.application.dsl.TargetFormat + +plugins { + alias(libs.plugins.kotlinJvm) + alias(libs.plugins.composeMultiplatform) + alias(libs.plugins.composeCompiler) + alias(libs.plugins.composeHotReload) +} + +kotlin { + dependencies { + implementation(projects.shared) + + implementation(compose.desktop.currentOs) + implementation(libs.kotlinx.coroutinesSwing) + } +} + +compose.desktop { + application { + mainClass = "compose.project.demo.composedemo.MainKt" + + nativeDistributions { + targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb) + packageName = "compose.project.demo.composedemo" + packageVersion = "1.0.0" + } + } +} diff --git a/composeApp/src/jvmMain/kotlin/compose/project/demo/composedemo/main.kt b/desktopApp/src/main/kotlin/compose/project/demo/composedemo/main.kt similarity index 100% rename from composeApp/src/jvmMain/kotlin/compose/project/demo/composedemo/main.kt rename to desktopApp/src/main/kotlin/compose/project/demo/composedemo/main.kt diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 703c4f3..1935471 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -agp = "8.11.2" +agp = "9.0.0-beta03" android-compileSdk = "36" android-minSdk = "24" android-targetSdk = "36" @@ -9,11 +9,13 @@ androidx-core = "1.17.0" androidx-espresso = "3.7.0" androidx-lifecycle = "2.9.6" androidx-testExt = "1.3.0" +compose-material3 = "1.9.0" composeHotReload = "1.0.0" -composeMultiplatform = "1.9.3" +composeMultiplatform = "1.10.0-beta02" junit = "4.13.2" kotlin = "2.2.21" kotlinx-coroutines = "1.10.2" +kotlinx-datetime = "0.7.1" [libraries] kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" } @@ -27,11 +29,20 @@ androidx-activity-compose = { module = "androidx.activity:activity-compose", ver androidx-lifecycle-viewmodelCompose = { module = "org.jetbrains.androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "androidx-lifecycle" } androidx-lifecycle-runtimeCompose = { module = "org.jetbrains.androidx.lifecycle:lifecycle-runtime-compose", version.ref = "androidx-lifecycle" } kotlinx-coroutinesSwing = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-swing", version.ref = "kotlinx-coroutines" } +compose-runtime = { module = "org.jetbrains.compose.runtime:runtime", version.ref = "composeMultiplatform" } +compose-ui = { module = "org.jetbrains.compose.ui:ui", version.ref = "composeMultiplatform" } +compose-foundation = { module = "org.jetbrains.compose.foundation:foundation", version.ref = "composeMultiplatform" } +compose-material3 = { module = "org.jetbrains.compose.material3:material3", version.ref = "compose-material3" } +compose-resources = { module = "org.jetbrains.compose.components:components-resources", version.ref = "composeMultiplatform" } +compose-ui-tooling = { module = "org.jetbrains.compose.ui:ui-tooling", version.ref = "composeMultiplatform" } +compose-ui-tooling-preview = { module = "org.jetbrains.compose.ui:ui-tooling-preview", version.ref = "composeMultiplatform" } +kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinx-datetime" } [plugins] androidApplication = { id = "com.android.application", version.ref = "agp" } -androidLibrary = { id = "com.android.library", version.ref = "agp" } +androidMultiplatformLibrary = { id = "com.android.kotlin.multiplatform.library", version.ref = "agp" } composeHotReload = { id = "org.jetbrains.compose.hot-reload", version.ref = "composeHotReload" } composeMultiplatform = { id = "org.jetbrains.compose", version.ref = "composeMultiplatform" } composeCompiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } -kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } \ No newline at end of file +kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } +kotlinJvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index d4081da..2e11132 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/iosApp/iosApp.xcodeproj/project.pbxproj b/iosApp/iosApp.xcodeproj/project.pbxproj index 39b5fe8..2af8a4c 100644 --- a/iosApp/iosApp.xcodeproj/project.pbxproj +++ b/iosApp/iosApp.xcodeproj/project.pbxproj @@ -152,7 +152,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "if [ \"YES\" = \"$OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED\" ]; then\n echo \"Skipping Gradle build task invocation due to OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED environment variable set to \\\"YES\\\"\"\n exit 0\nfi\ncd \"$SRCROOT/..\"\n./gradlew :composeApp:embedAndSignAppleFrameworkForXcode\n"; + shellScript = "if [ \"YES\" = \"$OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED\" ]; then\n echo \"Skipping Gradle build task invocation due to OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED environment variable set to \\\"YES\\\"\"\n exit 0\nfi\ncd \"$SRCROOT/..\"\n./gradlew :shared:embedAndSignAppleFrameworkForXcode\n"; }; /* End PBXShellScriptBuildPhase section */ @@ -296,7 +296,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; DEVELOPMENT_ASSET_PATHS = "\"iosApp/Preview Content\""; - DEVELOPMENT_TEAM = "${TEAM_ID}"; + DEVELOPMENT_TEAM = 62N94DGQ7K; ENABLE_PREVIEWS = YES; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -313,6 +313,7 @@ "$(inherited)", "@executable_path/Frameworks", ); + PRODUCT_BUNDLE_IDENTIFIER = compose.project.demo.composedemo2; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; @@ -329,7 +330,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; DEVELOPMENT_ASSET_PATHS = "\"iosApp/Preview Content\""; - DEVELOPMENT_TEAM = "${TEAM_ID}"; + DEVELOPMENT_TEAM = 62N94DGQ7K; ENABLE_PREVIEWS = YES; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -346,6 +347,7 @@ "$(inherited)", "@executable_path/Frameworks", ); + PRODUCT_BUNDLE_IDENTIFIER = compose.project.demo.composedemo2; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; @@ -376,4 +378,4 @@ /* End XCConfigurationList section */ }; rootObject = B9DA97A92DC1472C00A4DA20 /* Project object */; -} \ No newline at end of file +} diff --git a/iosApp/iosApp/Info.plist b/iosApp/iosApp/Info.plist index 99d16fa..11845e1 100644 --- a/iosApp/iosApp/Info.plist +++ b/iosApp/iosApp/Info.plist @@ -1,8 +1,8 @@ - - CADisableMinimumFrameDurationOnPhone - - + + CADisableMinimumFrameDurationOnPhone + + diff --git a/settings.gradle.kts b/settings.gradle.kts index c1978f2..69f0e2c 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -32,4 +32,8 @@ plugins { id("org.gradle.toolchains.foojay-resolver-convention") version "1.0.0" } -include(":composeApp") \ No newline at end of file +include(":shared") +include(":desktopApp") +include(":androidApp") +include(":webApp") +include(":androidApp") \ No newline at end of file diff --git a/shared/build.gradle.kts b/shared/build.gradle.kts new file mode 100644 index 0000000..38f69b3 --- /dev/null +++ b/shared/build.gradle.kts @@ -0,0 +1,77 @@ +import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi +import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl +import org.jetbrains.kotlin.gradle.dsl.JvmTarget + +plugins { + alias(libs.plugins.kotlinMultiplatform) + alias(libs.plugins.androidMultiplatformLibrary) + alias(libs.plugins.composeMultiplatform) + alias(libs.plugins.composeCompiler) + alias(libs.plugins.composeHotReload) +} + +kotlin { + androidLibrary { + namespace = "org.example.project.composeApp" + compileSdk = libs.versions.android.compileSdk.get().toInt() + minSdk = libs.versions.android.minSdk.get().toInt() + + compilerOptions { + jvmTarget = JvmTarget.JVM_11 + } + androidResources { + enable = true + } + withHostTest { + isIncludeAndroidResources = true + } + } + + listOf( + iosArm64(), + iosSimulatorArm64() + ).forEach { iosTarget -> + iosTarget.binaries.framework { + baseName = "ComposeApp" + isStatic = true + } + } + + jvm() + + js { + browser() + } + + @OptIn(ExperimentalWasmDsl::class) + wasmJs { + browser() + } + + @OptIn(ExperimentalKotlinGradlePluginApi::class) + dependencies { + implementation(libs.compose.runtime) + implementation(libs.compose.foundation) + implementation(libs.compose.material3) + implementation(libs.compose.ui) + implementation(libs.compose.resources) + implementation(libs.androidx.lifecycle.viewmodelCompose) + implementation(libs.androidx.lifecycle.runtimeCompose) + implementation(libs.compose.ui.tooling.preview) + implementation(libs.kotlinx.datetime) + + testImplementation(libs.kotlin.test) + } + + sourceSets { + all { + languageSettings { + optIn("kotlin.time.ExperimentalTime") + } + } + } +} + +dependencies { + "androidRuntimeClasspath"(libs.compose.ui.tooling) +} diff --git a/composeApp/src/commonMain/composeResources/drawable/compose-multiplatform.xml b/shared/src/commonMain/composeResources/drawable/compose-multiplatform.xml similarity index 100% rename from composeApp/src/commonMain/composeResources/drawable/compose-multiplatform.xml rename to shared/src/commonMain/composeResources/drawable/compose-multiplatform.xml diff --git a/composeApp/src/commonMain/composeResources/drawable/eg.png b/shared/src/commonMain/composeResources/drawable/eg.png similarity index 100% rename from composeApp/src/commonMain/composeResources/drawable/eg.png rename to shared/src/commonMain/composeResources/drawable/eg.png diff --git a/composeApp/src/commonMain/composeResources/drawable/fr.png b/shared/src/commonMain/composeResources/drawable/fr.png similarity index 100% rename from composeApp/src/commonMain/composeResources/drawable/fr.png rename to shared/src/commonMain/composeResources/drawable/fr.png diff --git a/composeApp/src/commonMain/composeResources/drawable/id.png b/shared/src/commonMain/composeResources/drawable/id.png similarity index 100% rename from composeApp/src/commonMain/composeResources/drawable/id.png rename to shared/src/commonMain/composeResources/drawable/id.png diff --git a/composeApp/src/commonMain/composeResources/drawable/jp.png b/shared/src/commonMain/composeResources/drawable/jp.png similarity index 100% rename from composeApp/src/commonMain/composeResources/drawable/jp.png rename to shared/src/commonMain/composeResources/drawable/jp.png diff --git a/composeApp/src/commonMain/composeResources/drawable/mx.png b/shared/src/commonMain/composeResources/drawable/mx.png similarity index 100% rename from composeApp/src/commonMain/composeResources/drawable/mx.png rename to shared/src/commonMain/composeResources/drawable/mx.png diff --git a/composeApp/src/commonMain/kotlin/compose/project/demo/composedemo/App.kt b/shared/src/commonMain/kotlin/App.kt similarity index 63% rename from composeApp/src/commonMain/kotlin/compose/project/demo/composedemo/App.kt rename to shared/src/commonMain/kotlin/App.kt index 111eb3d..ea55507 100644 --- a/composeApp/src/commonMain/kotlin/compose/project/demo/composedemo/App.kt +++ b/shared/src/commonMain/kotlin/App.kt @@ -1,54 +1,28 @@ package compose.project.demo.composedemo import androidx.compose.foundation.Image -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.safeContentPadding -import androidx.compose.foundation.layout.size -import androidx.compose.material3.Button -import androidx.compose.material3.DropdownMenu -import androidx.compose.material3.DropdownMenuItem -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.setValue +import androidx.compose.foundation.layout.* +import androidx.compose.material3.* +import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp -import composedemo.composeapp.generated.resources.Res -import composedemo.composeapp.generated.resources.eg -import composedemo.composeapp.generated.resources.fr -import composedemo.composeapp.generated.resources.id -import composedemo.composeapp.generated.resources.jp -import composedemo.composeapp.generated.resources.mx -import kotlin.time.Clock -import kotlinx.datetime.LocalTime +import composedemo.shared.generated.resources.Res +import composedemo.shared.generated.resources.eg +import composedemo.shared.generated.resources.fr +import composedemo.shared.generated.resources.id +import composedemo.shared.generated.resources.jp +import composedemo.shared.generated.resources.mx import kotlinx.datetime.TimeZone -import kotlinx.datetime.toLocalDateTime import org.jetbrains.compose.resources.DrawableResource import org.jetbrains.compose.resources.painterResource -import org.jetbrains.compose.ui.tooling.preview.Preview data class Country(val name: String, val zone: TimeZone, val image: DrawableResource) -fun currentTimeAt(location: String, zone: TimeZone): String { - fun LocalTime.formatted() = "$hour:$minute:$second" - - val time = Clock.System.now() - val localTime = time.toLocalDateTime(zone).time - - return "The time in $location is ${localTime.formatted()}" -} - val defaultCountries = listOf( Country("Japan", TimeZone.of("Asia/Tokyo"), Res.drawable.jp), Country("France", TimeZone.of("Europe/Paris"), Res.drawable.fr), @@ -59,7 +33,7 @@ val defaultCountries = listOf( @Composable @Preview -fun App(countries: List = defaultCountries) { +fun App() { MaterialTheme { var showCountries by remember { mutableStateOf(false) } var timeAtLocation by remember { mutableStateOf("No location selected") } @@ -81,7 +55,7 @@ fun App(countries: List = defaultCountries) { expanded = showCountries, onDismissRequest = { showCountries = false } ) { - countries.forEach { (name, zone, image) -> + defaultCountries.forEach { (name, zone, image) -> DropdownMenuItem( text = { Row(verticalAlignment = Alignment.CenterVertically) { diff --git a/shared/src/commonMain/kotlin/Time.kt b/shared/src/commonMain/kotlin/Time.kt new file mode 100644 index 0000000..93a6978 --- /dev/null +++ b/shared/src/commonMain/kotlin/Time.kt @@ -0,0 +1,17 @@ +package compose.project.demo.composedemo + +import kotlinx.datetime.LocalTime +import kotlinx.datetime.TimeZone +import kotlinx.datetime.toLocalDateTime +import kotlin.time.Clock +import kotlin.time.ExperimentalTime + +@OptIn(ExperimentalTime::class) +fun currentTimeAt(location: String, zone: TimeZone): String { + fun LocalTime.formatted() = "$hour:$minute:$second" + + val time = Clock.System.now() + val localTime = time.toLocalDateTime(zone).time + + return "The time in $location is ${localTime.formatted()}" +} \ No newline at end of file diff --git a/composeApp/src/iosMain/kotlin/compose/project/demo/composedemo/MainViewController.kt b/shared/src/iosMain/kotlin/compose/project/demo/composedemo/MainViewController.kt similarity index 100% rename from composeApp/src/iosMain/kotlin/compose/project/demo/composedemo/MainViewController.kt rename to shared/src/iosMain/kotlin/compose/project/demo/composedemo/MainViewController.kt diff --git a/webApp/build.gradle.kts b/webApp/build.gradle.kts new file mode 100644 index 0000000..f50b4e0 --- /dev/null +++ b/webApp/build.gradle.kts @@ -0,0 +1,30 @@ +import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl + +plugins { + alias(libs.plugins.kotlinMultiplatform) + alias(libs.plugins.composeMultiplatform) + alias(libs.plugins.composeCompiler) +} + + +kotlin { + js { + browser() + binaries.executable() + } + + @OptIn(ExperimentalWasmDsl::class) + wasmJs { + browser() + binaries.executable() + } + + sourceSets { + commonMain.dependencies { + implementation(projects.shared) + + implementation(libs.compose.ui) + implementation(npm("@js-joda/timezone", "2.22.0")) + } + } +} \ No newline at end of file diff --git a/composeApp/src/webMain/kotlin/compose/project/demo/composedemo/main.kt b/webApp/src/webMain/kotlin/compose/project/demo/composedemo/main.kt similarity index 100% rename from composeApp/src/webMain/kotlin/compose/project/demo/composedemo/main.kt rename to webApp/src/webMain/kotlin/compose/project/demo/composedemo/main.kt diff --git a/composeApp/src/webMain/resources/index.html b/webApp/src/webMain/resources/index.html similarity index 78% rename from composeApp/src/webMain/resources/index.html rename to webApp/src/webMain/resources/index.html index 0efc1d6..0038506 100644 --- a/composeApp/src/webMain/resources/index.html +++ b/webApp/src/webMain/resources/index.html @@ -5,7 +5,7 @@ composedemo - + diff --git a/composeApp/src/webMain/resources/styles.css b/webApp/src/webMain/resources/styles.css similarity index 100% rename from composeApp/src/webMain/resources/styles.css rename to webApp/src/webMain/resources/styles.css