From f4ae237a43e118405b97fe40df7c0c8f0d2fd7b0 Mon Sep 17 00:00:00 2001 From: Yahor Date: Thu, 30 May 2024 12:52:59 +0300 Subject: [PATCH] Kotlin 2.0, Compose 1.6.10, add Wasm target (#31) * Kotlin 2.0, Compose 1.6.10, add Wasm target * Rearrange sample structure --- .github/workflows/wasm_deploy.yml | 5 +- .gitignore | 15 +++- README.md | 36 +++++---- build.gradle.kts | 18 ++--- config/detekt/detekt.yml | 2 + example/{ => app}/composeApp/build.gradle.kts | 75 +++++++++++++----- .../src/androidMain/AndroidManifest.xml | 4 +- .../tiamat/example}/DeeplinkHelper.kt | 2 +- .../tiamat/example}/MainActivity.kt | 16 ++-- .../tiamat/example}/MainApplication.kt | 4 +- .../example/PlatformExamplesScreen.android.kt | 29 +++++++ .../platform}/AndroidViewLifecycleScreen.kt | 10 +-- .../example/platform}/DeeplinkScreen.kt | 12 +-- .../example/platform}/SavedStateScreen.kt | 4 +- .../src/androidMain/res/values/strings.xml | 0 .../composegears/tiamat/example}/App.kt | 33 +++++--- .../tiamat/example}/BackStackAlteration.kt | 4 +- .../tiamat/example}/CustomTransition.kt | 4 +- .../tiamat/example}/DataPassingFreeArgs.kt | 6 +- .../tiamat/example}/DataPassingParams.kt | 8 +- .../tiamat/example}/DataPassingResult.kt | 4 +- .../tiamat/example}/MainScreen.kt | 11 +-- .../tiamat/example}/NestedNavigation.kt | 4 +- .../tiamat/example/PlatformExamplesScreen.kt} | 51 +++++++----- .../tiamat/example}/SimpleForwardBack.kt | 5 +- .../tiamat/example}/SimpleReplace.kt | 10 +-- .../composegears/tiamat/example}/Tabs.kt | 8 +- .../example}/TwoPaneResizableExample.kt | 10 +-- .../tiamat/example}/ViewModels.kt | 4 +- .../tiamat/example}/multimodule/BaseModule.kt | 2 +- .../tiamat/example}/multimodule/Feature1.kt | 4 +- .../tiamat/example}/multimodule/Feature2.kt | 4 +- .../tiamat/example}/multimodule/Root.kt | 4 +- .../example/PlatformExamplesScreen.desktop.kt | 14 ++++ .../composegears/tiamat/example}/main.kt | 8 +- .../tiamat/example}/MainViewController.kt | 2 +- .../example/PlatformExamplesScreen.ios.kt | 13 +++ .../example/PlatformExamplesScreen.wasmJs.kt | 6 ++ .../composegears/tiamat/example/main.kt | 37 +++++++++ .../src/wasmJsMain/resources/app.js | 7 ++ .../wasmJsMain/resources/images/tiamat.png | Bin 0 -> 5277 bytes .../src/wasmJsMain/resources/index.html | 30 +++++++ .../src/wasmJsMain/resources/manifest.json | 13 +++ .../src/wasmJsMain/resources/style.css | 51 ++++++++++++ .../resources/unsupported_browser.js | 16 ++++ .../iosApp/Configuration/Config.xcconfig | 0 .../iosApp/iosApp.xcodeproj/project.pbxproj | 2 +- .../AccentColor.colorset/Contents.json | 0 .../AppIcon.appiconset/Contents.json | 0 .../AppIcon.appiconset/app-icon-1024.png | Bin .../iosApp/Assets.xcassets/Contents.json | 0 .../{ => app}/iosApp/iosApp/ContentView.swift | 0 example/{ => app}/iosApp/iosApp/Info.plist | 0 .../Preview Assets.xcassets/Contents.json | 0 example/{ => app}/iosApp/iosApp/iOSApp.swift | 0 .../examples/PlatformExample.android.kt | 43 ---------- .../content/examples/PlatformExample.kt | 5 -- .../examples/PlatformExample.desktop.kt | 12 --- .../content/examples/PlatformExample.ios.kt | 12 --- example/sample-koin/build.gradle.kts | 38 +++++++++ .../sample/koin/KoinIntegrationScreen.kt} | 40 ++-------- .../tiamat/sample}/koin/KoinLib.kt | 2 +- .../tiamat/sample}/koin/KoinModule.kt | 5 +- .../koin/viewmodel/KoinDetailViewModel.kt | 32 ++++++++ .../sample/koin/viewmodel/SharedViewModel.kt | 22 +++++ example/ui-core/build.gradle.kts | 46 +++++++++++ .../tiamat/example/ui/core}/AppTheme.kt | 4 +- .../tiamat/example/ui/core}/Common.kt | 39 +-------- .../tiamat/example/ui/core/SimpleScreen.kt | 56 +++++++++++++ gradle.properties | 11 ++- gradle/libs.versions.toml | 19 ++--- settings.gradle.kts | 4 +- tiamat-koin/build.gradle.kts | 13 ++- tiamat/build.gradle.kts | 18 ++++- .../com/composegears/tiamat/Platform.wasm.kt | 37 +++++++++ 75 files changed, 731 insertions(+), 334 deletions(-) rename example/{ => app}/composeApp/build.gradle.kts (50%) rename example/{ => app}/composeApp/src/androidMain/AndroidManifest.xml (90%) rename example/{composeApp/src/androidMain/kotlin/com/composegear/navigation => app/composeApp/src/androidMain/kotlin/composegears/tiamat/example}/DeeplinkHelper.kt (96%) rename example/{composeApp/src/androidMain/kotlin/com/composegear/navigation => app/composeApp/src/androidMain/kotlin/composegears/tiamat/example}/MainActivity.kt (81%) rename example/{composeApp/src/androidMain/kotlin/com/composegear/navigation => app/composeApp/src/androidMain/kotlin/composegears/tiamat/example}/MainApplication.kt (65%) create mode 100644 example/app/composeApp/src/androidMain/kotlin/composegears/tiamat/example/PlatformExamplesScreen.android.kt rename example/{composeApp/src/androidMain/kotlin/content/examples/platform/examples => app/composeApp/src/androidMain/kotlin/composegears/tiamat/example/platform}/AndroidViewLifecycleScreen.kt (95%) rename example/{composeApp/src/androidMain/kotlin/content/examples/platform/examples => app/composeApp/src/androidMain/kotlin/composegears/tiamat/example/platform}/DeeplinkScreen.kt (90%) rename example/{composeApp/src/androidMain/kotlin/content/examples/platform/examples => app/composeApp/src/androidMain/kotlin/composegears/tiamat/example/platform}/SavedStateScreen.kt (97%) rename example/{ => app}/composeApp/src/androidMain/res/values/strings.xml (100%) rename example/{composeApp/src/commonMain/kotlin => app/composeApp/src/commonMain/kotlin/composegears/tiamat/example}/App.kt (72%) rename example/{composeApp/src/commonMain/kotlin/content/examples => app/composeApp/src/commonMain/kotlin/composegears/tiamat/example}/BackStackAlteration.kt (98%) rename example/{composeApp/src/commonMain/kotlin/content/examples => app/composeApp/src/commonMain/kotlin/composegears/tiamat/example}/CustomTransition.kt (97%) rename example/{composeApp/src/commonMain/kotlin/content/examples => app/composeApp/src/commonMain/kotlin/composegears/tiamat/example}/DataPassingFreeArgs.kt (93%) rename example/{composeApp/src/commonMain/kotlin/content/examples => app/composeApp/src/commonMain/kotlin/composegears/tiamat/example}/DataPassingParams.kt (91%) rename example/{composeApp/src/commonMain/kotlin/content/examples => app/composeApp/src/commonMain/kotlin/composegears/tiamat/example}/DataPassingResult.kt (96%) rename example/{composeApp/src/commonMain/kotlin/content => app/composeApp/src/commonMain/kotlin/composegears/tiamat/example}/MainScreen.kt (89%) rename example/{composeApp/src/commonMain/kotlin/content/examples => app/composeApp/src/commonMain/kotlin/composegears/tiamat/example}/NestedNavigation.kt (95%) rename example/{composeApp/src/androidMain/kotlin/content/examples/platform/MainPlatformScreen.kt => app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/PlatformExamplesScreen.kt} (55%) rename example/{composeApp/src/commonMain/kotlin/content/examples => app/composeApp/src/commonMain/kotlin/composegears/tiamat/example}/SimpleForwardBack.kt (96%) rename example/{composeApp/src/commonMain/kotlin/content/examples => app/composeApp/src/commonMain/kotlin/composegears/tiamat/example}/SimpleReplace.kt (91%) rename example/{composeApp/src/commonMain/kotlin/content/examples => app/composeApp/src/commonMain/kotlin/composegears/tiamat/example}/Tabs.kt (95%) rename example/{composeApp/src/commonMain/kotlin/content/examples => app/composeApp/src/commonMain/kotlin/composegears/tiamat/example}/TwoPaneResizableExample.kt (94%) rename example/{composeApp/src/commonMain/kotlin/content/examples => app/composeApp/src/commonMain/kotlin/composegears/tiamat/example}/ViewModels.kt (98%) rename example/{composeApp/src/commonMain/kotlin/content/examples => app/composeApp/src/commonMain/kotlin/composegears/tiamat/example}/multimodule/BaseModule.kt (96%) rename example/{composeApp/src/commonMain/kotlin/content/examples => app/composeApp/src/commonMain/kotlin/composegears/tiamat/example}/multimodule/Feature1.kt (88%) rename example/{composeApp/src/commonMain/kotlin/content/examples => app/composeApp/src/commonMain/kotlin/composegears/tiamat/example}/multimodule/Feature2.kt (91%) rename example/{composeApp/src/commonMain/kotlin/content/examples => app/composeApp/src/commonMain/kotlin/composegears/tiamat/example}/multimodule/Root.kt (95%) create mode 100644 example/app/composeApp/src/desktopMain/kotlin/composegears/tiamat/example/PlatformExamplesScreen.desktop.kt rename example/{composeApp/src/desktopMain/kotlin => app/composeApp/src/desktopMain/kotlin/composegears/tiamat/example}/main.kt (88%) rename example/{composeApp/src/iosMain/kotlin => app/composeApp/src/iosMain/kotlin/composegears/tiamat/example}/MainViewController.kt (73%) create mode 100644 example/app/composeApp/src/iosMain/kotlin/composegears/tiamat/example/PlatformExamplesScreen.ios.kt create mode 100644 example/app/composeApp/src/wasmJsMain/kotlin/composegears/tiamat/example/PlatformExamplesScreen.wasmJs.kt create mode 100644 example/app/composeApp/src/wasmJsMain/kotlin/composegears/tiamat/example/main.kt create mode 100644 example/app/composeApp/src/wasmJsMain/resources/app.js create mode 100644 example/app/composeApp/src/wasmJsMain/resources/images/tiamat.png create mode 100644 example/app/composeApp/src/wasmJsMain/resources/index.html create mode 100644 example/app/composeApp/src/wasmJsMain/resources/manifest.json create mode 100644 example/app/composeApp/src/wasmJsMain/resources/style.css create mode 100644 example/app/composeApp/src/wasmJsMain/resources/unsupported_browser.js rename example/{ => app}/iosApp/Configuration/Config.xcconfig (100%) rename example/{ => app}/iosApp/iosApp.xcodeproj/project.pbxproj (99%) rename example/{ => app}/iosApp/iosApp/Assets.xcassets/AccentColor.colorset/Contents.json (100%) rename example/{ => app}/iosApp/iosApp/Assets.xcassets/AppIcon.appiconset/Contents.json (100%) rename example/{ => app}/iosApp/iosApp/Assets.xcassets/AppIcon.appiconset/app-icon-1024.png (100%) rename example/{ => app}/iosApp/iosApp/Assets.xcassets/Contents.json (100%) rename example/{ => app}/iosApp/iosApp/ContentView.swift (100%) rename example/{ => app}/iosApp/iosApp/Info.plist (100%) rename example/{ => app}/iosApp/iosApp/Preview Content/Preview Assets.xcassets/Contents.json (100%) rename example/{ => app}/iosApp/iosApp/iOSApp.swift (100%) delete mode 100644 example/composeApp/src/androidMain/kotlin/content/examples/PlatformExample.android.kt delete mode 100644 example/composeApp/src/commonMain/kotlin/content/examples/PlatformExample.kt delete mode 100644 example/composeApp/src/desktopMain/kotlin/content/examples/PlatformExample.desktop.kt delete mode 100644 example/composeApp/src/iosMain/kotlin/content/examples/PlatformExample.ios.kt create mode 100644 example/sample-koin/build.gradle.kts rename example/{composeApp/src/commonMain/kotlin/content/examples/koin/KoinIntegration.kt => sample-koin/src/commonMain/kotlin/composegears/tiamat/sample/koin/KoinIntegrationScreen.kt} (72%) rename example/{composeApp/src/commonMain/kotlin/content/examples => sample-koin/src/commonMain/kotlin/composegears/tiamat/sample}/koin/KoinLib.kt (79%) rename example/{composeApp/src/commonMain/kotlin/content/examples => sample-koin/src/commonMain/kotlin/composegears/tiamat/sample}/koin/KoinModule.kt (67%) create mode 100644 example/sample-koin/src/commonMain/kotlin/composegears/tiamat/sample/koin/viewmodel/KoinDetailViewModel.kt create mode 100644 example/sample-koin/src/commonMain/kotlin/composegears/tiamat/sample/koin/viewmodel/SharedViewModel.kt create mode 100644 example/ui-core/build.gradle.kts rename example/{composeApp/src/commonMain/kotlin => ui-core/src/commonMain/kotlin/composegears/tiamat/example/ui/core}/AppTheme.kt (94%) rename example/{composeApp/src/commonMain/kotlin/content/examples/common => ui-core/src/commonMain/kotlin/composegears/tiamat/example/ui/core}/Common.kt (76%) create mode 100644 example/ui-core/src/commonMain/kotlin/composegears/tiamat/example/ui/core/SimpleScreen.kt create mode 100644 tiamat/src/wasmJsMain/kotlin/com/composegears/tiamat/Platform.wasm.kt diff --git a/.github/workflows/wasm_deploy.yml b/.github/workflows/wasm_deploy.yml index 0b0592c..ed6d5f0 100644 --- a/.github/workflows/wasm_deploy.yml +++ b/.github/workflows/wasm_deploy.yml @@ -21,11 +21,8 @@ jobs: distribution: 'zulu' java-version: 17 - - name: kotlinUpgradeYarnLock - run: ./gradlew kotlinUpgradeYarnLock - - name: Build web app - run: ./gradlew :example:composeApp:assemble + run: ./gradlew :example:composeApp:wasmJsBrowserDistribution - name: Upload artifact uses: actions/upload-pages-artifact@v3 diff --git a/.gitignore b/.gitignore index 52b1c6a..038500d 100644 --- a/.gitignore +++ b/.gitignore @@ -9,5 +9,18 @@ local.properties captures .externalNativeBuild .cxx +.kotlin publish.bat -kotlin-js-store/ \ No newline at end of file +kotlin-js-store/ + +# Xcode +*.pbxuser +*.mode1v3 +*.mode2v3 +*.perspectivev3 +*.xcuserstate +*.xccheckout +*.xcsmblueprint +xcuserdata/ +xcshareddata/ +contents.xcworkspacedata \ No newline at end of file diff --git a/README.md b/README.md index 50b0073..6136718 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ Setup } ``` -see example: [App.kt](example/composeApp/src/commonMain/kotlin/App.kt#L16) +see example: [App.kt](example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/App.kt#L27) Overview -------- @@ -249,19 +249,19 @@ Custom transition: ### Examples code -- [SimpleForwardBack.kt](example/composeApp/src/commonMain/kotlin/content/examples/SimpleForwardBack.kt) - Simple back and forward navigation -- [SimpleReplace.kt](example/composeApp/src/commonMain/kotlin/content/examples/SimpleReplace.kt) - Example of `replace` navigation -- [Tabs.kt](example/composeApp/src/commonMain/kotlin/content/examples/Tabs.kt) - Bottom navigation example -- [NestedNavigation.kt](example/composeApp/src/commonMain/kotlin/content/examples/NestedNavigation.kt) - Nested nav controller interaction -- [DataPassingParams.kt](example/composeApp/src/commonMain/kotlin/content/examples/DataPassingParams.kt) - How to pass data to next screen -- [DataPassingFreeArgs.kt](example/composeApp/src/commonMain/kotlin/content/examples/DataPassingFreeArgs.kt) - How to pass addition type-free data to next screen (useful to metadata/deeplink) -- [DataPassingResult.kt](example/composeApp/src/commonMain/kotlin/content/examples/DataPassingResult.kt) - How to provide result -- [ViewModels.kt](example/composeApp/src/commonMain/kotlin/content/examples/ViewModels.kt) - ViewModels usage -- [CustomTransition.kt](example/composeApp/src/commonMain/kotlin/content/examples/CustomTransition.kt) - Custom animations/transition -- [Root.kt](example/composeApp/src/commonMain/kotlin/content/examples/multimodule/Root.kt) - Multi-module communication example (using Signals/Broadcast-api) -- [BackStackAlteration.kt](example/composeApp/src/commonMain/kotlin/content/examples/BackStackAlteration.kt) - Alteration(modification) of backstack (deeplinks) -- [TwoPaneResizableExample.kt](example/composeApp/src/commonMain/kotlin/content/examples/TwoPaneResizableExample.kt) - 2 pane example (list+details, dynamic switch between 1-pane or 2-pane layout) -- [KoinIntegration.kt](example/composeApp/src/commonMain/kotlin/content/examples/koin/KoinIntegration.kt) - Koin integration +- [SimpleForwardBack.kt](example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/SimpleForwardBack.kt) - Simple back and forward navigation +- [SimpleReplace.kt](example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/SimpleReplace.kt) - Example of `replace` navigation +- [Tabs.kt](example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/Tabs.kt) - Bottom navigation example +- [NestedNavigation.kt](example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/NestedNavigation.kt) - Nested nav controller interaction +- [DataPassingParams.kt](example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/DataPassingParams.kt) - How to pass data to next screen +- [DataPassingFreeArgs.kt](example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/DataPassingFreeArgs.kt) - How to pass addition type-free data to next screen (useful to metadata/deeplink) +- [DataPassingResult.kt](example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/DataPassingResult.kt) - How to provide result +- [ViewModels.kt](example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/ViewModels.kt) - ViewModels usage +- [CustomTransition.kt](example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/CustomTransition.kt) - Custom animations/transition +- [Root.kt](example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/multimodule/Root.kt) - Multi-module communication example (using Signals/Broadcast-api) +- [BackStackAlteration.kt](example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/BackStackAlteration.kt) - Alteration(modification) of backstack (deeplinks) +- [TwoPaneResizableExample.kt](example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/TwoPaneResizableExample.kt) - 2 pane example (list+details, dynamic switch between 1-pane or 2-pane layout) +- [KoinIntegrationScreen.kt](example/sample-koin/src/commonMain/kotlin/composegears/tiamat/sample/koin/KoinIntegrationScreen.kt) - Koin integration Hint ---- @@ -322,7 +322,7 @@ fun main() = application { ### Android `Tiamat-android` overrides `LocalLifecycleOwner` for each destination and compatible with lifecycle-aware components -See an example of camera usage: [AndroidViewLifecycleExample.kt](example/composeApp/src/androidMain/kotlin/content/examples/platform/examples/AndroidViewLifecycleScreen.kt) +See an example of camera usage: [AndroidViewLifecycleScreen.kt](example/app/composeApp/src/androidMain/kotlin/composegears/tiamat/example/platform/AndroidViewLifecycleScreen.kt) ### iOS @@ -330,9 +330,11 @@ Nothing specific (yet) ### Run/Build sample -Android: `./gradlew example:composeApp:assembleDebug` +Android: `./gradlew example:app:composeApp:assembleDebug` -Desktop: `./gradlew example:composeApp:run` +Desktop: `./gradlew example:app:composeApp:run` + +Web: `./gradlew example:app:composeApp:wasmJsBrowserRun` iOS: run XCode project or else use [KMM](https://plugins.jetbrains.com/plugin/14936-kotlin-multiplatform-mobile) plugin iOS target diff --git a/build.gradle.kts b/build.gradle.kts index a900d75..6042fbc 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,6 +4,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { alias(libs.plugins.android.application) apply false alias(libs.plugins.android.library) apply false + alias(libs.plugins.compose.compiler) alias(libs.plugins.jetbrains.compose) apply false alias(libs.plugins.detekt) alias(libs.plugins.kotlin.multiplatform) apply false @@ -29,8 +30,10 @@ allprojects { files( "src/commonMain/kotlin", "src/jvmMain/kotlin", + "src/desktopMain/kotlin", "src/androidMain/kotlin", "src/iosMain/kotlin", + "src/wasmJsMain/kotlin", ) ) } @@ -44,18 +47,13 @@ allprojects { subprojects { tasks.withType().configureEach { val outPath = layout.buildDirectory.dir("compose_compiler").get().asFile.absoluteFile + compilerOptions { if (project.findProperty("composeCompilerReports") == "true") { - freeCompilerArgs.addAll( - "-P", - "plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=$outPath" - ) - } - if (project.findProperty("composeCompilerMetrics") == "true") { - freeCompilerArgs.addAll( - "-P", - "plugin:androidx.compose.compiler.plugins.kotlin:metricsDestination=$outPath" - ) + composeCompiler { + reportsDestination = outPath + metricsDestination = outPath + } } } } diff --git a/config/detekt/detekt.yml b/config/detekt/detekt.yml index 0c04bbc..cfe7e52 100644 --- a/config/detekt/detekt.yml +++ b/config/detekt/detekt.yml @@ -1133,6 +1133,8 @@ Compose: active: true MutableParams: active: true + ParameterNaming: + active: true MutableStateAutoboxing: active: true MutableStateParam: diff --git a/example/composeApp/build.gradle.kts b/example/app/composeApp/build.gradle.kts similarity index 50% rename from example/composeApp/build.gradle.kts rename to example/app/composeApp/build.gradle.kts index 0a388ec..d6b67aa 100644 --- a/example/composeApp/build.gradle.kts +++ b/example/app/composeApp/build.gradle.kts @@ -1,21 +1,24 @@ import org.jetbrains.compose.desktop.application.dsl.TargetFormat +import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi +import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl +import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig plugins { alias(libs.plugins.kotlin.multiplatform) alias(libs.plugins.android.application) + alias(libs.plugins.compose.compiler) alias(libs.plugins.jetbrains.compose) alias(libs.plugins.kotlin.parcelize) } kotlin { androidTarget { - compilations.all { - kotlinOptions { - jvmTarget = "1.8" - } + @OptIn(ExperimentalKotlinGradlePluginApi::class) + compilerOptions { + jvmTarget = JvmTarget.JVM_1_8 } } - jvm("desktop") listOf( @@ -26,40 +29,68 @@ kotlin { iosTarget.binaries.framework { baseName = "ComposeApp" isStatic = true + + export(projects.example.sampleKoin) } } - sourceSets { - val desktopMain by getting + @OptIn(ExperimentalWasmDsl::class) + wasmJs { + moduleName = "tiamatApp" + browser { + commonWebpackConfig { + outputFileName = "tiamatApp.js" + devServer = (devServer ?: KotlinWebpackConfig.DevServer()).apply { + static = (static ?: mutableListOf()).apply { + // Serve sources to debug inside browser + add(project.projectDir.path) + } + } + } + } + binaries.executable() + } + sourceSets { + commonMain.dependencies { + implementation(projects.tiamat) + implementation(projects.example.uiCore) + } androidMain.dependencies { + implementation(projects.tiamatKoin) + implementation(projects.example.sampleKoin) + implementation(libs.androidx.activity.compose) implementation(libs.androidx.camera.camera2) implementation(libs.androidx.camera.lifecycle) implementation(libs.androidx.camera.view) implementation(libs.androidx.concurrent.futures) + implementation(libs.koin.compose) } - commonMain.dependencies { - implementation(projects.tiamat) + iosMain.dependencies { implementation(projects.tiamatKoin) - - implementation(compose.runtime) - implementation(compose.foundation) - implementation(compose.material3) - implementation(compose.materialIconsExtended) - implementation(compose.ui) + api(projects.example.sampleKoin) implementation(libs.koin.compose) } - desktopMain.dependencies { - implementation(compose.desktop.currentOs) - implementation(libs.kotlin.coroutines.swing) + wasmJsMain.dependencies { + + } + val desktopMain by getting { + dependencies { + implementation(projects.tiamatKoin) + implementation(projects.example.sampleKoin) + + implementation(compose.desktop.currentOs) + implementation(libs.koin.compose) + implementation(libs.kotlin.coroutines.swing) + } } } } android { - namespace = "com.compose.gear.navigation.example" + namespace = "composegears.tiamat.example" compileSdk = libs.versions.android.compileSdk.get().toInt() sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml") @@ -67,7 +98,7 @@ android { sourceSets["main"].resources.srcDirs("src/commonMain/resources") defaultConfig { - applicationId = "com.compose.gear.navigation" + applicationId = "composegears.tiamat.example" minSdk = libs.versions.android.minSdk.get().toInt() targetSdk = libs.versions.android.targetSdk.get().toInt() versionCode = 1 @@ -81,11 +112,11 @@ android { compose.desktop { application { - mainClass = "MainKt" + mainClass = "composegears.tiamat.example.MainKt" nativeDistributions { targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb) - packageName = "com.compose.gear.navigation.example" + packageName = "composegears.tiamat.example" packageVersion = "1.0.0" } } diff --git a/example/composeApp/src/androidMain/AndroidManifest.xml b/example/app/composeApp/src/androidMain/AndroidManifest.xml similarity index 90% rename from example/composeApp/src/androidMain/AndroidManifest.xml rename to example/app/composeApp/src/androidMain/AndroidManifest.xml index 0f4acc9..b8b6dbe 100644 --- a/example/composeApp/src/androidMain/AndroidManifest.xml +++ b/example/app/composeApp/src/androidMain/AndroidManifest.xml @@ -8,10 +8,10 @@ android:allowBackup="true" android:label="@string/app_name" android:supportsRtl="true" - android:name="com.composegear.navigation.MainApplication" + android:name=".MainApplication" android:theme="@android:style/Theme.Material.Light.NoActionBar"> diff --git a/example/composeApp/src/androidMain/kotlin/com/composegear/navigation/DeeplinkHelper.kt b/example/app/composeApp/src/androidMain/kotlin/composegears/tiamat/example/DeeplinkHelper.kt similarity index 96% rename from example/composeApp/src/androidMain/kotlin/com/composegear/navigation/DeeplinkHelper.kt rename to example/app/composeApp/src/androidMain/kotlin/composegears/tiamat/example/DeeplinkHelper.kt index 296951c..f8ede62 100644 --- a/example/composeApp/src/androidMain/kotlin/com/composegear/navigation/DeeplinkHelper.kt +++ b/example/app/composeApp/src/androidMain/kotlin/composegears/tiamat/example/DeeplinkHelper.kt @@ -1,4 +1,4 @@ -package com.composegear.navigation +package composegears.tiamat.example import android.content.Intent import androidx.compose.runtime.getValue diff --git a/example/composeApp/src/androidMain/kotlin/com/composegear/navigation/MainActivity.kt b/example/app/composeApp/src/androidMain/kotlin/composegears/tiamat/example/MainActivity.kt similarity index 81% rename from example/composeApp/src/androidMain/kotlin/com/composegear/navigation/MainActivity.kt rename to example/app/composeApp/src/androidMain/kotlin/composegears/tiamat/example/MainActivity.kt index b0a7254..66b1538 100644 --- a/example/composeApp/src/androidMain/kotlin/com/composegear/navigation/MainActivity.kt +++ b/example/app/composeApp/src/androidMain/kotlin/composegears/tiamat/example/MainActivity.kt @@ -1,6 +1,5 @@ -package com.composegear.navigation +package composegears.tiamat.example -import App import android.content.Intent import android.os.Bundle import androidx.activity.ComponentActivity @@ -8,8 +7,7 @@ import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge import androidx.compose.runtime.DisposableEffect import com.composegears.tiamat.navigationFadeInOut -import content.MainScreen -import content.examples.PlatformExample +import composegears.tiamat.example.platform.DeeplinkScreen class MainActivity : ComponentActivity() { @@ -20,7 +18,7 @@ class MainActivity : ComponentActivity() { super.onCreate(savedInstanceState) deepLinkController.onIntent(intent) setContent { - App { rootNavController -> + App { rootNavController, content -> // pass deeplink deeper and handle inside screen val deeplink = deepLinkController.deeplink // using disposable effect as it runs faster then LaunchedEffect @@ -29,9 +27,10 @@ class MainActivity : ComponentActivity() { rootNavController.editBackStack { clear() add(MainScreen) + add(PlatformExamplesScreen) } rootNavController.replace( - dest = PlatformExample, + dest = DeeplinkScreen, freeArgs = deeplink, // we only animate root content switch // all nested items should use navigationNone() transition to prevent `blink` @@ -41,12 +40,13 @@ class MainActivity : ComponentActivity() { } onDispose { } } + content() } } } - override fun onNewIntent(intent: Intent?) { + override fun onNewIntent(intent: Intent) { super.onNewIntent(intent) - intent?.let(deepLinkController::onIntent) + deepLinkController.onIntent(intent) } } \ No newline at end of file diff --git a/example/composeApp/src/androidMain/kotlin/com/composegear/navigation/MainApplication.kt b/example/app/composeApp/src/androidMain/kotlin/composegears/tiamat/example/MainApplication.kt similarity index 65% rename from example/composeApp/src/androidMain/kotlin/com/composegear/navigation/MainApplication.kt rename to example/app/composeApp/src/androidMain/kotlin/composegears/tiamat/example/MainApplication.kt index b08bb13..89fb99b 100644 --- a/example/composeApp/src/androidMain/kotlin/com/composegear/navigation/MainApplication.kt +++ b/example/app/composeApp/src/androidMain/kotlin/composegears/tiamat/example/MainApplication.kt @@ -1,7 +1,7 @@ -package com.composegear.navigation +package composegears.tiamat.example import android.app.Application -import content.examples.koin.KoinLib +import composegears.tiamat.sample.koin.KoinLib class MainApplication : Application() { diff --git a/example/app/composeApp/src/androidMain/kotlin/composegears/tiamat/example/PlatformExamplesScreen.android.kt b/example/app/composeApp/src/androidMain/kotlin/composegears/tiamat/example/PlatformExamplesScreen.android.kt new file mode 100644 index 0000000..6e9ea84 --- /dev/null +++ b/example/app/composeApp/src/androidMain/kotlin/composegears/tiamat/example/PlatformExamplesScreen.android.kt @@ -0,0 +1,29 @@ +package composegears.tiamat.example + +import composegears.tiamat.example.PlatformConfig.PlatformDestination +import composegears.tiamat.example.platform.AndroidViewLifecycleScreen +import composegears.tiamat.example.platform.DeeplinkScreen +import composegears.tiamat.example.platform.SavedStateScreen +import composegears.tiamat.sample.koin.KoinIntegrationScreen + +actual val platformExamplesConfig = PlatformConfig( + platformName = "Android", + availableScreens = listOf( + PlatformDestination( + name = "Android SavedState", + destination = SavedStateScreen + ), + PlatformDestination( + name = "AndroidView + Lifecycle handle", + destination = AndroidViewLifecycleScreen + ), + PlatformDestination( + name = "Deeplink", + destination = DeeplinkScreen + ), + PlatformDestination( + name = "Koin (ViewModel/SharedViewModel)", + destination = KoinIntegrationScreen + ) + ) +) \ No newline at end of file diff --git a/example/composeApp/src/androidMain/kotlin/content/examples/platform/examples/AndroidViewLifecycleScreen.kt b/example/app/composeApp/src/androidMain/kotlin/composegears/tiamat/example/platform/AndroidViewLifecycleScreen.kt similarity index 95% rename from example/composeApp/src/androidMain/kotlin/content/examples/platform/examples/AndroidViewLifecycleScreen.kt rename to example/app/composeApp/src/androidMain/kotlin/composegears/tiamat/example/platform/AndroidViewLifecycleScreen.kt index df4bef3..40ae616 100644 --- a/example/composeApp/src/androidMain/kotlin/content/examples/platform/examples/AndroidViewLifecycleScreen.kt +++ b/example/app/composeApp/src/androidMain/kotlin/composegears/tiamat/example/platform/AndroidViewLifecycleScreen.kt @@ -1,4 +1,4 @@ -package content.examples.platform.examples +package composegears.tiamat.example.platform import android.Manifest import android.app.Activity @@ -36,10 +36,10 @@ import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat import com.composegears.tiamat.navController import com.composegears.tiamat.navDestination -import content.examples.common.BackButton -import content.examples.common.NextButton -import content.examples.common.SimpleScreen -import content.examples.common.TextBody +import composegears.tiamat.example.ui.core.BackButton +import composegears.tiamat.example.ui.core.NextButton +import composegears.tiamat.example.ui.core.SimpleScreen +import composegears.tiamat.example.ui.core.TextBody val AndroidViewLifecycleScreen by navDestination { val context = LocalContext.current diff --git a/example/composeApp/src/androidMain/kotlin/content/examples/platform/examples/DeeplinkScreen.kt b/example/app/composeApp/src/androidMain/kotlin/composegears/tiamat/example/platform/DeeplinkScreen.kt similarity index 90% rename from example/composeApp/src/androidMain/kotlin/content/examples/platform/examples/DeeplinkScreen.kt rename to example/app/composeApp/src/androidMain/kotlin/composegears/tiamat/example/platform/DeeplinkScreen.kt index 125386a..091ab69 100644 --- a/example/composeApp/src/androidMain/kotlin/content/examples/platform/examples/DeeplinkScreen.kt +++ b/example/app/composeApp/src/androidMain/kotlin/composegears/tiamat/example/platform/DeeplinkScreen.kt @@ -1,4 +1,4 @@ -package content.examples.platform.examples +package composegears.tiamat.example.platform import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column @@ -7,12 +7,12 @@ import androidx.compose.material3.Text import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp -import com.composegear.navigation.DeeplinkData import com.composegears.tiamat.* -import content.examples.common.BackButton -import content.examples.common.NextButton -import content.examples.common.SimpleScreen -import content.examples.common.TextBody +import composegears.tiamat.example.DeeplinkData +import composegears.tiamat.example.ui.core.BackButton +import composegears.tiamat.example.ui.core.NextButton +import composegears.tiamat.example.ui.core.SimpleScreen +import composegears.tiamat.example.ui.core.TextBody /* * To run sample from adb, run in terminal: diff --git a/example/composeApp/src/androidMain/kotlin/content/examples/platform/examples/SavedStateScreen.kt b/example/app/composeApp/src/androidMain/kotlin/composegears/tiamat/example/platform/SavedStateScreen.kt similarity index 97% rename from example/composeApp/src/androidMain/kotlin/content/examples/platform/examples/SavedStateScreen.kt rename to example/app/composeApp/src/androidMain/kotlin/composegears/tiamat/example/platform/SavedStateScreen.kt index b433498..0c776a4 100644 --- a/example/composeApp/src/androidMain/kotlin/content/examples/platform/examples/SavedStateScreen.kt +++ b/example/app/composeApp/src/androidMain/kotlin/composegears/tiamat/example/platform/SavedStateScreen.kt @@ -1,4 +1,4 @@ -package content.examples.platform.examples +package composegears.tiamat.example.platform import android.os.Parcelable import androidx.compose.foundation.border @@ -17,7 +17,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import com.composegears.tiamat.* -import content.examples.common.* +import composegears.tiamat.example.ui.core.* import kotlinx.parcelize.Parcelize val SavedStateScreen by navDestination { diff --git a/example/composeApp/src/androidMain/res/values/strings.xml b/example/app/composeApp/src/androidMain/res/values/strings.xml similarity index 100% rename from example/composeApp/src/androidMain/res/values/strings.xml rename to example/app/composeApp/src/androidMain/res/values/strings.xml diff --git a/example/composeApp/src/commonMain/kotlin/App.kt b/example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/App.kt similarity index 72% rename from example/composeApp/src/commonMain/kotlin/App.kt rename to example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/App.kt index c03f209..f1e20c8 100644 --- a/example/composeApp/src/commonMain/kotlin/App.kt +++ b/example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/App.kt @@ -1,4 +1,4 @@ -@file:Suppress("MissingPackageDeclaration") +package composegears.tiamat.example import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.systemBarsPadding @@ -9,13 +9,19 @@ import com.composegears.tiamat.NavController import com.composegears.tiamat.Navigation import com.composegears.tiamat.StorageMode import com.composegears.tiamat.rememberNavController -import content.MainScreen -import content.examples.* -import content.examples.koin.KoinIntegration -import content.examples.multimodule.MultiModuleRoot +import composegears.tiamat.example.multimodule.MultiModuleRoot +import composegears.tiamat.example.ui.core.AppTheme @Composable -fun App(configure: @Composable (NavController) -> Unit = {}) { +@Suppress("SpreadOperator") +fun App( + configure: @Composable ( + NavController, + @Composable () -> Unit + ) -> Unit = { _, content -> + content() + } +) { AppTheme { Surface { val rootNavController = rememberNavController( @@ -47,15 +53,16 @@ fun App(configure: @Composable (NavController) -> Unit = {}) { MultiModuleRoot, BackStackAlterationRoot, TwoPaneResizableRoot, - KoinIntegration, - PlatformExample + PlatformExamplesScreen, + *platformExamplesConfig.destinations() ) ) - configure(rootNavController) - Navigation( - navController = rootNavController, - modifier = Modifier.fillMaxSize().systemBarsPadding() - ) + configure(rootNavController) { + Navigation( + navController = rootNavController, + modifier = Modifier.fillMaxSize().systemBarsPadding() + ) + } } } } \ No newline at end of file diff --git a/example/composeApp/src/commonMain/kotlin/content/examples/BackStackAlteration.kt b/example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/BackStackAlteration.kt similarity index 98% rename from example/composeApp/src/commonMain/kotlin/content/examples/BackStackAlteration.kt rename to example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/BackStackAlteration.kt index 3030af0..46adaca 100644 --- a/example/composeApp/src/commonMain/kotlin/content/examples/BackStackAlteration.kt +++ b/example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/BackStackAlteration.kt @@ -1,4 +1,4 @@ -package content.examples +package composegears.tiamat.example import androidx.compose.foundation.background import androidx.compose.foundation.border @@ -16,7 +16,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.unit.dp import com.composegears.tiamat.* -import content.examples.common.* +import composegears.tiamat.example.ui.core.* @Composable private fun NavDestinationScope<*>.Screen( diff --git a/example/composeApp/src/commonMain/kotlin/content/examples/CustomTransition.kt b/example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/CustomTransition.kt similarity index 97% rename from example/composeApp/src/commonMain/kotlin/content/examples/CustomTransition.kt rename to example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/CustomTransition.kt index 84b8d92..bd42334 100644 --- a/example/composeApp/src/commonMain/kotlin/content/examples/CustomTransition.kt +++ b/example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/CustomTransition.kt @@ -1,4 +1,4 @@ -package content.examples +package composegears.tiamat.example import androidx.compose.animation.scaleIn import androidx.compose.animation.scaleOut @@ -14,7 +14,7 @@ import com.composegears.tiamat.navController import com.composegears.tiamat.navDestination import com.composegears.tiamat.navigationSlideInOut import com.composegears.tiamat.navigationSlideOutToBottom -import content.examples.common.* +import composegears.tiamat.example.ui.core.* val CustomTransitionRoot by navDestination { val navController = navController() diff --git a/example/composeApp/src/commonMain/kotlin/content/examples/DataPassingFreeArgs.kt b/example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/DataPassingFreeArgs.kt similarity index 93% rename from example/composeApp/src/commonMain/kotlin/content/examples/DataPassingFreeArgs.kt rename to example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/DataPassingFreeArgs.kt index 14b6a3c..44ca303 100644 --- a/example/composeApp/src/commonMain/kotlin/content/examples/DataPassingFreeArgs.kt +++ b/example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/DataPassingFreeArgs.kt @@ -1,6 +1,6 @@ @file:Suppress("MatchingDeclarationName") -package content.examples +package composegears.tiamat.example import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column @@ -14,8 +14,8 @@ import androidx.compose.ui.unit.dp import com.composegears.tiamat.freeArgs import com.composegears.tiamat.navController import com.composegears.tiamat.navDestination -import content.examples.common.BackButton -import content.examples.common.SimpleScreen +import composegears.tiamat.example.ui.core.BackButton +import composegears.tiamat.example.ui.core.SimpleScreen class FreeArgsData diff --git a/example/composeApp/src/commonMain/kotlin/content/examples/DataPassingParams.kt b/example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/DataPassingParams.kt similarity index 91% rename from example/composeApp/src/commonMain/kotlin/content/examples/DataPassingParams.kt rename to example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/DataPassingParams.kt index 34ba4de..b81efcf 100644 --- a/example/composeApp/src/commonMain/kotlin/content/examples/DataPassingParams.kt +++ b/example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/DataPassingParams.kt @@ -1,6 +1,6 @@ @file:Suppress("MatchingDeclarationName") -package content.examples +package composegears.tiamat.example import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column @@ -19,9 +19,9 @@ import androidx.compose.ui.unit.dp import com.composegears.tiamat.navArgsOrNull import com.composegears.tiamat.navController import com.composegears.tiamat.navDestination -import content.examples.common.BackButton -import content.examples.common.CircleButton -import content.examples.common.SimpleScreen +import composegears.tiamat.example.ui.core.BackButton +import composegears.tiamat.example.ui.core.CircleButton +import composegears.tiamat.example.ui.core.SimpleScreen data class NavArgsData(val counter: Int) diff --git a/example/composeApp/src/commonMain/kotlin/content/examples/DataPassingResult.kt b/example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/DataPassingResult.kt similarity index 96% rename from example/composeApp/src/commonMain/kotlin/content/examples/DataPassingResult.kt rename to example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/DataPassingResult.kt index 1906887..d6caed0 100644 --- a/example/composeApp/src/commonMain/kotlin/content/examples/DataPassingResult.kt +++ b/example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/DataPassingResult.kt @@ -1,6 +1,6 @@ @file:Suppress("MatchingDeclarationName") -package content.examples +package composegears.tiamat.example import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column @@ -16,7 +16,7 @@ import androidx.compose.ui.unit.dp import com.composegears.tiamat.navController import com.composegears.tiamat.navDestination import com.composegears.tiamat.navResult -import content.examples.common.* +import composegears.tiamat.example.ui.core.* data class NavResult(val counter: Int) diff --git a/example/composeApp/src/commonMain/kotlin/content/MainScreen.kt b/example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/MainScreen.kt similarity index 89% rename from example/composeApp/src/commonMain/kotlin/content/MainScreen.kt rename to example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/MainScreen.kt index 724c562..6e5f7e4 100644 --- a/example/composeApp/src/commonMain/kotlin/content/MainScreen.kt +++ b/example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/MainScreen.kt @@ -1,4 +1,4 @@ -package content +package composegears.tiamat.example import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.LazyColumn @@ -14,9 +14,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import com.composegears.tiamat.navController import com.composegears.tiamat.navDestination -import content.examples.* -import content.examples.koin.KoinIntegration -import content.examples.multimodule.MultiModuleRoot +import composegears.tiamat.example.multimodule.MultiModuleRoot val MainScreen by navDestination { val navController = navController() @@ -34,8 +32,7 @@ val MainScreen by navDestination { "Multi-module" to { navController.navigate(MultiModuleRoot) }, "Back stack alteration" to { navController.navigate(BackStackAlterationRoot) }, "2 Pane (list + detail, resizable)" to { navController.navigate(TwoPaneResizableRoot) }, - "Koin (ViewModel/SharedViewModel)" to { navController.navigate(KoinIntegration) }, - "Platform specific" to { navController.navigate(PlatformExample) } + "Platform specific" to { navController.navigate(PlatformExamplesScreen) } ) } Box( @@ -43,7 +40,7 @@ val MainScreen by navDestination { contentAlignment = Alignment.Center ) { LazyColumn( - contentPadding = PaddingValues(horizontal = 8.dp), + contentPadding = PaddingValues(24.dp), verticalArrangement = Arrangement.spacedBy(4.dp) ) { items(content) { (name, action) -> diff --git a/example/composeApp/src/commonMain/kotlin/content/examples/NestedNavigation.kt b/example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/NestedNavigation.kt similarity index 95% rename from example/composeApp/src/commonMain/kotlin/content/examples/NestedNavigation.kt rename to example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/NestedNavigation.kt index 8654d4e..a897d71 100644 --- a/example/composeApp/src/commonMain/kotlin/content/examples/NestedNavigation.kt +++ b/example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/NestedNavigation.kt @@ -1,4 +1,4 @@ -package content.examples +package composegears.tiamat.example import androidx.compose.foundation.border import androidx.compose.foundation.layout.Column @@ -10,7 +10,7 @@ import androidx.compose.ui.unit.dp import com.composegears.tiamat.Navigation import com.composegears.tiamat.navDestination import com.composegears.tiamat.rememberNavController -import content.examples.common.SimpleScreen +import composegears.tiamat.example.ui.core.SimpleScreen val NestedNavigationRoot by navDestination { SimpleScreen("Nested navigation") { diff --git a/example/composeApp/src/androidMain/kotlin/content/examples/platform/MainPlatformScreen.kt b/example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/PlatformExamplesScreen.kt similarity index 55% rename from example/composeApp/src/androidMain/kotlin/content/examples/platform/MainPlatformScreen.kt rename to example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/PlatformExamplesScreen.kt index 96b0ae8..f9cef58 100644 --- a/example/composeApp/src/androidMain/kotlin/content/examples/platform/MainPlatformScreen.kt +++ b/example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/PlatformExamplesScreen.kt @@ -1,4 +1,4 @@ -package content.examples.platform +package composegears.tiamat.example import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.PaddingValues @@ -11,36 +11,31 @@ import androidx.compose.material.icons.automirrored.filled.NavigateNext import androidx.compose.material3.Button import androidx.compose.material3.Icon import androidx.compose.material3.Text -import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp +import com.composegears.tiamat.NavDestination import com.composegears.tiamat.navController import com.composegears.tiamat.navDestination -import content.examples.common.SimpleScreen -import content.examples.platform.examples.AndroidViewLifecycleScreen -import content.examples.platform.examples.DeeplinkScreen -import content.examples.platform.examples.SavedStateScreen +import composegears.tiamat.example.ui.core.SimpleScreen +import composegears.tiamat.example.ui.core.TextCaption -val MainPlatformScreen by navDestination { +val PlatformExamplesScreen by navDestination { val navController = navController() - val content = remember { - listOf( - "Android SavedState" to { navController.navigate(SavedStateScreen) }, - "AndroidView + Lifecycle handle" to { navController.navigate(AndroidViewLifecycleScreen) }, - "Deeplink" to { navController.navigate(DeeplinkScreen) } - ) - } - SimpleScreen("Platform samples") { - LazyColumn( - contentPadding = PaddingValues(horizontal = 8.dp), + SimpleScreen("Platform ${platformExamplesConfig.platformName}") { + if (platformExamplesConfig.availableScreens.isEmpty()) { + TextCaption("Nothing platform specific yet") + } else LazyColumn( + contentPadding = PaddingValues(24.dp), verticalArrangement = Arrangement.spacedBy(4.dp) ) { - items(content) { (name, action) -> + items(platformExamplesConfig.availableScreens) { (name, screen) -> Button( modifier = Modifier.widthIn(max = 450.dp), - onClick = action, + onClick = { + navController.navigate(screen) + }, contentPadding = PaddingValues(horizontal = 16.dp, vertical = 8.dp) ) { Row(verticalAlignment = Alignment.CenterVertically) { @@ -51,4 +46,20 @@ val MainPlatformScreen by navDestination { } } } -} \ No newline at end of file +} + +expect val platformExamplesConfig: PlatformConfig + +class PlatformConfig( + val platformName: String, + val availableScreens: List, +) { + data class PlatformDestination( + val name: String, + val destination: NavDestination<*> + ) + + fun destinations() = availableScreens + .map { it.destination } + .toTypedArray() +} diff --git a/example/composeApp/src/commonMain/kotlin/content/examples/SimpleForwardBack.kt b/example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/SimpleForwardBack.kt similarity index 96% rename from example/composeApp/src/commonMain/kotlin/content/examples/SimpleForwardBack.kt rename to example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/SimpleForwardBack.kt index 50c668d..433a972 100644 --- a/example/composeApp/src/commonMain/kotlin/content/examples/SimpleForwardBack.kt +++ b/example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/SimpleForwardBack.kt @@ -1,4 +1,4 @@ -package content.examples +package composegears.tiamat.example import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.padding @@ -10,8 +10,7 @@ import com.composegears.tiamat.NavDestination import com.composegears.tiamat.NavDestinationScope import com.composegears.tiamat.navController import com.composegears.tiamat.navDestination -import content.MainScreen -import content.examples.common.* +import composegears.tiamat.example.ui.core.* @Composable private fun NavDestinationScope<*>.Screen( diff --git a/example/composeApp/src/commonMain/kotlin/content/examples/SimpleReplace.kt b/example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/SimpleReplace.kt similarity index 91% rename from example/composeApp/src/commonMain/kotlin/content/examples/SimpleReplace.kt rename to example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/SimpleReplace.kt index 80a8abe..533abec 100644 --- a/example/composeApp/src/commonMain/kotlin/content/examples/SimpleReplace.kt +++ b/example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/SimpleReplace.kt @@ -1,4 +1,4 @@ -package content.examples +package composegears.tiamat.example import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer @@ -14,10 +14,10 @@ import com.composegears.tiamat.NavDestination import com.composegears.tiamat.NavDestinationScope import com.composegears.tiamat.navController import com.composegears.tiamat.navDestination -import content.examples.common.BackButton -import content.examples.common.NextButton -import content.examples.common.SimpleScreen -import content.examples.common.TextCaption +import composegears.tiamat.example.ui.core.BackButton +import composegears.tiamat.example.ui.core.NextButton +import composegears.tiamat.example.ui.core.SimpleScreen +import composegears.tiamat.example.ui.core.TextCaption @Composable private fun NavDestinationScope<*>.Screen( diff --git a/example/composeApp/src/commonMain/kotlin/content/examples/Tabs.kt b/example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/Tabs.kt similarity index 95% rename from example/composeApp/src/commonMain/kotlin/content/examples/Tabs.kt rename to example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/Tabs.kt index 1ba29b6..b8fe776 100644 --- a/example/composeApp/src/commonMain/kotlin/content/examples/Tabs.kt +++ b/example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/Tabs.kt @@ -1,4 +1,4 @@ -package content.examples +package composegears.tiamat.example import androidx.compose.foundation.layout.* import androidx.compose.material.icons.Icons @@ -15,9 +15,9 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import com.composegears.tiamat.* -import content.examples.common.BackButton -import content.examples.common.NextButton -import content.examples.common.SimpleScreen +import composegears.tiamat.example.ui.core.BackButton +import composegears.tiamat.example.ui.core.NextButton +import composegears.tiamat.example.ui.core.SimpleScreen @Composable private fun Screen( diff --git a/example/composeApp/src/commonMain/kotlin/content/examples/TwoPaneResizableExample.kt b/example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/TwoPaneResizableExample.kt similarity index 94% rename from example/composeApp/src/commonMain/kotlin/content/examples/TwoPaneResizableExample.kt rename to example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/TwoPaneResizableExample.kt index 5613696..a72bd23 100644 --- a/example/composeApp/src/commonMain/kotlin/content/examples/TwoPaneResizableExample.kt +++ b/example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/TwoPaneResizableExample.kt @@ -1,4 +1,4 @@ -package content.examples +package composegears.tiamat.example import androidx.compose.animation.AnimatedContent import androidx.compose.foundation.layout.* @@ -11,10 +11,10 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import com.composegears.tiamat.* -import content.examples.common.BackButton -import content.examples.common.NextButton -import content.examples.common.SimpleScreen -import content.examples.common.TextButton +import composegears.tiamat.example.ui.core.BackButton +import composegears.tiamat.example.ui.core.NextButton +import composegears.tiamat.example.ui.core.SimpleScreen +import composegears.tiamat.example.ui.core.TextButton data class MasterItem( val name: String diff --git a/example/composeApp/src/commonMain/kotlin/content/examples/ViewModels.kt b/example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/ViewModels.kt similarity index 98% rename from example/composeApp/src/commonMain/kotlin/content/examples/ViewModels.kt rename to example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/ViewModels.kt index 4fa2cde..e8c2ae7 100644 --- a/example/composeApp/src/commonMain/kotlin/content/examples/ViewModels.kt +++ b/example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/ViewModels.kt @@ -1,4 +1,4 @@ -package content.examples +package composegears.tiamat.example import androidx.compose.foundation.layout.* import androidx.compose.material3.MaterialTheme @@ -9,7 +9,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import com.composegears.tiamat.* -import content.examples.common.* +import composegears.tiamat.example.ui.core.* import kotlinx.coroutines.delay import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow diff --git a/example/composeApp/src/commonMain/kotlin/content/examples/multimodule/BaseModule.kt b/example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/multimodule/BaseModule.kt similarity index 96% rename from example/composeApp/src/commonMain/kotlin/content/examples/multimodule/BaseModule.kt rename to example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/multimodule/BaseModule.kt index d7f20b6..95f4c97 100644 --- a/example/composeApp/src/commonMain/kotlin/content/examples/multimodule/BaseModule.kt +++ b/example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/multimodule/BaseModule.kt @@ -1,4 +1,4 @@ -package content.examples.multimodule +package composegears.tiamat.example.multimodule import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect diff --git a/example/composeApp/src/commonMain/kotlin/content/examples/multimodule/Feature1.kt b/example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/multimodule/Feature1.kt similarity index 88% rename from example/composeApp/src/commonMain/kotlin/content/examples/multimodule/Feature1.kt rename to example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/multimodule/Feature1.kt index 5da6d5e..f79640b 100644 --- a/example/composeApp/src/commonMain/kotlin/content/examples/multimodule/Feature1.kt +++ b/example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/multimodule/Feature1.kt @@ -1,4 +1,4 @@ -package content.examples.multimodule +package composegears.tiamat.example.multimodule import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column @@ -8,7 +8,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import com.composegears.tiamat.navController import com.composegears.tiamat.navDestination -import content.examples.common.NextButton +import composegears.tiamat.example.ui.core.NextButton // Feature1 know about Feature2 diff --git a/example/composeApp/src/commonMain/kotlin/content/examples/multimodule/Feature2.kt b/example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/multimodule/Feature2.kt similarity index 91% rename from example/composeApp/src/commonMain/kotlin/content/examples/multimodule/Feature2.kt rename to example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/multimodule/Feature2.kt index c95060c..dbb6f37 100644 --- a/example/composeApp/src/commonMain/kotlin/content/examples/multimodule/Feature2.kt +++ b/example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/multimodule/Feature2.kt @@ -1,4 +1,4 @@ -package content.examples.multimodule +package composegears.tiamat.example.multimodule import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column @@ -7,7 +7,7 @@ import androidx.compose.material3.Text import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import com.composegears.tiamat.navDestination -import content.examples.common.TextButton +import composegears.tiamat.example.ui.core.TextButton import kotlin.random.Random // Feature2 only know about BaseModule diff --git a/example/composeApp/src/commonMain/kotlin/content/examples/multimodule/Root.kt b/example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/multimodule/Root.kt similarity index 95% rename from example/composeApp/src/commonMain/kotlin/content/examples/multimodule/Root.kt rename to example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/multimodule/Root.kt index eed2ebd..8106a31 100644 --- a/example/composeApp/src/commonMain/kotlin/content/examples/multimodule/Root.kt +++ b/example/app/composeApp/src/commonMain/kotlin/composegears/tiamat/example/multimodule/Root.kt @@ -1,4 +1,4 @@ -package content.examples.multimodule +package composegears.tiamat.example.multimodule import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize @@ -17,7 +17,7 @@ import com.composegears.tiamat.Navigation import com.composegears.tiamat.navController import com.composegears.tiamat.navDestination import com.composegears.tiamat.rememberNavController -import content.examples.common.SimpleScreen +import composegears.tiamat.example.ui.core.SimpleScreen // Root - knows about Feature1 and Feature2 // Feature1 - knows about Feature2. diff --git a/example/app/composeApp/src/desktopMain/kotlin/composegears/tiamat/example/PlatformExamplesScreen.desktop.kt b/example/app/composeApp/src/desktopMain/kotlin/composegears/tiamat/example/PlatformExamplesScreen.desktop.kt new file mode 100644 index 0000000..32690b8 --- /dev/null +++ b/example/app/composeApp/src/desktopMain/kotlin/composegears/tiamat/example/PlatformExamplesScreen.desktop.kt @@ -0,0 +1,14 @@ +package composegears.tiamat.example + +import composegears.tiamat.example.PlatformConfig.PlatformDestination +import composegears.tiamat.sample.koin.KoinIntegrationScreen + +actual val platformExamplesConfig = PlatformConfig( + platformName = "Desktop", + availableScreens = listOf( + PlatformDestination( + name = "Koin (ViewModel/SharedViewModel)", + destination = KoinIntegrationScreen + ) + ) +) \ No newline at end of file diff --git a/example/composeApp/src/desktopMain/kotlin/main.kt b/example/app/composeApp/src/desktopMain/kotlin/composegears/tiamat/example/main.kt similarity index 88% rename from example/composeApp/src/desktopMain/kotlin/main.kt rename to example/app/composeApp/src/desktopMain/kotlin/composegears/tiamat/example/main.kt index e453b48..363c815 100644 --- a/example/composeApp/src/desktopMain/kotlin/main.kt +++ b/example/app/composeApp/src/desktopMain/kotlin/composegears/tiamat/example/main.kt @@ -1,3 +1,7 @@ +@file:Suppress("Filename") + +package composegears.tiamat.example + import androidx.compose.desktop.ui.tooling.preview.Preview import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment @@ -9,7 +13,7 @@ import androidx.compose.ui.unit.DpSize import androidx.compose.ui.unit.dp import androidx.compose.ui.window.* import com.composegears.tiamat.LocalNavBackHandler -import content.examples.koin.KoinLib +import composegears.tiamat.sample.koin.KoinLib fun main() { KoinLib.start() @@ -35,6 +39,6 @@ fun main() { @Preview @Composable -fun AppDesktopPreview() { +private fun AppDesktopPreview() { App() } \ No newline at end of file diff --git a/example/composeApp/src/iosMain/kotlin/MainViewController.kt b/example/app/composeApp/src/iosMain/kotlin/composegears/tiamat/example/MainViewController.kt similarity index 73% rename from example/composeApp/src/iosMain/kotlin/MainViewController.kt rename to example/app/composeApp/src/iosMain/kotlin/composegears/tiamat/example/MainViewController.kt index cc0afb9..7342413 100644 --- a/example/composeApp/src/iosMain/kotlin/MainViewController.kt +++ b/example/app/composeApp/src/iosMain/kotlin/composegears/tiamat/example/MainViewController.kt @@ -1,4 +1,4 @@ -@file:Suppress("MissingPackageDeclaration") +package composegears.tiamat.example import androidx.compose.ui.window.ComposeUIViewController diff --git a/example/app/composeApp/src/iosMain/kotlin/composegears/tiamat/example/PlatformExamplesScreen.ios.kt b/example/app/composeApp/src/iosMain/kotlin/composegears/tiamat/example/PlatformExamplesScreen.ios.kt new file mode 100644 index 0000000..8c4c012 --- /dev/null +++ b/example/app/composeApp/src/iosMain/kotlin/composegears/tiamat/example/PlatformExamplesScreen.ios.kt @@ -0,0 +1,13 @@ +package composegears.tiamat.example + +import composegears.tiamat.sample.koin.KoinIntegrationScreen + +actual val platformExamplesConfig = PlatformConfig( + platformName = "iOS", + availableScreens = listOf( + PlatformConfig.PlatformDestination( + name = "Koin (ViewModel/SharedViewModel)", + destination = KoinIntegrationScreen + ) + ) +) \ No newline at end of file diff --git a/example/app/composeApp/src/wasmJsMain/kotlin/composegears/tiamat/example/PlatformExamplesScreen.wasmJs.kt b/example/app/composeApp/src/wasmJsMain/kotlin/composegears/tiamat/example/PlatformExamplesScreen.wasmJs.kt new file mode 100644 index 0000000..6a9290e --- /dev/null +++ b/example/app/composeApp/src/wasmJsMain/kotlin/composegears/tiamat/example/PlatformExamplesScreen.wasmJs.kt @@ -0,0 +1,6 @@ +package composegears.tiamat.example + +actual val platformExamplesConfig = PlatformConfig( + platformName = "Wasm", + availableScreens = emptyList() +) \ No newline at end of file diff --git a/example/app/composeApp/src/wasmJsMain/kotlin/composegears/tiamat/example/main.kt b/example/app/composeApp/src/wasmJsMain/kotlin/composegears/tiamat/example/main.kt new file mode 100644 index 0000000..fd047ce --- /dev/null +++ b/example/app/composeApp/src/wasmJsMain/kotlin/composegears/tiamat/example/main.kt @@ -0,0 +1,37 @@ +@file:Suppress("Filename") + +package composegears.tiamat.example + +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.Text +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.ui.Alignment +import androidx.compose.ui.ExperimentalComposeUiApi +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import androidx.compose.ui.window.CanvasBasedWindow + +external fun onLoadFinished() + +@OptIn(ExperimentalComposeUiApi::class) +fun main() { + CanvasBasedWindow(canvasElementId = "TiamatTarget") { + LaunchedEffect(Unit) { + onLoadFinished() + } + Box { + App() + Text( + modifier = Modifier.align(Alignment.BottomEnd).padding(16.dp), + color = Color.White, + fontSize = 20.sp, + fontWeight = FontWeight.Bold, + text = "Pre Alpha (Wasm)", + ) + } + } +} \ No newline at end of file diff --git a/example/app/composeApp/src/wasmJsMain/resources/app.js b/example/app/composeApp/src/wasmJsMain/resources/app.js new file mode 100644 index 0000000..5e11ed3 --- /dev/null +++ b/example/app/composeApp/src/wasmJsMain/resources/app.js @@ -0,0 +1,7 @@ +function onLoadFinished() { + document.dispatchEvent(new Event("app-loaded")); +} + +document.addEventListener("app-loaded", function() { + document.getElementById("spinner").style.display = "none"; +}); \ No newline at end of file diff --git a/example/app/composeApp/src/wasmJsMain/resources/images/tiamat.png b/example/app/composeApp/src/wasmJsMain/resources/images/tiamat.png new file mode 100644 index 0000000000000000000000000000000000000000..029f7fcef5a1c3c6cc7a7ad620443951e0c9c9dc GIT binary patch literal 5277 zcmc&&4LHzP2sJ79q-aE47KR((FM++r5 zLv3c$KBti^MZ!VCj2;!997;Fom1(abA1Q@x!n*&f!Fd zP+Fy5ffF3==4Yr(-m+y)(0aQVZI_Lj=^e_=hpVYWE_<>wL_#i-XrRM8>2IeC!)X+c z5CUoUig)wTnJ22AmM7X*x_MXg-U%RGvUtI_9_(cFGKwi;)J8gWDQBhFvxWx|OMkqO8PY3Z~1mf^0PS zuDKOyrI8b)CwN7V6>CzHli8+~txD@apu6&!uNK%wKa@=j59QFN(=kR^-ZcrE=1#2_ z?-B@fN48FWP$<>}u}IKS1f(y>6#wJe4m1|?13~u7un~a&Ff7k#e$pq04G!k$SVt65 z8dFw-q5Rwstt%#iC-DP|rY0uX;iY9z++vxLZMfLq8ctyl`_Cpi8C3?w_i8qOd5qAt?g*k@l8zQc*!E$YlYS%~?3klf<=J+M!cU>1ee! z!d3Tx6Qv`*L(61r?U7z(h@M_y{7xn^l%~V?&7`CbzsZc10dA~9bTXM3B(`R`3IU#U zsG6Ee#FR3%*Q^C@n_(_dHabas&GPSieK9b+eIuvaX+r3CL?~$^tgiLeoX*6wI`i$G z%E^QLfqe98rhM%JqV{DM!0$N4=nNJS3hCCh)OzT#0Ezr6sBV@c3XTa_Cky1<=mY0 zT}8Ly;@Qm&Fr53Q9JmI6oas5Ram=jfY_h&Ns=rwV^pJ}?#Dh=8Q5RD00~_^IN?O8) z%!(utrQaFg<=>8~^~&Sm>sEsaYC>)zmig}8ZaGOX@r_AM_>RooNWaa%*?J2{D3zxI z;**Tmfya5HKqf9`L9A~GJ!ra+4a}6rWJ1-}fSzs*+(_1W@QdpTgNfa^II0FtH5LXg z`MO6a*HhcpK*P(saa`=MG32+~Tv&;UKyMvH+d6kc8`ucf1E2-P0T=+%0N6kyC`Kp( zfP+S>{@ts;Nd9?~KgIns`TvsXZ^^mBNuplyuYTTV0sb5E{&_QemUBf>|JG{%m;AG> zrGf1q_`&1QgiX8irPC05i62YUqh8!U8t|ca5W}vPTm?exati{AYR;@U&ng_iU&+R@ zVoGz8m5wiy`?VmouQc4JhU=_;TiVtpBGjC1j1Q_yVj-A&RU=<+_m#Jvv$m9yhQ#mj z|BV*FAicvNo}Zc)X>UJGe!C^MMpGPBMwaEzkQhE7o>$V>J4l#9can$KcID$i}i&IM~Q6G6RvTc}6Iu2FdS=MFR ze#?ySF*)mj^L5w^|3gvQkW(a0LRu{z-CO_gXi5qkAq=2Hzx%FA%<%E7x26jYALqW8 znkEZ^`UB(S#xk&!p<-5xeo$Ruc?q-6y~5wkP&8ioaJ?})T1`~eX{8e$IQ9DSm89vq zg)~yNlamtks|!v?Dh{|8UeR*h-UfjDRqJ_ayO9kV0_S4>8 zp6TlzcFxt|jG{6~3@y;A;oXOhCD4vcVV&ccqw;Dcy=R`pot{+hm+d+Uu5IH$mw|1p zJoEkf`EI}VzW1@>!p4LYPA8=}#K6;|QsrFagfA~!f$Ecx_%OBW5)YyhkevO=klHt)6L^Kro+%p*JogBB|28b9$EEqU2z+32wTwmk zl82>n=ph^rUR8?lqf}ap*jGyjWs_YTe`9-k)6H6iv}U=yhL~V_LnN2ARls8y(b_-W z2Ky(unsd@+vr zLWNkxP=n13jXEKDFT|alXQ`8+sYAm>*kGsMHBf$G%TU+bW!b|zPL@1uiC5AdNDRMhc4z~rJMf$9PV5=K06*PLOqe}k3${XWY-kH$oC&>>CV}7ZPVbYg zduMs-p~ug4X52=`ZwI=5zpCPmH_N7saV9d5z#uD(8g}x6T%#(yZL{ zw?5o-IUp`+$dVPQvlb_lUGyp9E%r4iSeHJR>)z(7>3H0s$XMkvqH=uiwZ!Y-@#`fS zDBwxsZp~aZD=aM5wqmDtn=Nl%W#dcx)xN2(1%u2Ae&1mYv~!+DG0J_FVizFqJMW(fb%b@v!JMyiuDnft z;)}q(dSyKq84qv~GC0xTI{!D>y4lT&#Pj+2X43 zc{y@M_Y!N{rG_KDMB%;;$u&B0H_g7NW;JErvP;;s^c7Aw12scGre6_ZUgk&Jqpny* z!wAymrLRSARye>d_G#}+ND+s>XVG^hehSgsV2aCA3n?a~IsCdX_Z0e-yGZLx0D_>_6oT@H8 zt#+-rhTm*my+_r;=k5n^q9uy4X)Gbv>5F@NN7ECn?w}P%psPb@wGH6!#L#jm7hk_> z8FjKquO*|sO8sBu`z+0kI};w*9@;mfZhzr|Xf@$j(&U_8 z)9ste`zPLeA5$@&tJMa7kPARUZiZkafcn3bFG31fS@k*P(E7t&ek1?9$zLSLLEL}M zhCZ|SJoo>&|EpL3Y7PqBf8rBhp3=~9`y(a(fdDqp!audkKPP)QXyHH4{W(s*n&xk8 z{I}#>k!cl98%p&4lk)1Cfs>n|1oHNnHuxX7<6wda>o)*+V(s1Q7h_ac@Q|04}^2d@Jmz~uyUt~IihF5ce@5o3()Vq}dRs~4pk0FE>uX`rhFRVG$oRk@T_ zj%I4hxw6a^^pzYkn6tL60s#C?BCPmat{7c*6~cQz$uPvb0X-V_3F1B1l(M0mokhs4 z0{&-?d3$rljRK0e;;2qffPd7{UO;&eXwZ;bEF~)Ieu{nL7xYJ)`58>x^EBLuJgeFQe zQvaSMl!%tZ`D1v9sxP}=zA8dcu=bS2eUhti`Nl;~IR`U+&C2LbYc09}3@Zae%)qz5|(bnEWh#XIlmsi`T}ux!`KlJAy7BBW@lhTuf13f+6&DziUT zFRe`&xxccj7=}0OT$rADB_b)ps=4wiYG#0&zuob|sdnyL|8`}{o#ENRSOriwGKt)( z(7|o;ZyzTVw5^u3QAil~D~tL1ktsZkseQ!&JL>~%lJ2H-%ulC0xu$&6A|zf5Ao;FB zs%m(;z55`FB4pYvQ4g@A1@%g+Rw^#LG?Qc*Z(B}Gw7%m+K2qR1I&A_W-On*gBjj}d z?-COm3kj#Z;&tQz$>-vtGufe{P+?)sMg(t_giTz#BZ8OIdV(|2?bmgVZF(`>|F+IX zFi>vT+MM=inkV*tbn@gPa)b_BSG{<}$p931+nH!4p}yKk&Uo^Q$J!O$Si&}~=~0rm z$@0i1nbbY%R59X}u2jyFG2PA87yx)XS{q%#Uf+kxVfo#)+|RB}_4 z_&FOWIJKR3h;aWUi_NsY7r`gkgq4NNT+=iL5fivNg-Xj{`@siMtoy}*_C>MgW + + + Tiamat Wasm + + + + + + + + + + + + + + + +
+
+ + +
+ + \ No newline at end of file diff --git a/example/app/composeApp/src/wasmJsMain/resources/manifest.json b/example/app/composeApp/src/wasmJsMain/resources/manifest.json new file mode 100644 index 0000000..0d41b99 --- /dev/null +++ b/example/app/composeApp/src/wasmJsMain/resources/manifest.json @@ -0,0 +1,13 @@ +{ + "name": "Tiamat Wasm", + "icons": [ + { + "src": "images/tiamat.png", + "type": "image/png", + "sizes": "512x512" + } + ], + "start_url": "/Tiamat", + "display": "standalone", + "background_color": "white" +} \ No newline at end of file diff --git a/example/app/composeApp/src/wasmJsMain/resources/style.css b/example/app/composeApp/src/wasmJsMain/resources/style.css new file mode 100644 index 0000000..0cbd0b2 --- /dev/null +++ b/example/app/composeApp/src/wasmJsMain/resources/style.css @@ -0,0 +1,51 @@ +#TiamatTarget { + width: 100vw; + height: 100vh; +} + +body { + background-color: #2b2d30; + margin: 0; + padding: 0; + width: 100vw; + height: 100vh; + display: flex; + justify-content: center; + align-items: center; +} + +#warning { + color: #fff; + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + text-align: center; +} + +.spinner { + margin: auto; + left:0; + right:0; + top:0; + bottom:0; + position: fixed; + width: 48px; + height: 48px; + border: 5px solid #dfe1e5; + border-bottom-color: #375fad; + border-radius: 50%; + display: inline-block; + box-sizing: border-box; + animation: rotation 1s linear infinite; + z-index: 1; +} + +@keyframes rotation { + 0% { + transform: rotate(0deg); + } + 100% { + transform: rotate(360deg); + } +} \ No newline at end of file diff --git a/example/app/composeApp/src/wasmJsMain/resources/unsupported_browser.js b/example/app/composeApp/src/wasmJsMain/resources/unsupported_browser.js new file mode 100644 index 0000000..c9905f6 --- /dev/null +++ b/example/app/composeApp/src/wasmJsMain/resources/unsupported_browser.js @@ -0,0 +1,16 @@ +const unhandledError = (event, error) => { + if (error instanceof WebAssembly.CompileError) { + document.getElementById("warning").style.display = "initial"; + + // Hide Webpack Overlay + const webpackOverlay = document.getElementById("webpack-dev-server-client-overlay"); + if (webpackOverlay != null) { + webpackOverlay.style.display = "none"; + } + + document.getElementById("spinner").style.display = "none"; + document.getElementById("TiamatTarget").style.display = "none"; + } +} +addEventListener("error", (event) => unhandledError(event, event.error)); +addEventListener("unhandledrejection", (event) => unhandledError(event, event.reason)); \ No newline at end of file diff --git a/example/iosApp/Configuration/Config.xcconfig b/example/app/iosApp/Configuration/Config.xcconfig similarity index 100% rename from example/iosApp/Configuration/Config.xcconfig rename to example/app/iosApp/Configuration/Config.xcconfig diff --git a/example/iosApp/iosApp.xcodeproj/project.pbxproj b/example/app/iosApp/iosApp.xcodeproj/project.pbxproj similarity index 99% rename from example/iosApp/iosApp.xcodeproj/project.pbxproj rename to example/app/iosApp/iosApp.xcodeproj/project.pbxproj index 821b1a0..877326a 100644 --- a/example/iosApp/iosApp.xcodeproj/project.pbxproj +++ b/example/app/iosApp/iosApp.xcodeproj/project.pbxproj @@ -159,7 +159,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 :example: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 :example:app:composeApp:embedAndSignAppleFrameworkForXcode\n"; }; /* End PBXShellScriptBuildPhase section */ diff --git a/example/iosApp/iosApp/Assets.xcassets/AccentColor.colorset/Contents.json b/example/app/iosApp/iosApp/Assets.xcassets/AccentColor.colorset/Contents.json similarity index 100% rename from example/iosApp/iosApp/Assets.xcassets/AccentColor.colorset/Contents.json rename to example/app/iosApp/iosApp/Assets.xcassets/AccentColor.colorset/Contents.json diff --git a/example/iosApp/iosApp/Assets.xcassets/AppIcon.appiconset/Contents.json b/example/app/iosApp/iosApp/Assets.xcassets/AppIcon.appiconset/Contents.json similarity index 100% rename from example/iosApp/iosApp/Assets.xcassets/AppIcon.appiconset/Contents.json rename to example/app/iosApp/iosApp/Assets.xcassets/AppIcon.appiconset/Contents.json diff --git a/example/iosApp/iosApp/Assets.xcassets/AppIcon.appiconset/app-icon-1024.png b/example/app/iosApp/iosApp/Assets.xcassets/AppIcon.appiconset/app-icon-1024.png similarity index 100% rename from example/iosApp/iosApp/Assets.xcassets/AppIcon.appiconset/app-icon-1024.png rename to example/app/iosApp/iosApp/Assets.xcassets/AppIcon.appiconset/app-icon-1024.png diff --git a/example/iosApp/iosApp/Assets.xcassets/Contents.json b/example/app/iosApp/iosApp/Assets.xcassets/Contents.json similarity index 100% rename from example/iosApp/iosApp/Assets.xcassets/Contents.json rename to example/app/iosApp/iosApp/Assets.xcassets/Contents.json diff --git a/example/iosApp/iosApp/ContentView.swift b/example/app/iosApp/iosApp/ContentView.swift similarity index 100% rename from example/iosApp/iosApp/ContentView.swift rename to example/app/iosApp/iosApp/ContentView.swift diff --git a/example/iosApp/iosApp/Info.plist b/example/app/iosApp/iosApp/Info.plist similarity index 100% rename from example/iosApp/iosApp/Info.plist rename to example/app/iosApp/iosApp/Info.plist diff --git a/example/iosApp/iosApp/Preview Content/Preview Assets.xcassets/Contents.json b/example/app/iosApp/iosApp/Preview Content/Preview Assets.xcassets/Contents.json similarity index 100% rename from example/iosApp/iosApp/Preview Content/Preview Assets.xcassets/Contents.json rename to example/app/iosApp/iosApp/Preview Content/Preview Assets.xcassets/Contents.json diff --git a/example/iosApp/iosApp/iOSApp.swift b/example/app/iosApp/iosApp/iOSApp.swift similarity index 100% rename from example/iosApp/iosApp/iOSApp.swift rename to example/app/iosApp/iosApp/iOSApp.swift diff --git a/example/composeApp/src/androidMain/kotlin/content/examples/PlatformExample.android.kt b/example/composeApp/src/androidMain/kotlin/content/examples/PlatformExample.android.kt deleted file mode 100644 index 4a79aec..0000000 --- a/example/composeApp/src/androidMain/kotlin/content/examples/PlatformExample.android.kt +++ /dev/null @@ -1,43 +0,0 @@ -package content.examples - -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.ui.Modifier -import com.composegear.navigation.DeeplinkData -import com.composegears.tiamat.* -import content.examples.platform.MainPlatformScreen -import content.examples.platform.examples.AndroidViewLifecycleScreen -import content.examples.platform.examples.DeeplinkScreen -import content.examples.platform.examples.SavedStateScreen - -actual val PlatformExample: NavDestination by navDestination { - val deeplink = freeArgs() - - val platformNavController = rememberNavController( - key = "platformNavController", - startDestination = MainPlatformScreen, - destinations = arrayOf( - MainPlatformScreen, - SavedStateScreen, - AndroidViewLifecycleScreen, - DeeplinkScreen - ) - ) { - if (deeplink != null) { - editBackStack { - clear() - add(MainPlatformScreen) - } - replace( - dest = DeeplinkScreen, - freeArgs = deeplink, - transition = navigationNone() - ) - clearFreeArgs() - } - } - - Navigation( - navController = platformNavController, - modifier = Modifier.fillMaxSize() - ) -} \ No newline at end of file diff --git a/example/composeApp/src/commonMain/kotlin/content/examples/PlatformExample.kt b/example/composeApp/src/commonMain/kotlin/content/examples/PlatformExample.kt deleted file mode 100644 index 049cde2..0000000 --- a/example/composeApp/src/commonMain/kotlin/content/examples/PlatformExample.kt +++ /dev/null @@ -1,5 +0,0 @@ -package content.examples - -import com.composegears.tiamat.NavDestination - -expect val PlatformExample: NavDestination \ No newline at end of file diff --git a/example/composeApp/src/desktopMain/kotlin/content/examples/PlatformExample.desktop.kt b/example/composeApp/src/desktopMain/kotlin/content/examples/PlatformExample.desktop.kt deleted file mode 100644 index 8ea2860..0000000 --- a/example/composeApp/src/desktopMain/kotlin/content/examples/PlatformExample.desktop.kt +++ /dev/null @@ -1,12 +0,0 @@ -package content.examples - -import com.composegears.tiamat.NavDestination -import com.composegears.tiamat.navDestination -import content.examples.common.SimpleScreen -import content.examples.common.TextCaption - -actual val PlatformExample: NavDestination by navDestination { - SimpleScreen("Platform Desktop") { - TextCaption("Nothing platform specific yet") - } -} \ No newline at end of file diff --git a/example/composeApp/src/iosMain/kotlin/content/examples/PlatformExample.ios.kt b/example/composeApp/src/iosMain/kotlin/content/examples/PlatformExample.ios.kt deleted file mode 100644 index 4a80df5..0000000 --- a/example/composeApp/src/iosMain/kotlin/content/examples/PlatformExample.ios.kt +++ /dev/null @@ -1,12 +0,0 @@ -package content.examples - -import com.composegears.tiamat.NavDestination -import com.composegears.tiamat.navDestination -import content.examples.common.SimpleScreen -import content.examples.common.TextCaption - -actual val PlatformExample: NavDestination by navDestination { - SimpleScreen("Platform iOS") { - TextCaption("Nothing platform specific yet") - } -} \ No newline at end of file diff --git a/example/sample-koin/build.gradle.kts b/example/sample-koin/build.gradle.kts new file mode 100644 index 0000000..67f4556 --- /dev/null +++ b/example/sample-koin/build.gradle.kts @@ -0,0 +1,38 @@ +import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi +import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl + +plugins { + alias(libs.plugins.kotlin.multiplatform) + alias(libs.plugins.android.library) + alias(libs.plugins.compose.compiler) + alias(libs.plugins.jetbrains.compose) +} + +android { + namespace = "composegears.tiamat.sample.koin" + compileSdk = libs.versions.android.compileSdk.get().toInt() +} + +kotlin { + jvm() + androidTarget { + @OptIn(ExperimentalKotlinGradlePluginApi::class) + compilerOptions { + jvmTarget = JvmTarget.JVM_1_8 + } + } + iosX64() + iosArm64() + iosSimulatorArm64() + + sourceSets { + commonMain.dependencies { + implementation(projects.tiamat) + implementation(projects.tiamatKoin) + implementation(projects.example.uiCore) + + implementation(libs.koin.compose) + } + } +} \ No newline at end of file diff --git a/example/composeApp/src/commonMain/kotlin/content/examples/koin/KoinIntegration.kt b/example/sample-koin/src/commonMain/kotlin/composegears/tiamat/sample/koin/KoinIntegrationScreen.kt similarity index 72% rename from example/composeApp/src/commonMain/kotlin/content/examples/koin/KoinIntegration.kt rename to example/sample-koin/src/commonMain/kotlin/composegears/tiamat/sample/koin/KoinIntegrationScreen.kt index 637440b..ba777de 100644 --- a/example/composeApp/src/commonMain/kotlin/content/examples/koin/KoinIntegration.kt +++ b/example/sample-koin/src/commonMain/kotlin/composegears/tiamat/sample/koin/KoinIntegrationScreen.kt @@ -1,4 +1,4 @@ -package content.examples.koin +package composegears.tiamat.sample.koin import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column @@ -12,18 +12,14 @@ import androidx.compose.ui.unit.dp import com.composegears.tiamat.* import com.composegears.tiamat.koin.koinSharedTiamatViewModel import com.composegears.tiamat.koin.koinTiamatViewModel -import content.examples.SharedViewModel -import content.examples.common.* -import content.examples.koin.KoinDetailViewModel.Companion.KoinDetailState.Loading -import content.examples.koin.KoinDetailViewModel.Companion.KoinDetailState.Success -import kotlinx.coroutines.delay -import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.asStateFlow -import kotlinx.coroutines.flow.update -import kotlinx.coroutines.launch +import composegears.tiamat.example.ui.core.* +import composegears.tiamat.sample.koin.viewmodel.KoinDetailViewModel +import composegears.tiamat.sample.koin.viewmodel.KoinDetailViewModel.Companion.KoinDetailState.Loading +import composegears.tiamat.sample.koin.viewmodel.KoinDetailViewModel.Companion.KoinDetailState.Success +import composegears.tiamat.sample.koin.viewmodel.SharedViewModel import org.koin.core.parameter.parametersOf -val KoinIntegration by navDestination { +val KoinIntegrationScreen by navDestination { val navController = rememberNavController( key = "KoinNavController", startDestination = KoinListScreen, @@ -87,25 +83,3 @@ private val KoinDetailScreen by navDestination { } } } - -internal class KoinDetailViewModel(private val params: String) : TiamatViewModel() { - - companion object { - internal sealed interface KoinDetailState { - data object Loading : KoinDetailState - data class Success(val result: String) : KoinDetailState - } - } - - private val _state = MutableStateFlow(Loading) - val state = _state.asStateFlow() - - init { - viewModelScope.launch { - delay(500) - - val result = "$params: ${hashCode()}" - _state.update { Success(result) } - } - } -} \ No newline at end of file diff --git a/example/composeApp/src/commonMain/kotlin/content/examples/koin/KoinLib.kt b/example/sample-koin/src/commonMain/kotlin/composegears/tiamat/sample/koin/KoinLib.kt similarity index 79% rename from example/composeApp/src/commonMain/kotlin/content/examples/koin/KoinLib.kt rename to example/sample-koin/src/commonMain/kotlin/composegears/tiamat/sample/koin/KoinLib.kt index 7a0332d..8940e01 100644 --- a/example/composeApp/src/commonMain/kotlin/content/examples/koin/KoinLib.kt +++ b/example/sample-koin/src/commonMain/kotlin/composegears/tiamat/sample/koin/KoinLib.kt @@ -1,4 +1,4 @@ -package content.examples.koin +package composegears.tiamat.sample.koin import org.koin.core.context.startKoin diff --git a/example/composeApp/src/commonMain/kotlin/content/examples/koin/KoinModule.kt b/example/sample-koin/src/commonMain/kotlin/composegears/tiamat/sample/koin/KoinModule.kt similarity index 67% rename from example/composeApp/src/commonMain/kotlin/content/examples/koin/KoinModule.kt rename to example/sample-koin/src/commonMain/kotlin/composegears/tiamat/sample/koin/KoinModule.kt index 562cddc..e7018c7 100644 --- a/example/composeApp/src/commonMain/kotlin/content/examples/koin/KoinModule.kt +++ b/example/sample-koin/src/commonMain/kotlin/composegears/tiamat/sample/koin/KoinModule.kt @@ -1,7 +1,8 @@ -package content.examples.koin +package composegears.tiamat.sample.koin import com.composegears.tiamat.koin.tiamatViewModelOf -import content.examples.SharedViewModel +import composegears.tiamat.sample.koin.viewmodel.KoinDetailViewModel +import composegears.tiamat.sample.koin.viewmodel.SharedViewModel import org.koin.dsl.module val koinIntegrationModule = module { diff --git a/example/sample-koin/src/commonMain/kotlin/composegears/tiamat/sample/koin/viewmodel/KoinDetailViewModel.kt b/example/sample-koin/src/commonMain/kotlin/composegears/tiamat/sample/koin/viewmodel/KoinDetailViewModel.kt new file mode 100644 index 0000000..6f7d6e0 --- /dev/null +++ b/example/sample-koin/src/commonMain/kotlin/composegears/tiamat/sample/koin/viewmodel/KoinDetailViewModel.kt @@ -0,0 +1,32 @@ +package composegears.tiamat.sample.koin.viewmodel + +import com.composegears.tiamat.TiamatViewModel +import composegears.tiamat.sample.koin.viewmodel.KoinDetailViewModel.Companion.KoinDetailState.Loading +import composegears.tiamat.sample.koin.viewmodel.KoinDetailViewModel.Companion.KoinDetailState.Success +import kotlinx.coroutines.delay +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.update +import kotlinx.coroutines.launch + +internal class KoinDetailViewModel(private val params: String) : TiamatViewModel() { + + companion object { + internal sealed interface KoinDetailState { + data object Loading : KoinDetailState + data class Success(val result: String) : KoinDetailState + } + } + + private val _state = MutableStateFlow(Loading) + val state = _state.asStateFlow() + + init { + viewModelScope.launch { + delay(500) + + val result = "$params: ${hashCode()}" + _state.update { Success(result) } + } + } +} \ No newline at end of file diff --git a/example/sample-koin/src/commonMain/kotlin/composegears/tiamat/sample/koin/viewmodel/SharedViewModel.kt b/example/sample-koin/src/commonMain/kotlin/composegears/tiamat/sample/koin/viewmodel/SharedViewModel.kt new file mode 100644 index 0000000..4d9c6ae --- /dev/null +++ b/example/sample-koin/src/commonMain/kotlin/composegears/tiamat/sample/koin/viewmodel/SharedViewModel.kt @@ -0,0 +1,22 @@ +package composegears.tiamat.sample.koin.viewmodel + +import com.composegears.tiamat.TiamatViewModel +import kotlinx.coroutines.delay +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.isActive +import kotlinx.coroutines.launch + +internal class SharedViewModel : TiamatViewModel() { + private val _timer = MutableStateFlow(0) + val timer = _timer.asStateFlow() + + init { + viewModelScope.launch { + while (isActive) { + _timer.value++ + delay(1000) + } + } + } +} \ No newline at end of file diff --git a/example/ui-core/build.gradle.kts b/example/ui-core/build.gradle.kts new file mode 100644 index 0000000..8eb2b33 --- /dev/null +++ b/example/ui-core/build.gradle.kts @@ -0,0 +1,46 @@ +import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi +import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl + +plugins { + alias(libs.plugins.kotlin.multiplatform) + alias(libs.plugins.android.library) + alias(libs.plugins.compose.compiler) + alias(libs.plugins.jetbrains.compose) +} + +android { + namespace = "composegears.tiamat.example.ui.core" + compileSdk = libs.versions.android.compileSdk.get().toInt() +} + +kotlin { + jvm() + androidTarget { + @OptIn(ExperimentalKotlinGradlePluginApi::class) + compilerOptions { + jvmTarget = JvmTarget.JVM_1_8 + } + } + iosX64() + iosArm64() + iosSimulatorArm64() + + @OptIn(ExperimentalWasmDsl::class) + wasmJs { + binaries.executable() + nodejs() + } + + sourceSets { + commonMain.dependencies { + implementation(projects.tiamat) + + api(compose.foundation) + api(compose.material3) + api(compose.materialIconsExtended) + api(compose.runtime) + api(compose.ui) + } + } +} diff --git a/example/composeApp/src/commonMain/kotlin/AppTheme.kt b/example/ui-core/src/commonMain/kotlin/composegears/tiamat/example/ui/core/AppTheme.kt similarity index 94% rename from example/composeApp/src/commonMain/kotlin/AppTheme.kt rename to example/ui-core/src/commonMain/kotlin/composegears/tiamat/example/ui/core/AppTheme.kt index 84b1dda..b214618 100644 --- a/example/composeApp/src/commonMain/kotlin/AppTheme.kt +++ b/example/ui-core/src/commonMain/kotlin/composegears/tiamat/example/ui/core/AppTheme.kt @@ -1,4 +1,4 @@ -@file:Suppress("MissingPackageDeclaration") +package composegears.tiamat.example.ui.core import androidx.compose.material3.MaterialTheme import androidx.compose.material3.darkColorScheme @@ -48,7 +48,7 @@ private val DarkColors = darkColorScheme( ) @Composable -internal fun AppTheme(content: @Composable () -> Unit) { +fun AppTheme(content: @Composable () -> Unit) { MaterialTheme( colorScheme = DarkColors, content = content diff --git a/example/composeApp/src/commonMain/kotlin/content/examples/common/Common.kt b/example/ui-core/src/commonMain/kotlin/composegears/tiamat/example/ui/core/Common.kt similarity index 76% rename from example/composeApp/src/commonMain/kotlin/content/examples/common/Common.kt rename to example/ui-core/src/commonMain/kotlin/composegears/tiamat/example/ui/core/Common.kt index d985b26..81d683f 100644 --- a/example/composeApp/src/commonMain/kotlin/content/examples/common/Common.kt +++ b/example/ui-core/src/commonMain/kotlin/composegears/tiamat/example/ui/core/Common.kt @@ -1,10 +1,9 @@ -package content.examples.common +package composegears.tiamat.example.ui.core import androidx.compose.foundation.background import androidx.compose.foundation.layout.* import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.automirrored.filled.ArrowBack import androidx.compose.material.icons.automirrored.filled.NavigateBefore import androidx.compose.material.icons.automirrored.filled.NavigateNext import androidx.compose.material.icons.filled.Close @@ -12,45 +11,9 @@ import androidx.compose.material3.* import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp -import com.composegears.tiamat.NavDestinationScope -import com.composegears.tiamat.navController - -@Composable -fun NavDestinationScope<*>.SimpleScreen( - title: String, - color: Color = MaterialTheme.colorScheme.surface, - body: @Composable BoxScope.() -> Unit -) { - val navController = navController() - Surface(color = color) { - Column(Modifier.fillMaxSize()) { - Surface(shadowElevation = 8.dp) { - Row(verticalAlignment = Alignment.CenterVertically) { - IconButton(navController::back) { - Icon(Icons.AutoMirrored.Filled.ArrowBack, "") - } - Text( - text = title, - modifier = Modifier.fillMaxWidth(), - textAlign = TextAlign.Center, - fontWeight = FontWeight.Bold - ) - } - } - Box( - modifier = Modifier.fillMaxSize(), - contentAlignment = Alignment.Center - ) { - body() - } - } - } -} @Composable fun ViewModelInfoCard(content: @Composable ColumnScope.() -> Unit) { diff --git a/example/ui-core/src/commonMain/kotlin/composegears/tiamat/example/ui/core/SimpleScreen.kt b/example/ui-core/src/commonMain/kotlin/composegears/tiamat/example/ui/core/SimpleScreen.kt new file mode 100644 index 0000000..ecf5a7d --- /dev/null +++ b/example/ui-core/src/commonMain/kotlin/composegears/tiamat/example/ui/core/SimpleScreen.kt @@ -0,0 +1,56 @@ +package composegears.tiamat.example.ui.core + +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.BoxScope +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.material.icons.Icons +import androidx.compose.material.icons.automirrored.filled.ArrowBack +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Surface +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.unit.dp +import com.composegears.tiamat.NavDestinationScope +import com.composegears.tiamat.navController + +@Composable +fun NavDestinationScope<*>.SimpleScreen( + title: String, + color: Color = MaterialTheme.colorScheme.surface, + body: @Composable BoxScope.() -> Unit +) { + val navController = navController() + Surface(color = color) { + Column(Modifier.fillMaxSize()) { + Surface(shadowElevation = 8.dp) { + Row(verticalAlignment = Alignment.CenterVertically) { + IconButton(navController::back) { + Icon(Icons.AutoMirrored.Filled.ArrowBack, "") + } + Text( + text = title, + modifier = Modifier.fillMaxWidth(), + textAlign = TextAlign.Center, + fontWeight = FontWeight.Bold + ) + } + } + Box( + modifier = Modifier.fillMaxSize(), + contentAlignment = Alignment.Center + ) { + body() + } + } + } +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 6bb25e8..bf40384 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,11 +3,16 @@ kotlin.code.style=official #Gradle org.gradle.jvmargs=-Xmx2048M -Dfile.encoding=UTF-8 -Dkotlin.daemon.jvm.options\="-Xmx2048M" - #Android android.nonTransitiveRClass=true android.useAndroidX=true #MPP -kotlin.mpp.androidSourceSetLayoutVersion=2 -kotlin.mpp.enableCInteropCommonization=true \ No newline at end of file +kotlin.mpp.enableCInteropCommonization=true +kotlin.native.ignoreDisabledTargets=true + +#WASM +org.jetbrains.compose.experimental.wasm.enabled=true + +#IOS +xcodeproj=./example/app/iosApp \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 2a37801..f6c7944 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -5,22 +5,22 @@ android-minSdk = "21" android-targetSdk = "34" detekt = "1.23.6" -jetbrains-compose = "1.6.2" -kotlin = "1.9.23" +jetbrains-compose = "1.6.10" +kotlin = "2.0.0" [libraries] -androidx-activity-compose = "androidx.activity:activity-compose:1.8.2" -androidx-camera-camera2 = "androidx.camera:camera-camera2:1.3.2" -androidx-camera-lifecycle = "androidx.camera:camera-lifecycle:1.3.2" -androidx-camera-view = "androidx.camera:camera-view:1.3.2" +androidx-activity-compose = "androidx.activity:activity-compose:1.9.0" +androidx-camera-camera2 = "androidx.camera:camera-camera2:1.3.3" +androidx-camera-lifecycle = "androidx.camera:camera-lifecycle:1.3.3" +androidx-camera-view = "androidx.camera:camera-view:1.3.3" androidx-concurrent-futures = "androidx.concurrent:concurrent-futures-ktx:1.1.0" -androidx-lifecycle-runtime = "androidx.lifecycle:lifecycle-runtime-ktx:2.7.0" +androidx-lifecycle-runtime = "androidx.lifecycle:lifecycle-runtime-ktx:2.8.0" -detekt-compose = "io.nlopez.compose.rules:detekt:0.3.15" +detekt-compose = "io.nlopez.compose.rules:detekt:0.4.3" detekt-formatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detekt" } koin-compose = "io.insert-koin:koin-compose:1.1.3" -koin-core = "io.insert-koin:koin-core:3.5.4" +koin-core = "io.insert-koin:koin-core:3.5.6" kotlin-coroutines-swing = "org.jetbrains.kotlinx:kotlinx-coroutines-swing:1.8.0" kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" } @@ -28,6 +28,7 @@ kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotl [plugins] android-application = { id = "com.android.application", version.ref = "agp" } android-library = { id = "com.android.library", version.ref = "agp" } +compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" } jetbrains-compose = { id = "org.jetbrains.compose", version.ref = "jetbrains-compose" } kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } diff --git a/settings.gradle.kts b/settings.gradle.kts index f3c2521..d4d372f 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -21,4 +21,6 @@ dependencyResolutionManagement { include(":tiamat") include(":tiamat-koin") -include(":example:composeApp") \ No newline at end of file +include(":example:app:composeApp") +include(":example:ui-core") +include(":example:sample-koin") \ No newline at end of file diff --git a/tiamat-koin/build.gradle.kts b/tiamat-koin/build.gradle.kts index 696e00c..61426e4 100644 --- a/tiamat-koin/build.gradle.kts +++ b/tiamat-koin/build.gradle.kts @@ -1,6 +1,11 @@ +import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi +import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl + plugins { alias(libs.plugins.kotlin.multiplatform) alias(libs.plugins.android.library) + alias(libs.plugins.compose.compiler) alias(libs.plugins.jetbrains.compose) alias(libs.plugins.m2p) } @@ -11,10 +16,9 @@ kotlin { jvm() androidTarget { publishLibraryVariants("release") - compilations.all { - kotlinOptions { - jvmTarget = "1.8" - } + @OptIn(ExperimentalKotlinGradlePluginApi::class) + compilerOptions { + jvmTarget = JvmTarget.JVM_1_8 } } iosX64() @@ -28,6 +32,7 @@ kotlin { implementation(libs.koin.core) implementation(libs.koin.compose) + implementation(compose.foundation) implementation(compose.runtime) } } diff --git a/tiamat/build.gradle.kts b/tiamat/build.gradle.kts index 074fd92..27fe9aa 100644 --- a/tiamat/build.gradle.kts +++ b/tiamat/build.gradle.kts @@ -1,6 +1,11 @@ +import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi +import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl + plugins { alias(libs.plugins.kotlin.multiplatform) alias(libs.plugins.android.library) + alias(libs.plugins.compose.compiler) alias(libs.plugins.jetbrains.compose) alias(libs.plugins.m2p) } @@ -11,16 +16,21 @@ kotlin { jvm() androidTarget { publishLibraryVariants("release") - compilations.all { - kotlinOptions { - jvmTarget = "1.8" - } + @OptIn(ExperimentalKotlinGradlePluginApi::class) + compilerOptions { + jvmTarget = JvmTarget.JVM_1_8 } } iosX64() iosArm64() iosSimulatorArm64() + @OptIn(ExperimentalWasmDsl::class) + wasmJs { + binaries.executable() + nodejs() + } + sourceSets { commonMain.dependencies { implementation(compose.runtime) diff --git a/tiamat/src/wasmJsMain/kotlin/com/composegears/tiamat/Platform.wasm.kt b/tiamat/src/wasmJsMain/kotlin/com/composegears/tiamat/Platform.wasm.kt new file mode 100644 index 0000000..df093e7 --- /dev/null +++ b/tiamat/src/wasmJsMain/kotlin/com/composegears/tiamat/Platform.wasm.kt @@ -0,0 +1,37 @@ +package com.composegears.tiamat + +import androidx.compose.runtime.Composable + +/** + * Global in-memory data storage + */ +private val globalDataStorage = NavControllersStorage() + +/** + * @return platform root NavControllers storage object + */ +@Composable +internal actual fun rootNavControllersStore(): NavControllersStorage = globalDataStorage + +/** + * Wrap platform content and provides additional info/providable-s + */ +@Composable +internal actual fun NavDestinationScope.PlatformContentWrapper( + content: @Composable NavDestinationScope.() -> Unit +) { + content() +} + +/** + * No back button + */ +@Composable +actual fun NavBackHandler(enabled: Boolean, onBackEvent: () -> Unit) = Unit + +/** + * We can not call T::class in @Composable functions, + * + * workaround is to call it outside of @Composable via regular inline fun + */ +actual inline fun className(): String = T::class.simpleName!! \ No newline at end of file