diff --git a/.idea/artifacts/compose_destinations_bottom_sheet_jvm_2_1_0_beta07.xml b/.idea/artifacts/compose_destinations_bottom_sheet_jvm_2_1_0_beta07.xml new file mode 100644 index 00000000..e2eac4fa --- /dev/null +++ b/.idea/artifacts/compose_destinations_bottom_sheet_jvm_2_1_0_beta07.xml @@ -0,0 +1,8 @@ + + + $PROJECT_DIR$/compose-destinations-bottom-sheet/build/libs + + + + + \ No newline at end of file diff --git a/.idea/artifacts/compose_destinations_desktop_2_1_0_beta07.xml b/.idea/artifacts/compose_destinations_desktop_2_1_0_beta07.xml new file mode 100644 index 00000000..85e6a87e --- /dev/null +++ b/.idea/artifacts/compose_destinations_desktop_2_1_0_beta07.xml @@ -0,0 +1,8 @@ + + + $PROJECT_DIR$/compose-destinations/build/libs + + + + + \ No newline at end of file diff --git a/.idea/artifacts/compose_destinations_jvm_2_1_0_beta07.xml b/.idea/artifacts/compose_destinations_jvm_2_1_0_beta07.xml new file mode 100644 index 00000000..d6fa2e6a --- /dev/null +++ b/.idea/artifacts/compose_destinations_jvm_2_1_0_beta07.xml @@ -0,0 +1,8 @@ + + + $PROJECT_DIR$/compose-destinations/build/libs + + + + + \ No newline at end of file diff --git a/.idea/artifacts/compose_destinations_jvm_local_kmp_1.xml b/.idea/artifacts/compose_destinations_jvm_local_kmp_1.xml new file mode 100644 index 00000000..b813ce13 --- /dev/null +++ b/.idea/artifacts/compose_destinations_jvm_local_kmp_1.xml @@ -0,0 +1,8 @@ + + + $PROJECT_DIR$/compose-destinations/build/libs + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 6adde264..44b90aa3 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -9,6 +9,7 @@ + diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml index 2649b7bb..39eb8ee9 100644 --- a/.idea/deploymentTargetSelector.xml +++ b/.idea/deploymentTargetSelector.xml @@ -11,6 +11,9 @@ + + \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 6c0127a7..5bb43701 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,25 +3,18 @@ import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask plugins { alias(libs.plugins.dependencyCheckPlugin) -} - -buildscript { + alias(libs.plugins.androidLibrary) apply false + alias(libs.plugins.androidApplication) apply false - repositories { - google() - mavenCentral() - } + alias(libs.plugins.kotlinMultiplatform) apply false + alias(libs.plugins.kotlinAndroid) apply false + alias(libs.plugins.kotlinSerialization) apply false - dependencies { - classpath(libs.agp) - classpath(libs.kotlin) - classpath(libs.kotlinSerialization) - classpath(libs.mavenPublishPlugin) - } + alias(libs.plugins.mavenPublish) apply false } tasks.register("clean") { - delete(rootProject.buildDir) + delete(rootProject.layout.buildDirectory) } /** diff --git a/compose-destinations-bottom-sheet/build.gradle.kts b/compose-destinations-bottom-sheet/build.gradle.kts index bebb042c..a603183f 100644 --- a/compose-destinations-bottom-sheet/build.gradle.kts +++ b/compose-destinations-bottom-sheet/build.gradle.kts @@ -1,10 +1,21 @@ plugins { - id("com.android.library") - kotlin("android") + alias(libs.plugins.androidLibrary) + alias(libs.plugins.kotlinMultiplatform) } apply(from = "${rootProject.projectDir}/publish.gradle") +kotlin { + applyDefaultHierarchyTemplate() + androidTarget { + compilations.all { + kotlinOptions { + jvmTarget = JavaVersion.VERSION_1_8.toString() + } + } + } +} + android { namespace = "com.ramcosta.composedestinations.bottomsheet" @@ -12,7 +23,6 @@ android { defaultConfig { minSdk = libs.versions.minSdk.get().toIntOrNull() - targetSdk = libs.versions.targetSdk.get().toIntOrNull() testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles.add(File("consumer-rules.pro")) @@ -30,10 +40,6 @@ android { targetCompatibility = JavaVersion.VERSION_1_8 } - kotlinOptions { - jvmTarget = JavaVersion.VERSION_1_8.toString() - } - buildFeatures { compose = true } diff --git a/compose-destinations-bottom-sheet/src/main/java/com/ramcosta/composedestinations/bottomsheet/manualcomposablecalls/ManualComposableCallsBuilder.kt b/compose-destinations-bottom-sheet/src/main/java/com/ramcosta/composedestinations/bottomsheet/manualcomposablecalls/ManualComposableCallsBuilder.kt index c758fd22..53f5c9db 100644 --- a/compose-destinations-bottom-sheet/src/main/java/com/ramcosta/composedestinations/bottomsheet/manualcomposablecalls/ManualComposableCallsBuilder.kt +++ b/compose-destinations-bottom-sheet/src/main/java/com/ramcosta/composedestinations/bottomsheet/manualcomposablecalls/ManualComposableCallsBuilder.kt @@ -4,6 +4,7 @@ import androidx.compose.runtime.Composable import com.ramcosta.composedestinations.bottomsheet.spec.DestinationStyleBottomSheet import com.ramcosta.composedestinations.manualcomposablecalls.DestinationLambda import com.ramcosta.composedestinations.manualcomposablecalls.ManualComposableCallsBuilder +import com.ramcosta.composedestinations.manualcomposablecalls.ManualComposableCallsBuilderImpl import com.ramcosta.composedestinations.manualcomposablecalls.composable import com.ramcosta.composedestinations.scope.BottomSheetDestinationScope import com.ramcosta.composedestinations.scope.DestinationScope @@ -30,7 +31,7 @@ fun ManualComposableCallsBuilder.bottomSheetComposable( content: @Composable BottomSheetDestinationScope.() -> Unit ) { validateBottomSheet(destination) - + this as ManualComposableCallsBuilderImpl add( lambda = DestinationLambda.BottomSheet(content), destination = destination, @@ -40,6 +41,7 @@ fun ManualComposableCallsBuilder.bottomSheetComposable( private fun ManualComposableCallsBuilder.validateBottomSheet( destination: DestinationSpec ) { + this as ManualComposableCallsBuilderImpl if (engineType != NavHostEngine.Type.DEFAULT) { error("'bottomSheetComposable' can only be called with a 'NavHostEngine'") } diff --git a/compose-destinations-codegen/src/main/java/com/ramcosta/composedestinations/codegen/writers/CustomNavTypesWriter.kt b/compose-destinations-codegen/src/main/java/com/ramcosta/composedestinations/codegen/writers/CustomNavTypesWriter.kt index c634c2a0..6ce79d97 100644 --- a/compose-destinations-codegen/src/main/java/com/ramcosta/composedestinations/codegen/writers/CustomNavTypesWriter.kt +++ b/compose-destinations-codegen/src/main/java/com/ramcosta/composedestinations/codegen/writers/CustomNavTypesWriter.kt @@ -136,7 +136,6 @@ internal class CustomNavTypesWriter( "$CORE_PACKAGE_NAME.navargs.primitives.DestinationsEnumNavType", "$CORE_PACKAGE_NAME.navargs.primitives.array.DestinationsEnumArrayNavType", "$CORE_PACKAGE_NAME.navargs.primitives.arraylist.DestinationsEnumArrayListNavType", - "$CORE_PACKAGE_NAME.navargs.primitives.valueOfIgnoreCase", ) ) @@ -151,13 +150,13 @@ internal class CustomNavTypesWriter( val typePlaceHolder = importableHelper.addAndGetPlaceholder(importable) val (instantiateNavType, navType) = when { it.isArrayList() -> { - "DestinationsEnumArrayListNavType(${typePlaceHolder}::class.java)" to "DestinationsEnumArrayListNavType<${typePlaceHolder}>" + "DestinationsEnumArrayListNavType(${typePlaceHolder}::valueOf)" to "DestinationsEnumArrayListNavType<${typePlaceHolder}>" } it.isArray() -> { - "DestinationsEnumArrayNavType { Array<${typePlaceHolder}>(it.size) { idx -> ${typePlaceHolder}::class.java.valueOfIgnoreCase(it[idx]) } }" to "DestinationsEnumArrayNavType<${typePlaceHolder}>" + "DestinationsEnumArrayNavType { Array<${typePlaceHolder}>(it.size) { idx -> ${typePlaceHolder}.valueOf(it[idx]) } }" to "DestinationsEnumArrayNavType<${typePlaceHolder}>" } else -> { - "DestinationsEnumNavType(${typePlaceHolder}::class.java)" to "DestinationsEnumNavType<${typePlaceHolder}>" + "DestinationsEnumNavType(${typePlaceHolder}::valueOf)" to "DestinationsEnumNavType<${typePlaceHolder}>" } } diff --git a/compose-destinations-wear/build.gradle.kts b/compose-destinations-wear/build.gradle.kts index 75334d78..5aa05816 100644 --- a/compose-destinations-wear/build.gradle.kts +++ b/compose-destinations-wear/build.gradle.kts @@ -1,6 +1,6 @@ plugins { - id("com.android.library") - kotlin("android") + alias(libs.plugins.androidLibrary) + alias(libs.plugins.kotlinAndroid) } apply(from = "${rootProject.projectDir}/publish.gradle") @@ -12,7 +12,6 @@ android { defaultConfig { minSdk = 25 - targetSdk = libs.versions.targetSdk.get().toIntOrNull() testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles.add(File("consumer-rules.pro")) diff --git a/compose-destinations-wear/src/main/java/com/ramcosta/composedestinations/wear/WearNavHostEngine.kt b/compose-destinations-wear/src/main/java/com/ramcosta/composedestinations/wear/WearNavHostEngine.kt index 23a60291..e3276dfa 100644 --- a/compose-destinations-wear/src/main/java/com/ramcosta/composedestinations/wear/WearNavHostEngine.kt +++ b/compose-destinations-wear/src/main/java/com/ramcosta/composedestinations/wear/WearNavHostEngine.kt @@ -22,6 +22,7 @@ import com.ramcosta.composedestinations.manualcomposablecalls.allDeepLinks import com.ramcosta.composedestinations.navigation.DependenciesContainerBuilder import com.ramcosta.composedestinations.rememberNavHostEngine import com.ramcosta.composedestinations.scope.DestinationScopeImpl +import com.ramcosta.composedestinations.spec.ActivityDestinationStyle import com.ramcosta.composedestinations.spec.DestinationStyle import com.ramcosta.composedestinations.spec.NavGraphSpec import com.ramcosta.composedestinations.spec.NavHostEngine @@ -101,7 +102,7 @@ internal class WearNavHostEngine( ) } - is DestinationStyle.Activity -> { + is ActivityDestinationStyle -> { with(defaultNavHostEngine) { composable(destination, navController, dependenciesContainerBuilder, manualComposableCalls) } diff --git a/compose-destinations/build.gradle.kts b/compose-destinations/build.gradle.kts index c9959bce..33a56db5 100644 --- a/compose-destinations/build.gradle.kts +++ b/compose-destinations/build.gradle.kts @@ -1,10 +1,50 @@ plugins { - id("com.android.library") - kotlin("android") + alias(libs.plugins.androidLibrary) + alias(libs.plugins.kotlinMultiplatform) } apply(from = "${rootProject.projectDir}/publish.gradle") +kotlin { +// applyDefaultHierarchyTemplate() + androidTarget { + compilations.all { + kotlinOptions { + jvmTarget = JavaVersion.VERSION_1_8.toString() + } + } + } + jvm() + macosX64() + macosArm64() + iosX64() + iosArm64() + iosSimulatorArm64() + + sourceSets { +// val androidMain by getting +// val jvmMain by getting + + commonMain.dependencies { + api("org.jetbrains.androidx.navigation:navigation-compose:2.8.0-alpha02") + } + + androidMain.dependencies { +// api(libs.compose.navigation) + api("org.jetbrains.androidx.core:core-bundle:1.0.0") // TODO RACOSTA why do I need this? + } + +// androidMain.dependsOn(jvmMain) + } + + compilerOptions { + freeCompilerArgs.addAll( + "-opt-in=kotlin.RequiresOptIn", + "-opt-in=com.ramcosta.composedestinations.annotation.internal.InternalDestinationsApi" + ) + } +} + android { namespace = "com.ramcosta.composedestinations" @@ -12,7 +52,6 @@ android { defaultConfig { minSdk = libs.versions.minSdk.get().toIntOrNull() - targetSdk = libs.versions.targetSdk.get().toIntOrNull() testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles.add(File("consumer-rules.pro")) @@ -34,10 +73,6 @@ android { targetCompatibility = JavaVersion.VERSION_1_8 } - kotlinOptions { - jvmTarget = JavaVersion.VERSION_1_8.toString() - } - buildFeatures { compose = true } @@ -46,14 +81,3 @@ android { kotlinCompilerExtensionVersion = libs.versions.composeCompiler.get() } } - -tasks.withType().configureEach { - kotlinOptions.freeCompilerArgs += listOf( - "-opt-in=kotlin.RequiresOptIn", - "-opt-in=com.ramcosta.composedestinations.annotation.internal.InternalDestinationsApi" - ) -} - -dependencies { - api(libs.compose.navigation) -} diff --git a/compose-destinations/src/androidMain/AndroidManifest.xml b/compose-destinations/src/androidMain/AndroidManifest.xml new file mode 100644 index 00000000..44008a43 --- /dev/null +++ b/compose-destinations/src/androidMain/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/annotation/ActivityDestination.kt b/compose-destinations/src/androidMain/kotlin/com/ramcosta/composedestinations/annotation/ActivityDestination.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/annotation/ActivityDestination.kt rename to compose-destinations/src/androidMain/kotlin/com/ramcosta/composedestinations/annotation/ActivityDestination.kt diff --git a/compose-destinations/src/androidMain/kotlin/com/ramcosta/composedestinations/manualcomposablecalls/ManualComposableCallsBuilder.android.kt b/compose-destinations/src/androidMain/kotlin/com/ramcosta/composedestinations/manualcomposablecalls/ManualComposableCallsBuilder.android.kt new file mode 100644 index 00000000..c3accd23 --- /dev/null +++ b/compose-destinations/src/androidMain/kotlin/com/ramcosta/composedestinations/manualcomposablecalls/ManualComposableCallsBuilder.android.kt @@ -0,0 +1,18 @@ +package com.ramcosta.composedestinations.manualcomposablecalls + +import androidx.navigation.NavDeepLinkDslBuilder +import androidx.navigation.navDeepLink +import com.ramcosta.composedestinations.spec.Route + +/** + * Adds deep link created by [deepLinkBuilder] to this [Route] ([NavGraphSpec] or [DestinationSpec]). + * + * Useful when you need to create the deep link at runtime. + */ +fun ManualComposableCallsBuilder.addDeepLink( + route: Route, + deepLinkBuilder: NavDeepLinkDslBuilder.() -> Unit +) { + this as ManualComposableCallsBuilderImpl + add(route.route, navDeepLink(deepLinkBuilder)) +} \ No newline at end of file diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/parcelable/DefaultParcelableNavTypeSerializer.kt b/compose-destinations/src/androidMain/kotlin/com/ramcosta/composedestinations/navargs/parcelable/DefaultParcelableNavTypeSerializer.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/parcelable/DefaultParcelableNavTypeSerializer.kt rename to compose-destinations/src/androidMain/kotlin/com/ramcosta/composedestinations/navargs/parcelable/DefaultParcelableNavTypeSerializer.kt diff --git a/compose-destinations/src/androidMain/kotlin/com/ramcosta/composedestinations/navargs/serializable/DefaultSerializableNavTypeSerializer.kt b/compose-destinations/src/androidMain/kotlin/com/ramcosta/composedestinations/navargs/serializable/DefaultSerializableNavTypeSerializer.kt new file mode 100644 index 00000000..17cca089 --- /dev/null +++ b/compose-destinations/src/androidMain/kotlin/com/ramcosta/composedestinations/navargs/serializable/DefaultSerializableNavTypeSerializer.kt @@ -0,0 +1,49 @@ +package com.ramcosta.composedestinations.navargs.serializable + +import com.ramcosta.composedestinations.navargs.DestinationsNavTypeSerializer +import com.ramcosta.composedestinations.navargs.utils.base64ToByteArray +import com.ramcosta.composedestinations.navargs.utils.toBase64Str +import java.io.ByteArrayInputStream +import java.io.ByteArrayOutputStream +import java.io.ObjectInputStream +import java.io.ObjectOutputStream +import java.io.Serializable + +/** + * Default [DestinationsNavTypeSerializer] for [Serializable]s which converts them to Base64 strings + * and then parses them back. + * + * This gets used by the generated code if you don't provide an explicit + * [DestinationsNavTypeSerializer] annotated with `@NavTypeSerializer` for the type being + * passed as navigation argument. + */ +class DefaultSerializableNavTypeSerializer : DestinationsNavTypeSerializer { + //TODO RACOSTA, should be on android src set, given it's on jvm target :thinking: + // A: https://kotlinlang.slack.com/archives/C3PQML5NU/p1716459036428389 + // solution is to create my own src set for both jvm and Android, put this there instead + + override fun toRouteString(value: Serializable): String { + return value.toBase64() + } + + override fun fromRouteString(routeStr: String): Serializable { + return base64ToSerializable(routeStr) + } + + private fun Serializable.toBase64(): String { + return ByteArrayOutputStream().use { + val out = ObjectOutputStream(it) + out.writeObject(this) + out.flush() + it.toByteArray().toBase64Str() + } + } + + @Suppress("UNCHECKED_CAST") + private fun base64ToSerializable(base64: String): T { + val bytes = base64.base64ToByteArray() + return ObjectInputStream(ByteArrayInputStream(bytes)).use { + it.readObject() as T + } + } +} \ No newline at end of file diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/utils/NavArgEncodingUtils.kt b/compose-destinations/src/androidMain/kotlin/com/ramcosta/composedestinations/navargs/utils/NavArgEncodingUtils.android.kt similarity index 90% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/utils/NavArgEncodingUtils.kt rename to compose-destinations/src/androidMain/kotlin/com/ramcosta/composedestinations/navargs/utils/NavArgEncodingUtils.android.kt index ccbd3ad5..86a6eec7 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/utils/NavArgEncodingUtils.kt +++ b/compose-destinations/src/androidMain/kotlin/com/ramcosta/composedestinations/navargs/utils/NavArgEncodingUtils.android.kt @@ -7,7 +7,7 @@ import android.util.Base64 import java.net.URLEncoder import java.nio.charset.StandardCharsets -fun encodeForRoute(arg: String): String { +actual fun encodeForRoute(arg: String): String { return if (!isRunningOnUnitTests) { Uri.encode(arg) } else { @@ -16,7 +16,7 @@ fun encodeForRoute(arg: String): String { } @SuppressLint("NewApi") -fun String.base64ToByteArray(): ByteArray { +actual fun String.base64ToByteArray(): ByteArray { return if (shouldUseJavaUtil) { java.util.Base64.getUrlDecoder().decode(toByteArray(StandardCharsets.UTF_8)) } else { @@ -25,7 +25,7 @@ fun String.base64ToByteArray(): ByteArray { } @SuppressLint("NewApi") -fun ByteArray.toBase64Str(): String { +actual fun ByteArray.toBase64Str(): String { return if (shouldUseJavaUtil) { java.util.Base64.getUrlEncoder().encodeToString(this) } else { diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/ActivityDestinationSpec.kt b/compose-destinations/src/androidMain/kotlin/com/ramcosta/composedestinations/spec/ActivityDestinationSpec.kt similarity index 97% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/ActivityDestinationSpec.kt rename to compose-destinations/src/androidMain/kotlin/com/ramcosta/composedestinations/spec/ActivityDestinationSpec.kt index b7e6e4ab..d746e913 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/ActivityDestinationSpec.kt +++ b/compose-destinations/src/androidMain/kotlin/com/ramcosta/composedestinations/spec/ActivityDestinationSpec.kt @@ -42,7 +42,7 @@ interface ActivityDestinationSpec : TypedDestinationSpec { fun argsFrom(intent: Intent): T = argsFrom(intent.extras) override val style: DestinationStyle - get() = DestinationStyle.Activity + get() = ActivityDestinationStyle // region inherited that will never be used for activity destinations // ideally, we should have an additional level in the hierarchy, but at the point we are @@ -55,4 +55,4 @@ interface ActivityDestinationSpec : TypedDestinationSpec { error("unexpected error: calling Content method on ActivityDestination!") } // endregion -} \ No newline at end of file +} diff --git a/compose-destinations/src/androidMain/kotlin/com/ramcosta/composedestinations/spec/ActivityDestinationStyle.kt b/compose-destinations/src/androidMain/kotlin/com/ramcosta/composedestinations/spec/ActivityDestinationStyle.kt new file mode 100644 index 00000000..d490c28e --- /dev/null +++ b/compose-destinations/src/androidMain/kotlin/com/ramcosta/composedestinations/spec/ActivityDestinationStyle.kt @@ -0,0 +1,56 @@ +package com.ramcosta.composedestinations.spec + +import androidx.compose.runtime.Composable +import androidx.navigation.NavGraphBuilder +import androidx.navigation.NavHostController +import androidx.navigation.activity +import com.ramcosta.composedestinations.annotation.internal.InternalDestinationsApi +import com.ramcosta.composedestinations.manualcomposablecalls.ManualComposableCalls +import com.ramcosta.composedestinations.manualcomposablecalls.allDeepLinks +import com.ramcosta.composedestinations.navigation.DependenciesContainerBuilder + +@InternalDestinationsApi +object ActivityDestinationStyle: DestinationStyle() { + override fun NavGraphBuilder.addComposable( + destination: TypedDestinationSpec, + navController: NavHostController, + dependenciesContainerBuilder: @Composable DependenciesContainerBuilder<*>.() -> Unit, + manualComposableCalls: ManualComposableCalls + ) { + destination as ActivityDestinationSpec + + addComposable(destination, manualComposableCalls) + } + + internal fun NavGraphBuilder.addComposable( + destination: ActivityDestinationSpec, + manualComposableCalls: ManualComposableCalls? = null + ) { + activity(destination.route) { + targetPackage = destination.targetPackage + activityClass = destination.activityClass?.kotlin + action = destination.action + data = destination.data + dataPattern = destination.dataPattern + + destination.allDeepLinks(manualComposableCalls).forEach { deepLink -> + deepLink { + action = deepLink.action + uriPattern = deepLink.uriPattern + mimeType = deepLink.mimeType + } + } + + destination.arguments.forEach { navArg -> + argument(navArg.name) { + if (navArg.argument.isDefaultValuePresent) { + defaultValue = navArg.argument.defaultValue + } + type = navArg.argument.type + nullable = navArg.argument.isNullable + } + } + } + } + +} \ No newline at end of file diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/DirectionDestinationSpec.kt b/compose-destinations/src/androidMain/kotlin/com/ramcosta/composedestinations/spec/DirectionActivityDestinationSpec.kt similarity index 58% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/DirectionDestinationSpec.kt rename to compose-destinations/src/androidMain/kotlin/com/ramcosta/composedestinations/spec/DirectionActivityDestinationSpec.kt index 5e98628f..94d19c0d 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/DirectionDestinationSpec.kt +++ b/compose-destinations/src/androidMain/kotlin/com/ramcosta/composedestinations/spec/DirectionActivityDestinationSpec.kt @@ -3,19 +3,6 @@ package com.ramcosta.composedestinations.spec import android.os.Bundle import androidx.lifecycle.SavedStateHandle -/** - * [TypedDestinationSpec] that does not contain any navigation arguments. - * It itself is a [Direction] - */ -interface DirectionDestinationSpec: TypedDestinationSpec, Direction { - - override fun invoke(navArgs: Unit): Direction = this - - override fun argsFrom(bundle: Bundle?) = Unit - - override fun argsFrom(savedStateHandle: SavedStateHandle) = Unit -} - /** * [ActivityDestinationSpec] that does not contain any navigation arguments. * It itself is a [Direction] diff --git a/compose-destinations/src/androidMain/kotlin/com/ramcosta/composedestinations/utils/NavGraphBuilderDestinationExtensions.android.kt b/compose-destinations/src/androidMain/kotlin/com/ramcosta/composedestinations/utils/NavGraphBuilderDestinationExtensions.android.kt new file mode 100644 index 00000000..933fec91 --- /dev/null +++ b/compose-destinations/src/androidMain/kotlin/com/ramcosta/composedestinations/utils/NavGraphBuilderDestinationExtensions.android.kt @@ -0,0 +1,26 @@ +package com.ramcosta.composedestinations.utils + +import androidx.navigation.NavGraphBuilder +import com.ramcosta.composedestinations.spec.ActivityDestinationSpec +import com.ramcosta.composedestinations.spec.ActivityDestinationStyle + +/** + * Like [androidx.navigation.activity] but accepts + * a [ActivityDestinationSpec] to get the route, arguments and deep links. + * + * Useful if you opt to use [androidx.navigation.compose.NavHost] instead of + * [com.ramcosta.composedestinations.DestinationsNavHost]. + * This way, you can build the navigation graph in the "vanilla compose navigation" way. + * If you do this, you should also disable the `NavGraphs` generation + * in build.gradle: + * ``` + * ksp { + * arg("compose-destinations.generateNavGraphs", "false") + * } + * ``` + */ +fun NavGraphBuilder.activity( + destination: ActivityDestinationSpec, +) = with(destination.style as ActivityDestinationStyle) { + addComposable(destination) +} \ No newline at end of file diff --git a/compose-destinations/src/appleMain/kotlin/com/ramcosta/composedestinations/navargs/utils/Base64.kt b/compose-destinations/src/appleMain/kotlin/com/ramcosta/composedestinations/navargs/utils/Base64.kt new file mode 100644 index 00000000..9db8b9f5 --- /dev/null +++ b/compose-destinations/src/appleMain/kotlin/com/ramcosta/composedestinations/navargs/utils/Base64.kt @@ -0,0 +1,386 @@ +package com.ramcosta.composedestinations.navargs.utils + +import kotlin.math.min + +/** + * This class consists exclusively of static methods for obtaining + * encoders and decoders for the Base64 encoding scheme. The + * implementation of this class supports the following types of Base64 + * as specified in + * [RFC 4648](http://www.ietf.org/rfc/rfc4648.txt) and + * [RFC 2045](http://www.ietf.org/rfc/rfc2045.txt). + * + * + * * **Basic** + * + * Uses "The Base64 Alphabet" as specified in Table 1 of + * RFC 4648 and RFC 2045 for encoding and decoding operation. + * The encoder does not add any line feed (line separator) + * character. The decoder rejects data that contains characters + * outside the base64 alphabet. + * + * * **URL and Filename safe** + * + * Uses the "URL and Filename safe Base64 Alphabet" as specified + * in Table 2 of RFC 4648 for encoding and decoding. The + * encoder does not add any line feed (line separator) character. + * The decoder rejects data that contains characters outside the + * base64 alphabet. + * + * * **MIME** + * + * Uses "The Base64 Alphabet" as specified in Table 1 of + * RFC 2045 for encoding and decoding operation. The encoded output + * must be represented in lines of no more than 76 characters each + * and uses a carriage return `'\r'` followed immediately by + * a linefeed `'\n'` as the line separator. No line separator + * is added to the end of the encoded output. All line separators + * or other characters not found in the base64 alphabet table are + * ignored in decoding operation. + * + * + * + * Unless otherwise noted, passing a `null` argument to a + * method of this class will cause a [NullPointerException] to be thrown. + * + * @author Xueming Shen + * @since 1.8 + */ +object Base64 { + + fun ByteArray.encodeToBase64(): String { + return encoder.encode(this).decodeToString() + } + + fun String.decodeFromBase64(): ByteArray { + return decoder.decode(this.encodeToByteArray()) + } + + /** + * Returns a [Encoder] that encodes using the + * [Basic](#basic) type base64 encoding scheme. + * + * @return A Base64 encoder. + */ + val encoder = Encoder(null, -1, true) + + /** + * Returns a [Decoder] that decodes using the + * [Basic](#basic) type base64 encoding scheme. + * + * @return A Base64 decoder. + */ + val decoder = Decoder() + + /** + * This class implements an encoder for encoding byte data using + * the Base64 encoding scheme as specified in RFC 4648 and RFC 2045. + * + * + * Instances of [Encoder] class are safe for use by + * multiple concurrent threads. + * + * + * Unless otherwise noted, passing a `null` argument to + * a method of this class will cause a + * [NullPointerException][java.lang.NullPointerException] to + * be thrown. + * + * @see Decoder + * + * @since 1.8 + */ + class Encoder internal constructor(private val newline: ByteArray?, private val linemax: Int, private val doPadding: Boolean) { + private fun outLength(srclen: Int): Int { + var len = 0 + len = if (doPadding) { + 4 * ((srclen + 2) / 3) + } else { + val n = srclen % 3 + 4 * (srclen / 3) + if (n == 0) 0 else n + 1 + } + if (linemax > 0) // line separators + len += (len - 1) / linemax * newline!!.size + return len + } + + /** + * Encodes all bytes from the specified byte array into a newly-allocated + * byte array using the [Base64] encoding scheme. The returned byte + * array is of the length of the resulting bytes. + * + * @param src + * the byte array to encode + * @return A newly-allocated byte array containing the resulting + * encoded bytes. + */ + fun encode(src: ByteArray): ByteArray { + val len = outLength(src.size) // dst array size + val dst = ByteArray(len) + val ret = encode0(src, 0, src.size, dst) + return if (ret != dst.size) dst.copyOf(ret) else dst + } + + private fun encodeBlock(src: ByteArray, sp: Int, sl: Int, dst: ByteArray, dp: Int) { + var sp0 = sp + var dp0 = dp + while (sp0 < sl) { + val bits: Int = src[sp0++].toInt() and 0xff shl 16 or ( + src[sp0++].toInt() and 0xff shl 8) or + (src[sp0++].toInt() and 0xff) + dst[dp0++] = toBase64[bits ushr 18 and 0x3f].toByte() + dst[dp0++] = toBase64[bits ushr 12 and 0x3f].toByte() + dst[dp0++] = toBase64[bits ushr 6 and 0x3f].toByte() + dst[dp0++] = toBase64[bits and 0x3f].toByte() + } + } + + private fun encode0(src: ByteArray, off: Int, end: Int, dst: ByteArray): Int { + val base64 = toBase64 + var sp = off + var slen = (end - off) / 3 * 3 + val sl = off + slen + if (linemax > 0 && slen > linemax / 4 * 3) slen = linemax / 4 * 3 + var dp = 0 + while (sp < sl) { + val sl0: Int = min(sp + slen, sl) + encodeBlock(src, sp, sl0, dst, dp) + val dlen = (sl0 - sp) / 3 * 4 + dp += dlen + sp = sl0 + if (dlen == linemax && sp < end) { + for (b in newline!!) { + dst[dp++] = b + } + } + } + if (sp < end) { // 1 or 2 leftover bytes + val b0: Int = src[sp++].toInt() and 0xff + dst[dp++] = base64[b0 shr 2].toByte() + if (sp == end) { + dst[dp++] = base64[b0 shl 4 and 0x3f].toByte() + if (doPadding) { + dst[dp++] = '='.toByte() + dst[dp++] = '='.toByte() + } + } else { + val b1: Int = src[sp++].toInt() and 0xff + dst[dp++] = base64[b0 shl 4 and 0x3f or (b1 shr 4)].toByte() + dst[dp++] = base64[b1 shl 2 and 0x3f].toByte() + if (doPadding) { + dst[dp++] = '='.toByte() + } + } + } + return dp + } + + companion object { + /** + * This array is a lookup table that translates 6-bit positive integer + * index values into their "Base64 Alphabet" equivalents as specified + * in "Table 1: The Base64 Alphabet" of RFC 2045 (and RFC 4648). + */ + val toBase64 = charArrayOf( + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', + 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', + 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' + ) + + /** + * It's the lookup table for "URL and Filename safe Base64" as specified + * in Table 2 of the RFC 4648, with the '+' and '/' changed to '-' and + * '_'. This table is used when BASE64_URL is specified. + */ + internal val toBase64URL = charArrayOf( + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', + 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', + 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_' + ) + } + } + + /** + * This class implements a decoder for decoding byte data using the + * Base64 encoding scheme as specified in RFC 4648 and RFC 2045. + * + * + * The Base64 padding character `'='` is accepted and + * interpreted as the end of the encoded byte data, but is not + * required. So if the final unit of the encoded byte data only has + * two or three Base64 characters (without the corresponding padding + * character(s) padded), they are decoded as if followed by padding + * character(s). If there is a padding character present in the + * final unit, the correct number of padding character(s) must be + * present, otherwise `IllegalArgumentException` ( + * `IOException` when reading from a Base64 stream) is thrown + * during decoding. + * + * + * Instances of [Decoder] class are safe for use by + * multiple concurrent threads. + * + * + * Unless otherwise noted, passing a `null` argument to + * a method of this class will cause a + * [NullPointerException][java.lang.NullPointerException] to + * be thrown. + * + * @see Encoder + * + * @since 1.8 + */ + class Decoder { + companion object { + /** + * Lookup table for decoding unicode characters drawn from the + * "Base64 Alphabet" (as specified in Table 1 of RFC 2045) into + * their 6-bit positive integer equivalents. Characters that + * are not in the Base64 alphabet but fall within the bounds of + * the array are encoded to -1. + * + */ + internal val fromBase64 = IntArray(256) + + /** + * Lookup table for decoding "URL and Filename safe Base64 Alphabet" + * as specified in Table2 of the RFC 4648. + */ + private val fromBase64URL = IntArray(256) + + init { + fromBase64.fill(-1) + for (i in Encoder.toBase64.indices) fromBase64[Encoder.toBase64[i].toInt()] = i + fromBase64['='.toInt()] = -2 + } + + init { + fromBase64URL.fill(-1) + for (i in Encoder.toBase64URL.indices) fromBase64URL[Encoder.toBase64URL[i].toInt()] = i + fromBase64URL['='.toInt()] = -2 + } + } + + /** + * Decodes all bytes from the input byte array using the [Base64] + * encoding scheme, writing the results into a newly-allocated output + * byte array. The returned byte array is of the length of the resulting + * bytes. + * + * @param src + * the byte array to decode + * + * @return A newly-allocated byte array containing the decoded bytes. + * + * @throws IllegalArgumentException + * if `src` is not in valid Base64 scheme + */ + fun decode(src: ByteArray): ByteArray { + var dst = ByteArray(outLength(src, 0, src.size)) + val ret = decode0(src, 0, src.size, dst) + if (ret != dst.size) { + dst = dst.copyOf(ret) + } + return dst + } + + + private fun outLength(src: ByteArray, sp: Int, sl: Int): Int { + var sp = sp + var paddings = 0 + var len = sl - sp + if (len == 0) return 0 + if (len < 2) { + throw IllegalArgumentException( + "Input byte[] should at least have 2 bytes for base64 bytes" + ) + } + if (src[sl - 1].toChar() == '=') { + paddings++ + if (src[sl - 2].toChar() == '=') paddings++ + } + if (paddings == 0 && len and 0x3 != 0) paddings = 4 - (len and 0x3) + return 3 * ((len + 3) / 4) - paddings + } + + private fun decode0(src: ByteArray, sp: Int, sl: Int, dst: ByteArray): Int { + var sp = sp + val base64 = if (false) fromBase64URL else fromBase64 + var dp = 0 + var bits = 0 + var shiftto = 18 // pos of first byte of 4-byte atom + while (sp < sl) { + if (shiftto == 18 && sp + 4 < sl) { // fast path + val sl0 = sp + (sl - sp and 3.inv()) + while (sp < sl0) { + val b1 = base64[src[sp++].toInt() and 0xff] + val b2 = base64[src[sp++].toInt() and 0xff] + val b3 = base64[src[sp++].toInt() and 0xff] + val b4 = base64[src[sp++].toInt() and 0xff] + if (b1 or b2 or b3 or b4 < 0) { // non base64 byte + sp -= 4 + break + } + val bits0 = b1 shl 18 or (b2 shl 12) or (b3 shl 6) or b4 + dst[dp++] = (bits0 shr 16).toByte() + dst[dp++] = (bits0 shr 8).toByte() + dst[dp++] = bits0.toByte() + } + if (sp >= sl) break + } + var b: Int = src[sp++].toInt() and 0xff + if (base64[b].also { b = it } < 0) { + if (b == -2) { // padding byte '=' + // = shiftto==18 unnecessary padding + // x= shiftto==12 a dangling single x + // x to be handled together with non-padding case + // xx= shiftto==6&&sp==sl missing last = + // xx=y shiftto==6 last is not = + require( + !(shiftto == 6 && (sp == sl || src[sp++].toChar() != '=') || + shiftto == 18) + ) { "Input byte array has wrong 4-byte ending unit" } + break + } + throw IllegalArgumentException("Illegal base64 character " + src[sp - 1].toInt().toString(16)) + } + bits = bits or (b shl shiftto) + shiftto -= 6 + if (shiftto < 0) { + dst[dp++] = (bits shr 16).toByte() + dst[dp++] = (bits shr 8).toByte() + dst[dp++] = bits.toByte() + shiftto = 18 + bits = 0 + } + } + // reached end of byte array or hit padding '=' characters. + when (shiftto) { + 6 -> { + dst[dp++] = (bits shr 16).toByte() + } + 0 -> { + dst[dp++] = (bits shr 16).toByte() + dst[dp++] = (bits shr 8).toByte() + } + else -> require(shiftto != 12) { + // dangling single "x", incorrectly encoded. + "Last unit does not have enough valid bits" + } + } + // anything left is invalid, if is not MIME. + // if MIME, ignore all non-base64 character + while (sp < sl) { + throw IllegalArgumentException( + "Input byte array has incorrect ending byte at $sp" + ) + } + return dp + } + } + +} \ No newline at end of file diff --git a/compose-destinations/src/appleMain/kotlin/com/ramcosta/composedestinations/navargs/utils/NavArgEncodingUtils.apple.kt b/compose-destinations/src/appleMain/kotlin/com/ramcosta/composedestinations/navargs/utils/NavArgEncodingUtils.apple.kt new file mode 100644 index 00000000..e20fd846 --- /dev/null +++ b/compose-destinations/src/appleMain/kotlin/com/ramcosta/composedestinations/navargs/utils/NavArgEncodingUtils.apple.kt @@ -0,0 +1,24 @@ +package com.ramcosta.composedestinations.navargs.utils + +import com.ramcosta.composedestinations.navargs.utils.Base64.decodeFromBase64 +import com.ramcosta.composedestinations.navargs.utils.Base64.encodeToBase64 +import platform.Foundation.NSCharacterSet +import platform.Foundation.NSString +import platform.Foundation.URLQueryAllowedCharacterSet +import platform.Foundation.stringByAddingPercentEncodingWithAllowedCharacters + +actual fun encodeForRoute(arg: String): String { + @Suppress("CAST_NEVER_SUCCEEDS") + val encodedString = (arg as NSString).stringByAddingPercentEncodingWithAllowedCharacters( + NSCharacterSet.URLQueryAllowedCharacterSet + )!! + return encodedString +} + +actual fun String.base64ToByteArray(): ByteArray { + return decodeFromBase64() +} + +actual fun ByteArray.toBase64Str(): String { + return encodeToBase64() +} diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/DefaultNavHostEngine.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/DefaultNavHostEngine.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/DefaultNavHostEngine.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/DefaultNavHostEngine.kt diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/DestinationsNavHost.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/DestinationsNavHost.kt similarity index 98% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/DestinationsNavHost.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/DestinationsNavHost.kt index 28e1d09b..e32affc5 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/DestinationsNavHost.kt +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/DestinationsNavHost.kt @@ -8,6 +8,7 @@ import androidx.navigation.NavHostController import com.ramcosta.composedestinations.animations.NavHostAnimatedDestinationStyle import com.ramcosta.composedestinations.manualcomposablecalls.ManualComposableCalls import com.ramcosta.composedestinations.manualcomposablecalls.ManualComposableCallsBuilder +import com.ramcosta.composedestinations.manualcomposablecalls.ManualComposableCallsBuilderImpl import com.ramcosta.composedestinations.navigation.DependenciesContainerBuilder import com.ramcosta.composedestinations.spec.DestinationSpec import com.ramcosta.composedestinations.spec.NavGraphSpec @@ -46,7 +47,6 @@ import com.ramcosta.composedestinations.utils.NavGraphRegistry * * @param navController [NavHostController] that can be used to navigate between this NavHost's destinations. * If you need this outside the scope of this function, you should get it from [androidx.navigation.compose.rememberNavController] - * or, if you're using animation feature, from [com.google.accompanist.navigation.animation.rememberAnimatedNavController]. * Alternatively, you can also use [NavHostEngine.rememberNavController] that will internally call the correct remember function. * * @param dependenciesContainerBuilder offers a [DependenciesContainerBuilder] where you can add @@ -85,7 +85,7 @@ fun DestinationsNavHost( navGraph = navGraph, navController = navController, dependenciesContainerBuilder = dependenciesContainerBuilder, - manualComposableCalls = ManualComposableCallsBuilder(engine.type) + manualComposableCalls = ManualComposableCallsBuilderImpl(engine.type) .apply { manualComposableCallsBuilder() } .build(), ) diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/animations/NavHostAnimatedDestinationStyle.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/animations/NavHostAnimatedDestinationStyle.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/animations/NavHostAnimatedDestinationStyle.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/animations/NavHostAnimatedDestinationStyle.kt diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/animations/defaults/DefaultAnimationParams.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/animations/defaults/DefaultAnimationParams.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/animations/defaults/DefaultAnimationParams.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/animations/defaults/DefaultAnimationParams.kt diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/annotation/Destination.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/annotation/Destination.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/annotation/Destination.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/annotation/Destination.kt diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/annotation/ExternalDestination.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/annotation/ExternalDestination.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/annotation/ExternalDestination.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/annotation/ExternalDestination.kt diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/annotation/ExternalModuleDestinations.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/annotation/ExternalModuleDestinations.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/annotation/ExternalModuleDestinations.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/annotation/ExternalModuleDestinations.kt diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/annotation/ExternalModuleGraph.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/annotation/ExternalModuleGraph.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/annotation/ExternalModuleGraph.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/annotation/ExternalModuleGraph.kt diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/annotation/ExternalNavGraph.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/annotation/ExternalNavGraph.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/annotation/ExternalNavGraph.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/annotation/ExternalNavGraph.kt diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/annotation/NavGraph.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/annotation/NavGraph.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/annotation/NavGraph.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/annotation/NavGraph.kt diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/annotation/NavHostGraph.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/annotation/NavHostGraph.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/annotation/NavHostGraph.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/annotation/NavHostGraph.kt diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/annotation/internal/GeneratedCodeExternalDestinations.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/annotation/internal/GeneratedCodeExternalDestinations.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/annotation/internal/GeneratedCodeExternalDestinations.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/annotation/internal/GeneratedCodeExternalDestinations.kt diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/annotation/internal/InternalDestinationsApi.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/annotation/internal/InternalDestinationsApi.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/annotation/internal/InternalDestinationsApi.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/annotation/internal/InternalDestinationsApi.kt diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/annotation/parameters/CodeGenVisibility.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/annotation/parameters/CodeGenVisibility.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/annotation/parameters/CodeGenVisibility.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/annotation/parameters/CodeGenVisibility.kt diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/annotation/parameters/DeepLink.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/annotation/parameters/DeepLink.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/annotation/parameters/DeepLink.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/annotation/parameters/DeepLink.kt diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/annotation/parameters/NavHostParam.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/annotation/parameters/NavHostParam.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/annotation/parameters/NavHostParam.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/annotation/parameters/NavHostParam.kt diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/manualcomposablecalls/DestinationLambda.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/manualcomposablecalls/DestinationLambda.kt similarity index 95% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/manualcomposablecalls/DestinationLambda.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/manualcomposablecalls/DestinationLambda.kt index 535db44a..a800d63a 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/manualcomposablecalls/DestinationLambda.kt +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/manualcomposablecalls/DestinationLambda.kt @@ -1,13 +1,11 @@ package com.ramcosta.composedestinations.manualcomposablecalls -import android.annotation.SuppressLint import androidx.annotation.RestrictTo import androidx.compose.runtime.Composable import com.ramcosta.composedestinations.scope.AnimatedDestinationScope import com.ramcosta.composedestinations.scope.BottomSheetDestinationScope import com.ramcosta.composedestinations.scope.DestinationScope -@SuppressLint("ComposableNaming") @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) sealed class DestinationLambda { diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/manualcomposablecalls/ManualComposableCalls.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/manualcomposablecalls/ManualComposableCalls.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/manualcomposablecalls/ManualComposableCalls.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/manualcomposablecalls/ManualComposableCalls.kt diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/manualcomposablecalls/ManualComposableCallsBuilder.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/manualcomposablecalls/ManualComposableCallsBuilder.kt similarity index 72% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/manualcomposablecalls/ManualComposableCallsBuilder.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/manualcomposablecalls/ManualComposableCallsBuilder.kt index d125ed86..df076598 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/manualcomposablecalls/ManualComposableCallsBuilder.kt +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/manualcomposablecalls/ManualComposableCallsBuilder.kt @@ -7,8 +7,6 @@ import androidx.compose.animation.SizeTransform import androidx.compose.runtime.Composable import androidx.navigation.NavBackStackEntry import androidx.navigation.NavDeepLink -import androidx.navigation.NavDeepLinkDslBuilder -import androidx.navigation.navDeepLink import com.ramcosta.composedestinations.annotation.internal.InternalDestinationsApi import com.ramcosta.composedestinations.scope.AnimatedDestinationScope import com.ramcosta.composedestinations.scope.DestinationScope @@ -17,8 +15,8 @@ import com.ramcosta.composedestinations.spec.DestinationStyle import com.ramcosta.composedestinations.spec.NavGraphSpec import com.ramcosta.composedestinations.spec.NavHostEngine import com.ramcosta.composedestinations.spec.NavHostGraphSpec -import com.ramcosta.composedestinations.spec.Route import com.ramcosta.composedestinations.spec.TypedDestinationSpec +import kotlin.jvm.JvmSuppressWildcards /** * Registers [content] lambda as the responsible for calling @@ -32,6 +30,7 @@ fun ManualComposableCallsBuilder.composable( destination: TypedDestinationSpec, content: @Composable AnimatedDestinationScope.() -> Unit ) { + this as ManualComposableCallsBuilderImpl if (engineType != NavHostEngine.Type.DEFAULT) { error("'composable' can only be called with a 'NavHostEngine'") } @@ -58,6 +57,7 @@ fun ManualComposableCallsBuilder.dialogComposable( destination: TypedDestinationSpec, content: @Composable DestinationScope.() -> Unit ) { + this as ManualComposableCallsBuilderImpl if (engineType != NavHostEngine.Type.DEFAULT) { error("'dialogComposable' can only be called with a 'NavHostEngine'") } @@ -72,28 +72,13 @@ fun ManualComposableCallsBuilder.dialogComposable( ) } -class ManualComposableCallsBuilder internal constructor(@InternalDestinationsApi val engineType: NavHostEngine.Type) { - +sealed interface ManualComposableCallsBuilder { /** * Overrides the default animations of [this] [NavGraphSpec] at runtime to [animation]. * You should prefer to use the NavGraph annotation `defaultTransitions` unless there's a specific * reason to use this. */ - infix fun NavGraphSpec.animateWith(animation: DestinationStyle.Animated) { - if (this is NavHostGraphSpec) { - error("'animateWith' cannot be called for NavHostGraphs. Use DestinationsNavHost's 'defaultTransitions' for the same effect!") - } - add(route, animation) - } - - /** - * Adds deep link created by [deepLinkBuilder] to this [Route] ([NavGraphSpec] or [DestinationSpec]). - * - * Useful when you need to create the deep link at runtime. - */ - infix fun Route.addDeepLink(deepLinkBuilder: NavDeepLinkDslBuilder.() -> Unit) { - add(route, navDeepLink(deepLinkBuilder)) - } + infix fun NavGraphSpec.animateWith(animation: DestinationStyle.Animated) /** * Overrides the default animations of [this] [NavGraphSpec] at runtime to use [enterTransition], @@ -114,6 +99,53 @@ class ManualComposableCallsBuilder internal constructor(@InternalDestinationsApi )? = exitTransition, sizeTransform: (@JvmSuppressWildcards AnimatedContentTransitionScope.() -> SizeTransform?)? = null, + ) + + /** + * Overrides the style of [this] [DestinationSpec] at runtime to [animation]. + * You should prefer to use the Destination annotation `style` unless there's a specific + * reason to use this. + */ + infix fun DestinationSpec.animateWith(animation: DestinationStyle.Animated) + + /** + * Overrides the style of [this] [DestinationSpec] at runtime to use [enterTransition], + * [exitTransition], [popEnterTransition] and [popExitTransition]. + * You should prefer to use the Destination annotation `style` unless there's a specific + * reason to use this. + */ + fun DestinationSpec.animateWith( + enterTransition: (AnimatedContentTransitionScope.() -> EnterTransition?)? = null, + exitTransition: (AnimatedContentTransitionScope.() -> ExitTransition?)? = null, + popEnterTransition: (AnimatedContentTransitionScope.() -> EnterTransition?)? = enterTransition, + popExitTransition: (AnimatedContentTransitionScope.() -> ExitTransition?)? = exitTransition, + sizeTransform: (AnimatedContentTransitionScope.() -> SizeTransform?)? = null + ) +} + +@InternalDestinationsApi +class ManualComposableCallsBuilderImpl internal constructor( + @InternalDestinationsApi val engineType: NavHostEngine.Type +) : ManualComposableCallsBuilder { + + /** + * Overrides the default animations of [this] [NavGraphSpec] at runtime to [animation]. + * You should prefer to use the NavGraph annotation `defaultTransitions` unless there's a specific + * reason to use this. + */ + override infix fun NavGraphSpec.animateWith(animation: DestinationStyle.Animated) { + if (this is NavHostGraphSpec) { + error("'animateWith' cannot be called for NavHostGraphs. Use DestinationsNavHost's 'defaultTransitions' for the same effect!") + } + add(route, animation) + } + + override fun NavGraphSpec.animateWith( + enterTransition: (AnimatedContentTransitionScope.() -> EnterTransition?)?, + exitTransition: (AnimatedContentTransitionScope.() -> ExitTransition?)?, + popEnterTransition: (AnimatedContentTransitionScope.() -> EnterTransition?)?, + popExitTransition: (AnimatedContentTransitionScope.() -> ExitTransition?)?, + sizeTransform: (AnimatedContentTransitionScope.() -> SizeTransform?)?, ) { this animateWith object: DestinationStyle.Animated() { override val enterTransition = enterTransition @@ -124,37 +156,19 @@ class ManualComposableCallsBuilder internal constructor(@InternalDestinationsApi } } - /** - * Overrides the style of [this] [DestinationSpec] at runtime to [animation]. - * You should prefer to use the Destination annotation `style` unless there's a specific - * reason to use this. - */ - infix fun DestinationSpec.animateWith(animation: DestinationStyle.Animated) { + override infix fun DestinationSpec.animateWith(animation: DestinationStyle.Animated) { if (style !is DestinationStyle.Default && style !is DestinationStyle.Animated) { error("'animateWith' can only be called for a destination of style 'Default' or 'Animated'") } add(route, animation) } - /** - * Overrides the style of [this] [DestinationSpec] at runtime to use [enterTransition], - * [exitTransition], [popEnterTransition] and [popExitTransition]. - * You should prefer to use the Destination annotation `style` unless there's a specific - * reason to use this. - */ - fun DestinationSpec.animateWith( - enterTransition: (@JvmSuppressWildcards - AnimatedContentTransitionScope.() -> EnterTransition?)? = null, - exitTransition: (@JvmSuppressWildcards - AnimatedContentTransitionScope.() -> ExitTransition?)? = null, - popEnterTransition: (@JvmSuppressWildcards - AnimatedContentTransitionScope.() -> EnterTransition?)? = - enterTransition, - popExitTransition: (@JvmSuppressWildcards - AnimatedContentTransitionScope.() -> ExitTransition?)? = - exitTransition, - sizeTransform: (@JvmSuppressWildcards - AnimatedContentTransitionScope.() -> SizeTransform?)? = null, + override fun DestinationSpec.animateWith( + enterTransition: (@JvmSuppressWildcards AnimatedContentTransitionScope.() -> EnterTransition?)?, + exitTransition: (@JvmSuppressWildcards AnimatedContentTransitionScope.() -> ExitTransition?)?, + popEnterTransition: (@JvmSuppressWildcards AnimatedContentTransitionScope.() -> EnterTransition?)?, + popExitTransition: (@JvmSuppressWildcards AnimatedContentTransitionScope.() -> ExitTransition?)?, + sizeTransform: (@JvmSuppressWildcards AnimatedContentTransitionScope.() -> SizeTransform?)?, ) { this animateWith object : DestinationStyle.Animated() { override val enterTransition = enterTransition diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/DestinationsNavType.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/DestinationsNavType.kt similarity index 94% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/DestinationsNavType.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/DestinationsNavType.kt index 34301458..314d80a6 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/DestinationsNavType.kt +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/DestinationsNavType.kt @@ -1,6 +1,6 @@ package com.ramcosta.composedestinations.navargs -import android.os.Bundle +import androidx.core.bundle.Bundle import androidx.lifecycle.SavedStateHandle import androidx.navigation.NavType diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/DestinationsNavTypeSerializer.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/DestinationsNavTypeSerializer.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/DestinationsNavTypeSerializer.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/DestinationsNavTypeSerializer.kt diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/NavTypeSerializer.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/NavTypeSerializer.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/NavTypeSerializer.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/NavTypeSerializer.kt diff --git a/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/CommonConstants.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/CommonConstants.kt new file mode 100644 index 00000000..51bc1221 --- /dev/null +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/CommonConstants.kt @@ -0,0 +1,6 @@ +package com.ramcosta.composedestinations.navargs.primitives + +const val ENCODED_NULL = "%02null%03" +const val DECODED_NULL: String = "\u0002null\u0003" + +const val encodedComma = "%2C" \ No newline at end of file diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/DestinationsBooleanNavType.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/DestinationsBooleanNavType.kt similarity index 93% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/DestinationsBooleanNavType.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/DestinationsBooleanNavType.kt index 9a6692f8..ec5f5d9c 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/DestinationsBooleanNavType.kt +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/DestinationsBooleanNavType.kt @@ -1,6 +1,6 @@ package com.ramcosta.composedestinations.navargs.primitives -import android.os.Bundle +import androidx.core.bundle.Bundle import androidx.lifecycle.SavedStateHandle import com.ramcosta.composedestinations.navargs.DestinationsNavType @@ -10,7 +10,7 @@ object DestinationsBooleanNavType : DestinationsNavType() { when (val bundleValue = booleanToBundleValue(value)) { is Byte -> bundle.putByte(key, bundleValue) is Boolean -> bundle.putBoolean(key, bundleValue) - else -> error("Unexpected type ${bundleValue.javaClass}") + else -> error("Unexpected type ${bundleValue::class}") } } diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/DestinationsEnumNavType.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/DestinationsEnumNavType.kt similarity index 69% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/DestinationsEnumNavType.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/DestinationsEnumNavType.kt index e8457987..712fda37 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/DestinationsEnumNavType.kt +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/DestinationsEnumNavType.kt @@ -1,27 +1,25 @@ package com.ramcosta.composedestinations.navargs.primitives -import android.os.Bundle +import androidx.core.bundle.Bundle import androidx.lifecycle.SavedStateHandle import com.ramcosta.composedestinations.navargs.DestinationsNavType -@Suppress("UNCHECKED_CAST") class DestinationsEnumNavType>( - private val enumType: Class + private val converter: (String) -> E ) : DestinationsNavType() { override fun put(bundle: Bundle, key: String, value: E?) { - bundle.putSerializable(key, value) + bundle.putString(key, serializeValue(value)) } override fun get(bundle: Bundle, key: String): E? { - @Suppress("DEPRECATION") - return bundle.getSerializable(key) as E? + return bundle.getString(key)?.let { converter(it) } } override fun parseValue(value: String): E? { if (value == DECODED_NULL) return null - return enumType.valueOfIgnoreCase(value) + return converter(value) } override fun serializeValue(value: E?): String { @@ -29,11 +27,11 @@ class DestinationsEnumNavType>( } override fun get(savedStateHandle: SavedStateHandle, key: String): E? { - return savedStateHandle[key] + return savedStateHandle.get(key)?.let(converter) } override fun put(savedStateHandle: SavedStateHandle, key: String, value: E?) { - savedStateHandle[key] = value + savedStateHandle[key] = value?.name } } diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/DestinationsFloatNavType.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/DestinationsFloatNavType.kt similarity index 93% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/DestinationsFloatNavType.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/DestinationsFloatNavType.kt index 06ceb217..9fa7fdc8 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/DestinationsFloatNavType.kt +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/DestinationsFloatNavType.kt @@ -1,6 +1,6 @@ package com.ramcosta.composedestinations.navargs.primitives -import android.os.Bundle +import androidx.core.bundle.Bundle import androidx.lifecycle.SavedStateHandle import com.ramcosta.composedestinations.navargs.DestinationsNavType @@ -10,7 +10,7 @@ object DestinationsFloatNavType : DestinationsNavType() { when (val bundleValue = floatToBundleValue(value)) { is Byte -> bundle.putByte(key, bundleValue) is Float -> bundle.putFloat(key, bundleValue) - else -> error("Unexpected type ${bundleValue.javaClass}") + else -> error("Unexpected type ${bundleValue::class}") } } diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/DestinationsIntNavType.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/DestinationsIntNavType.kt similarity index 93% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/DestinationsIntNavType.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/DestinationsIntNavType.kt index 2186c8fc..917bc9c3 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/DestinationsIntNavType.kt +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/DestinationsIntNavType.kt @@ -1,6 +1,6 @@ package com.ramcosta.composedestinations.navargs.primitives -import android.os.Bundle +import androidx.core.bundle.Bundle import androidx.lifecycle.SavedStateHandle import com.ramcosta.composedestinations.navargs.DestinationsNavType @@ -10,7 +10,7 @@ object DestinationsIntNavType : DestinationsNavType() { when (val bundleValue = intToBundleValue(value)) { is Byte -> bundle.putByte(key, bundleValue) is Int -> bundle.putInt(key, bundleValue) - else -> error("Unexpected type ${bundleValue.javaClass}") + else -> error("Unexpected type ${bundleValue::class}") } } diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/DestinationsLongNavType.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/DestinationsLongNavType.kt similarity index 93% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/DestinationsLongNavType.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/DestinationsLongNavType.kt index 37e72dbf..bf41c0ba 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/DestinationsLongNavType.kt +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/DestinationsLongNavType.kt @@ -1,6 +1,6 @@ package com.ramcosta.composedestinations.navargs.primitives -import android.os.Bundle +import androidx.core.bundle.Bundle import androidx.lifecycle.SavedStateHandle import com.ramcosta.composedestinations.navargs.DestinationsNavType @@ -10,7 +10,7 @@ object DestinationsLongNavType : DestinationsNavType() { when (val bundleValue = longToBundleValue(value)) { is Byte -> bundle.putByte(key, bundleValue) is Long -> bundle.putLong(key, bundleValue) - else -> error("Unexpected type ${bundleValue.javaClass}") + else -> error("Unexpected type ${bundleValue::class}") } } diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/DestinationsStringNavType.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/DestinationsStringNavType.kt similarity index 98% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/DestinationsStringNavType.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/DestinationsStringNavType.kt index bc361142..ea47ae12 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/DestinationsStringNavType.kt +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/DestinationsStringNavType.kt @@ -1,6 +1,6 @@ package com.ramcosta.composedestinations.navargs.primitives -import android.os.Bundle +import androidx.core.bundle.Bundle import androidx.lifecycle.SavedStateHandle import com.ramcosta.composedestinations.navargs.DestinationsNavType import com.ramcosta.composedestinations.navargs.utils.encodeForRoute diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsBooleanArrayNavType.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsBooleanArrayNavType.kt similarity index 98% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsBooleanArrayNavType.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsBooleanArrayNavType.kt index 9bd7a735..658574c1 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsBooleanArrayNavType.kt +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsBooleanArrayNavType.kt @@ -1,6 +1,6 @@ package com.ramcosta.composedestinations.navargs.primitives.array -import android.os.Bundle +import androidx.core.bundle.Bundle import androidx.lifecycle.SavedStateHandle import com.ramcosta.composedestinations.navargs.DestinationsNavType import com.ramcosta.composedestinations.navargs.primitives.DECODED_NULL diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsEnumArrayNavType.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsEnumArrayNavType.kt similarity index 83% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsEnumArrayNavType.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsEnumArrayNavType.kt index 10e2b1f0..7f4aea0d 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsEnumArrayNavType.kt +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsEnumArrayNavType.kt @@ -1,24 +1,22 @@ package com.ramcosta.composedestinations.navargs.primitives.array -import android.os.Bundle +import androidx.core.bundle.Bundle import androidx.lifecycle.SavedStateHandle import com.ramcosta.composedestinations.navargs.DestinationsNavType import com.ramcosta.composedestinations.navargs.primitives.DECODED_NULL import com.ramcosta.composedestinations.navargs.primitives.ENCODED_NULL import com.ramcosta.composedestinations.navargs.primitives.encodedComma -@Suppress("UNCHECKED_CAST") class DestinationsEnumArrayNavType>( private val converter: (List) -> Array ) : DestinationsNavType?>() { override fun put(bundle: Bundle, key: String, value: Array?) { - bundle.putSerializable(key, value) + bundle.putString(key, serializeValue(value)) } override fun get(bundle: Bundle, key: String): Array? { - @Suppress("DEPRECATION") - return bundle.getSerializable(key) as Array? + return bundle.getString(key)?.let { parseValue(it) } } override fun parseValue(value: String): Array? { @@ -42,11 +40,11 @@ class DestinationsEnumArrayNavType>( } override fun get(savedStateHandle: SavedStateHandle, key: String): Array? { - return savedStateHandle[key] + return savedStateHandle.get(key)?.let { parseValue(it) } } override fun put(savedStateHandle: SavedStateHandle, key: String, value: Array?) { - savedStateHandle[key] = value + savedStateHandle[key] = value?.let { serializeValue(it) } } } \ No newline at end of file diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsFloatArrayNavType.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsFloatArrayNavType.kt similarity index 97% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsFloatArrayNavType.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsFloatArrayNavType.kt index 984b4f51..907cc32f 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsFloatArrayNavType.kt +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsFloatArrayNavType.kt @@ -1,6 +1,6 @@ package com.ramcosta.composedestinations.navargs.primitives.array -import android.os.Bundle +import androidx.core.bundle.Bundle import androidx.lifecycle.SavedStateHandle import com.ramcosta.composedestinations.navargs.DestinationsNavType import com.ramcosta.composedestinations.navargs.primitives.DECODED_NULL diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsIntArrayNavType.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsIntArrayNavType.kt similarity index 97% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsIntArrayNavType.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsIntArrayNavType.kt index a2b73cf7..d9055838 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsIntArrayNavType.kt +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsIntArrayNavType.kt @@ -1,6 +1,6 @@ package com.ramcosta.composedestinations.navargs.primitives.array -import android.os.Bundle +import androidx.core.bundle.Bundle import androidx.lifecycle.SavedStateHandle import com.ramcosta.composedestinations.navargs.DestinationsNavType import com.ramcosta.composedestinations.navargs.primitives.DECODED_NULL diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsLongArrayNavType.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsLongArrayNavType.kt similarity index 97% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsLongArrayNavType.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsLongArrayNavType.kt index 6964318b..4b7293a8 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsLongArrayNavType.kt +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsLongArrayNavType.kt @@ -1,6 +1,6 @@ package com.ramcosta.composedestinations.navargs.primitives.array -import android.os.Bundle +import androidx.core.bundle.Bundle import androidx.lifecycle.SavedStateHandle import com.ramcosta.composedestinations.navargs.DestinationsNavType import com.ramcosta.composedestinations.navargs.primitives.DECODED_NULL diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsStringArrayNavType.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsStringArrayNavType.kt similarity index 98% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsStringArrayNavType.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsStringArrayNavType.kt index 2109efb8..d4e33547 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsStringArrayNavType.kt +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/array/DestinationsStringArrayNavType.kt @@ -1,6 +1,6 @@ package com.ramcosta.composedestinations.navargs.primitives.array -import android.os.Bundle +import androidx.core.bundle.Bundle import androidx.lifecycle.SavedStateHandle import com.ramcosta.composedestinations.navargs.DestinationsNavType import com.ramcosta.composedestinations.navargs.primitives.DECODED_NULL diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsBooleanArrayListNavType.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsBooleanArrayListNavType.kt similarity index 98% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsBooleanArrayListNavType.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsBooleanArrayListNavType.kt index d35abf5e..b22f097e 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsBooleanArrayListNavType.kt +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsBooleanArrayListNavType.kt @@ -1,6 +1,6 @@ package com.ramcosta.composedestinations.navargs.primitives.arraylist -import android.os.Bundle +import androidx.core.bundle.Bundle import androidx.lifecycle.SavedStateHandle import com.ramcosta.composedestinations.navargs.DestinationsNavType import com.ramcosta.composedestinations.navargs.primitives.DECODED_NULL diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsEnumArrayListNavType.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsEnumArrayListNavType.kt similarity index 73% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsEnumArrayListNavType.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsEnumArrayListNavType.kt index b009aaa2..20230383 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsEnumArrayListNavType.kt +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsEnumArrayListNavType.kt @@ -1,25 +1,22 @@ package com.ramcosta.composedestinations.navargs.primitives.arraylist -import android.os.Bundle +import androidx.core.bundle.Bundle import androidx.lifecycle.SavedStateHandle import com.ramcosta.composedestinations.navargs.DestinationsNavType import com.ramcosta.composedestinations.navargs.primitives.DECODED_NULL import com.ramcosta.composedestinations.navargs.primitives.ENCODED_NULL import com.ramcosta.composedestinations.navargs.primitives.encodedComma -import com.ramcosta.composedestinations.navargs.primitives.valueOfIgnoreCase -@Suppress("UNCHECKED_CAST") class DestinationsEnumArrayListNavType>( - private val enumType: Class + private val converter: (String) -> E ) : DestinationsNavType?>() { override fun put(bundle: Bundle, key: String, value: ArrayList?) { - bundle.putSerializable(key, value) + bundle.putString(key, serializeValue(value)) } override fun get(bundle: Bundle, key: String): ArrayList? { - @Suppress("DEPRECATION") - return bundle.getSerializable(key) as ArrayList? + return bundle.getString(key)?.let { parseValue(it) } } override fun parseValue(value: String): ArrayList? { @@ -28,11 +25,13 @@ class DestinationsEnumArrayListNavType>( if (value == "[]") return arrayListOf() val contentValue = value.subSequence(1, value.length - 1) - return if (contentValue.contains(encodedComma)) { + val splits = if (contentValue.contains(encodedComma)) { contentValue.split(encodedComma) } else { contentValue.split(",") - }.mapTo(ArrayList()) { enumType.valueOfIgnoreCase(it) } + } + + return splits.mapTo(arrayListOf(), converter) } override fun serializeValue(value: ArrayList?): String { @@ -41,10 +40,10 @@ class DestinationsEnumArrayListNavType>( } override fun get(savedStateHandle: SavedStateHandle, key: String): ArrayList? { - return savedStateHandle[key] + return savedStateHandle.get(key)?.let { parseValue(it) } } override fun put(savedStateHandle: SavedStateHandle, key: String, value: ArrayList?) { - savedStateHandle[key] = value + savedStateHandle[key] = value?.let { serializeValue(it) } } } diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsFloatArrayListNavType.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsFloatArrayListNavType.kt similarity index 98% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsFloatArrayListNavType.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsFloatArrayListNavType.kt index 418ca804..5a6464ae 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsFloatArrayListNavType.kt +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsFloatArrayListNavType.kt @@ -1,6 +1,6 @@ package com.ramcosta.composedestinations.navargs.primitives.arraylist -import android.os.Bundle +import androidx.core.bundle.Bundle import androidx.lifecycle.SavedStateHandle import com.ramcosta.composedestinations.navargs.DestinationsNavType import com.ramcosta.composedestinations.navargs.primitives.DECODED_NULL diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsIntArrayListNavType.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsIntArrayListNavType.kt similarity index 97% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsIntArrayListNavType.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsIntArrayListNavType.kt index 89b6eadc..c4211bc4 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsIntArrayListNavType.kt +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsIntArrayListNavType.kt @@ -1,6 +1,6 @@ package com.ramcosta.composedestinations.navargs.primitives.arraylist -import android.os.Bundle +import androidx.core.bundle.Bundle import androidx.lifecycle.SavedStateHandle import com.ramcosta.composedestinations.navargs.DestinationsNavType import com.ramcosta.composedestinations.navargs.primitives.DECODED_NULL diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsLongArrayListNavType.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsLongArrayListNavType.kt similarity index 98% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsLongArrayListNavType.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsLongArrayListNavType.kt index 1faf07e6..e16df18a 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsLongArrayListNavType.kt +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsLongArrayListNavType.kt @@ -1,6 +1,6 @@ package com.ramcosta.composedestinations.navargs.primitives.arraylist -import android.os.Bundle +import androidx.core.bundle.Bundle import androidx.lifecycle.SavedStateHandle import com.ramcosta.composedestinations.navargs.DestinationsNavType import com.ramcosta.composedestinations.navargs.primitives.DECODED_NULL diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsStringArrayListNavType.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsStringArrayListNavType.kt similarity index 98% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsStringArrayListNavType.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsStringArrayListNavType.kt index 0bb559d1..5f2cad23 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsStringArrayListNavType.kt +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/primitives/arraylist/DestinationsStringArrayListNavType.kt @@ -1,6 +1,6 @@ package com.ramcosta.composedestinations.navargs.primitives.arraylist -import android.os.Bundle +import androidx.core.bundle.Bundle import androidx.lifecycle.SavedStateHandle import com.ramcosta.composedestinations.navargs.DestinationsNavType import com.ramcosta.composedestinations.navargs.primitives.DECODED_NULL diff --git a/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/utils/NavArgEncodingUtils.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/utils/NavArgEncodingUtils.kt new file mode 100644 index 00000000..c76d63a3 --- /dev/null +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navargs/utils/NavArgEncodingUtils.kt @@ -0,0 +1,7 @@ +package com.ramcosta.composedestinations.navargs.utils + +expect fun encodeForRoute(arg: String): String + +expect fun String.base64ToByteArray(): ByteArray + +expect fun ByteArray.toBase64Str(): String diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navigation/DestinationDependenciesContainer.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navigation/DestinationDependenciesContainer.kt similarity index 90% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/navigation/DestinationDependenciesContainer.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navigation/DestinationDependenciesContainer.kt index 8e380c2c..113f851f 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navigation/DestinationDependenciesContainer.kt +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navigation/DestinationDependenciesContainer.kt @@ -1,6 +1,5 @@ package com.ramcosta.composedestinations.navigation -import android.annotation.SuppressLint import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import com.ramcosta.composedestinations.scope.DestinationScopeWithNoDependencies @@ -32,7 +31,6 @@ inline fun DependenciesContainerBuilder.dependency(depen * navigated to, giving an opportunity to specify dependencies with [dependency] method * that are supposed to be used only by destinations of that [navGraph]. */ -@SuppressLint("ComposableNaming") @Composable inline fun DependenciesContainerBuilder.navGraph( navGraph: NavGraphSpec, @@ -54,7 +52,6 @@ inline fun DependenciesContainerBuilder.navGraph( * giving an opportunity to specify dependencies with [dependency] method * that are supposed to be used only by that [destination]. */ -@SuppressLint("ComposableNaming") @Composable inline fun DependenciesContainerBuilder.destination( destination: DestinationSpec, @@ -101,10 +98,10 @@ internal class DestinationDependenciesContainerImpl( DependenciesContainerBuilder, DestinationScopeWithNoDependencies by destinationScope { - private val map: MutableMap, Any> = mutableMapOf() + private val map: MutableMap, Any> = mutableMapOf() fun dependency(dependency: D, asType: KClass) { - map[asType.java] = dependency + map[asType] = dependency } inline fun require( @@ -115,11 +112,11 @@ internal class DestinationDependenciesContainerImpl( @Suppress("UNCHECKED_CAST") fun require(type: KClass, isMarkedNavHostParam: Boolean): D { - var depForType: D? = map[type.java] as? D + var depForType: D? = map[type] as? D if (depForType == null) { depForType = map.values.firstOrNull { - type.java.isAssignableFrom(it.javaClass) + type.isInstance(it) // TODO RACOSTA check } as? D depForType?.let { @@ -131,10 +128,10 @@ internal class DestinationDependenciesContainerImpl( return depForType ?: throw RuntimeException( if (isMarkedNavHostParam) { - "${type.java.simpleName} was requested and it is marked with @NavHostParam but it " + + "${type.simpleName} was requested and it is marked with @NavHostParam but it " + "was not provided via dependency container" } else { - "${type.java.simpleName} was requested, but it is not present" + "${type.simpleName} was requested, but it is not present" } ) } diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navigation/DestinationsNavController.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navigation/DestinationsNavController.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/navigation/DestinationsNavController.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navigation/DestinationsNavController.kt diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navigation/DestinationsNavOptionsBuilder.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navigation/DestinationsNavOptionsBuilder.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/navigation/DestinationsNavOptionsBuilder.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navigation/DestinationsNavOptionsBuilder.kt diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navigation/DestinationsNavigator.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navigation/DestinationsNavigator.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/navigation/DestinationsNavigator.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navigation/DestinationsNavigator.kt diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navigation/EmptyDestinationsNavigator.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navigation/EmptyDestinationsNavigator.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/navigation/EmptyDestinationsNavigator.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/navigation/EmptyDestinationsNavigator.kt diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/result/EmptyResultBackNavigator.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/result/EmptyResultBackNavigator.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/result/EmptyResultBackNavigator.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/result/EmptyResultBackNavigator.kt diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/result/EmptyResultRecipient.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/result/EmptyResultRecipient.kt similarity index 84% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/result/EmptyResultRecipient.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/result/EmptyResultRecipient.kt index 9153fecd..c79004c4 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/result/EmptyResultRecipient.kt +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/result/EmptyResultRecipient.kt @@ -1,7 +1,5 @@ -@file:SuppressLint("ComposableNaming") package com.ramcosta.composedestinations.result -import android.annotation.SuppressLint import androidx.compose.runtime.Composable import com.ramcosta.composedestinations.spec.DestinationSpec diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/result/NavResult.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/result/NavResult.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/result/NavResult.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/result/NavResult.kt diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/result/OpenResultRecipient.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/result/OpenResultRecipient.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/result/OpenResultRecipient.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/result/OpenResultRecipient.kt diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/result/ResultBackNavigator.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/result/ResultBackNavigator.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/result/ResultBackNavigator.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/result/ResultBackNavigator.kt diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/result/ResultBackNavigatorImpl.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/result/ResultBackNavigatorImpl.kt similarity index 92% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/result/ResultBackNavigatorImpl.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/result/ResultBackNavigatorImpl.kt index cee9aaf5..739e607d 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/result/ResultBackNavigatorImpl.kt +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/result/ResultBackNavigatorImpl.kt @@ -1,6 +1,5 @@ package com.ramcosta.composedestinations.result -import android.annotation.SuppressLint import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.remember @@ -9,11 +8,12 @@ import androidx.lifecycle.LifecycleEventObserver import androidx.lifecycle.LifecycleOwner import androidx.navigation.NavController import com.ramcosta.composedestinations.spec.DestinationSpec +import kotlin.reflect.KClass -internal class ResultBackNavigatorImpl( +internal class ResultBackNavigatorImpl( private val navController: NavController, - resultOriginType: Class, - resultType: Class + resultOriginType: KClass, + resultType: KClass ) : ResultBackNavigator { private val resultKey = resultKey(resultOriginType, resultType) @@ -35,7 +35,6 @@ internal class ResultBackNavigatorImpl( navController.navigateUp() } - @SuppressLint("ComposableNaming") @Composable fun handleCanceled() { val currentNavBackStackEntry = remember { navController.currentBackStackEntry } ?: return diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/result/ResultCommons.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/result/ResultCommons.kt similarity index 59% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/result/ResultCommons.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/result/ResultCommons.kt index c53a8374..2f7fae9d 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/result/ResultCommons.kt +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/result/ResultCommons.kt @@ -6,23 +6,24 @@ import androidx.navigation.NavBackStackEntry import androidx.navigation.NavController import com.ramcosta.composedestinations.spec.DestinationSpec import com.ramcosta.composedestinations.spec.ExternalRoute +import kotlin.reflect.KClass @Composable @PublishedApi -internal fun resultBackNavigator( +internal fun resultBackNavigator( destination: DestinationSpec, - resultType: Class, + resultType: KClass, navController: NavController, navBackStackEntry: NavBackStackEntry ): ResultBackNavigator { val backNavigator = remember(navController, navBackStackEntry, destination, resultType) { - ResultBackNavigatorImpl( + ResultBackNavigatorImpl( navController = navController, resultOriginType = if (destination is ExternalRoute) { - (destination.original as DestinationSpec).javaClass + (destination.original as DestinationSpec)::class } else { - destination.javaClass + destination::class }, resultType = resultType ) @@ -35,10 +36,10 @@ internal fun resultBackNavigator( @Composable @PublishedApi -internal fun resultRecipient( +internal fun resultRecipient( navBackStackEntry: NavBackStackEntry, - originType: Class, - resultType: Class + originType: KClass, + resultType: KClass ): ResultRecipient = remember(navBackStackEntry, originType, resultType) { ResultRecipientImpl( navBackStackEntry = navBackStackEntry, @@ -47,12 +48,12 @@ internal fun resultRecipient( ) } -internal fun resultKey( - resultOriginType: Class, - resultType: Class -) = "compose-destinations@${resultOriginType.name}@${resultType.name}@result" +internal fun resultKey( + resultOriginType: KClass, + resultType: KClass +) = "compose-destinations@${resultOriginType.qualifiedName}@${resultType.qualifiedName}@result" -internal fun canceledKey( - resultOriginType: Class, - resultType: Class -) = "compose-destinations@${resultOriginType.name}@${resultType.name}@canceled" \ No newline at end of file +internal fun canceledKey( + resultOriginType: KClass, + resultType: KClass +) = "compose-destinations@${resultOriginType.qualifiedName}@${resultType.qualifiedName}@canceled" \ No newline at end of file diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/result/ResultRecipient.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/result/ResultRecipient.kt similarity index 94% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/result/ResultRecipient.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/result/ResultRecipient.kt index 7fe380e8..83ac1c78 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/result/ResultRecipient.kt +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/result/ResultRecipient.kt @@ -1,9 +1,5 @@ -@file:SuppressLint("ComposableNaming") -@file:Suppress("UNCHECKED_CAST") - package com.ramcosta.composedestinations.result -import android.annotation.SuppressLint import androidx.compose.runtime.Composable import androidx.compose.runtime.DisallowComposableCalls import com.ramcosta.composedestinations.spec.DestinationSpec diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/result/ResultRecipientImpl.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/result/ResultRecipientImpl.kt similarity index 91% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/result/ResultRecipientImpl.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/result/ResultRecipientImpl.kt index f06029ab..6a0f3d7d 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/result/ResultRecipientImpl.kt +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/result/ResultRecipientImpl.kt @@ -1,9 +1,5 @@ -@file:SuppressLint("ComposableNaming") -@file:Suppress("UNCHECKED_CAST") - package com.ramcosta.composedestinations.result -import android.annotation.SuppressLint import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.getValue @@ -13,11 +9,12 @@ import androidx.lifecycle.LifecycleEventObserver import androidx.lifecycle.LifecycleOwner import androidx.navigation.NavBackStackEntry import com.ramcosta.composedestinations.spec.DestinationSpec +import kotlin.reflect.KClass -internal class ResultRecipientImpl( +internal class ResultRecipientImpl( private val navBackStackEntry: NavBackStackEntry, - resultOriginType: Class, - resultType: Class, + resultOriginType: KClass, + resultType: KClass, ) : ResultRecipient { private val resultKey = resultKey(resultOriginType, resultType) @@ -63,6 +60,7 @@ internal class ResultRecipientImpl( if (canceled == true) { listener(NavResult.Canceled) } else if (navBackStackEntry.savedStateHandle.contains(resultKey)) { + @Suppress("UNCHECKED_CAST") listener( NavResult.Value( navBackStackEntry.savedStateHandle.remove(resultKey) as R diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/scope/DestinationScope.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/scope/DestinationScope.kt similarity index 88% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/scope/DestinationScope.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/scope/DestinationScope.kt index 88de20b3..a15aaf09 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/scope/DestinationScope.kt +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/scope/DestinationScope.kt @@ -63,15 +63,15 @@ interface DestinationScope: DestinationScopeWithNoDependencies { * Returns a well typed [ResultBackNavigator] for this [DestinationScope] */ @Composable -inline fun DestinationScopeWithNoDependencies<*>.resultBackNavigator(): ResultBackNavigator = - resultBackNavigator(destination, R::class.java, navController, navBackStackEntry) +inline fun DestinationScopeWithNoDependencies<*>.resultBackNavigator(): ResultBackNavigator = + resultBackNavigator(destination, A::class, navController, navBackStackEntry) /** * Returns a well typed [ResultRecipient] for this [DestinationScope] */ @Composable -inline fun DestinationScopeWithNoDependencies<*>.resultRecipient(): ResultRecipient = - resultRecipient(navBackStackEntry, D::class.java, R::class.java) +inline fun DestinationScopeWithNoDependencies<*>.resultRecipient(): ResultRecipient = + resultRecipient(navBackStackEntry, D::class, A::class) /** * Like [DestinationScope] but also [AnimatedVisibilityScope] so that diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/scope/DestinationScopeInternals.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/scope/DestinationScopeInternals.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/scope/DestinationScopeInternals.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/scope/DestinationScopeInternals.kt diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/scope/DestinationScopeWithNoDependencies.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/scope/DestinationScopeWithNoDependencies.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/scope/DestinationScopeWithNoDependencies.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/scope/DestinationScopeWithNoDependencies.kt diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/scope/NavGraphBuilderDestinationScope.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/scope/NavGraphBuilderDestinationScope.kt similarity index 86% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/scope/NavGraphBuilderDestinationScope.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/scope/NavGraphBuilderDestinationScope.kt index 394ce8a5..fb2da657 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/scope/NavGraphBuilderDestinationScope.kt +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/scope/NavGraphBuilderDestinationScope.kt @@ -43,18 +43,18 @@ interface NavGraphBuilderDestinationScope { * Returns a well typed [ResultBackNavigator] for this [NavGraphBuilderDestinationScope] */ @Composable -inline fun NavGraphBuilderDestinationScope<*>.resultBackNavigator( +inline fun NavGraphBuilderDestinationScope<*>.resultBackNavigator( navController: NavController ): ResultBackNavigator = - resultBackNavigator(destination, R::class.java, navController, navBackStackEntry) + resultBackNavigator(destination, A::class, navController, navBackStackEntry) /** * Returns a well typed [ResultRecipient] for this [NavGraphBuilderDestinationScope] */ @Composable -inline fun NavGraphBuilderDestinationScope<*>.resultRecipient(): ResultRecipient = - resultRecipient(navBackStackEntry, D::class.java, R::class.java) +inline fun NavGraphBuilderDestinationScope<*>.resultRecipient(): ResultRecipient = + resultRecipient(navBackStackEntry, D::class, A::class) /** * Like [NavGraphBuilderDestinationScope] but also [AnimatedVisibilityScope] so that diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/BaseRoute.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/spec/BaseRoute.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/BaseRoute.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/spec/BaseRoute.kt diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/DestinationSpec.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/spec/DestinationSpec.kt similarity index 98% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/DestinationSpec.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/spec/DestinationSpec.kt index def00a75..72bed375 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/DestinationSpec.kt +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/spec/DestinationSpec.kt @@ -1,7 +1,7 @@ package com.ramcosta.composedestinations.spec -import android.os.Bundle import androidx.compose.runtime.Composable +import androidx.core.bundle.Bundle import androidx.lifecycle.SavedStateHandle import androidx.navigation.NavBackStackEntry import com.ramcosta.composedestinations.scope.DestinationScope diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/DestinationStyle.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/spec/DestinationStyle.kt similarity index 82% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/DestinationStyle.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/spec/DestinationStyle.kt index 36697844..9124a892 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/DestinationStyle.kt +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/spec/DestinationStyle.kt @@ -11,10 +11,8 @@ import androidx.compose.ui.window.DialogProperties import androidx.navigation.NavBackStackEntry import androidx.navigation.NavGraphBuilder import androidx.navigation.NavHostController -import androidx.navigation.activity import androidx.navigation.compose.composable import androidx.navigation.compose.dialog -import com.ramcosta.composedestinations.annotation.internal.InternalDestinationsApi import com.ramcosta.composedestinations.manualcomposablecalls.DestinationLambda import com.ramcosta.composedestinations.manualcomposablecalls.ManualComposableCalls import com.ramcosta.composedestinations.manualcomposablecalls.allDeepLinks @@ -168,52 +166,6 @@ abstract class DestinationStyle { } } } - - @InternalDestinationsApi - object Activity: DestinationStyle() { - override fun NavGraphBuilder.addComposable( - destination: TypedDestinationSpec, - navController: NavHostController, - dependenciesContainerBuilder: @Composable DependenciesContainerBuilder<*>.() -> Unit, - manualComposableCalls: ManualComposableCalls - ) { - destination as ActivityDestinationSpec - - addComposable(destination, manualComposableCalls) - } - - internal fun NavGraphBuilder.addComposable( - destination: ActivityDestinationSpec, - manualComposableCalls: ManualComposableCalls? = null - ) { - activity(destination.route) { - targetPackage = destination.targetPackage - activityClass = destination.activityClass?.kotlin - action = destination.action - data = destination.data - dataPattern = destination.dataPattern - - destination.allDeepLinks(manualComposableCalls).forEach { deepLink -> - deepLink { - action = deepLink.action - uriPattern = deepLink.uriPattern - mimeType = deepLink.mimeType - } - } - - destination.arguments.forEach { navArg -> - argument(navArg.name) { - if (navArg.argument.isDefaultValuePresent) { - defaultValue = navArg.argument.defaultValue - } - type = navArg.argument.type - nullable = navArg.argument.isNullable - } - } - } - } - - } } @Composable diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/Direction.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/spec/Direction.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/Direction.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/spec/Direction.kt diff --git a/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/spec/DirectionDestinationSpec.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/spec/DirectionDestinationSpec.kt new file mode 100644 index 00000000..4f7b993a --- /dev/null +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/spec/DirectionDestinationSpec.kt @@ -0,0 +1,17 @@ +package com.ramcosta.composedestinations.spec + +import androidx.core.bundle.Bundle +import androidx.lifecycle.SavedStateHandle + +/** + * [TypedDestinationSpec] that does not contain any navigation arguments. + * It itself is a [Direction] + */ +interface DirectionDestinationSpec: TypedDestinationSpec, Direction { + + override fun invoke(navArgs: Unit): Direction = this + + override fun argsFrom(bundle: Bundle?) = Unit + + override fun argsFrom(savedStateHandle: SavedStateHandle) = Unit +} diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/DirectionNavGraphSpec.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/spec/DirectionNavGraphSpec.kt similarity index 94% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/DirectionNavGraphSpec.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/spec/DirectionNavGraphSpec.kt index 58930f41..22f61bc0 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/DirectionNavGraphSpec.kt +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/spec/DirectionNavGraphSpec.kt @@ -1,6 +1,6 @@ package com.ramcosta.composedestinations.spec -import android.os.Bundle +import androidx.core.bundle.Bundle import androidx.lifecycle.SavedStateHandle /** diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/ModuleDestinationsContainer.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/spec/ModuleDestinationsContainer.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/ModuleDestinationsContainer.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/spec/ModuleDestinationsContainer.kt diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/NavGraphSpec.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/spec/NavGraphSpec.kt similarity index 98% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/NavGraphSpec.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/spec/NavGraphSpec.kt index 5d0dc386..a1c3d36d 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/NavGraphSpec.kt +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/spec/NavGraphSpec.kt @@ -1,6 +1,6 @@ package com.ramcosta.composedestinations.spec -import android.os.Bundle +import androidx.core.bundle.Bundle import androidx.lifecycle.SavedStateHandle import androidx.navigation.NavBackStackEntry diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/NavHostEngine.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/spec/NavHostEngine.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/NavHostEngine.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/spec/NavHostEngine.kt diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/NavHostGraphSpec.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/spec/NavHostGraphSpec.kt similarity index 97% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/NavHostGraphSpec.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/spec/NavHostGraphSpec.kt index 09cfeba7..4b9e9df8 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/NavHostGraphSpec.kt +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/spec/NavHostGraphSpec.kt @@ -1,6 +1,6 @@ package com.ramcosta.composedestinations.spec -import android.os.Bundle +import androidx.core.bundle.Bundle import androidx.lifecycle.SavedStateHandle import com.ramcosta.composedestinations.animations.NavHostAnimatedDestinationStyle diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/Route.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/spec/Route.kt similarity index 98% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/Route.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/spec/Route.kt index 1df560ff..9813e21e 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/Route.kt +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/spec/Route.kt @@ -1,6 +1,6 @@ package com.ramcosta.composedestinations.spec -import android.os.Bundle +import androidx.core.bundle.Bundle import androidx.lifecycle.SavedStateHandle import androidx.navigation.NamedNavArgument import androidx.navigation.NavBackStackEntry diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/RouteOrDirection.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/spec/RouteOrDirection.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/RouteOrDirection.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/spec/RouteOrDirection.kt diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/utils/NavControllerExt.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/utils/NavControllerExt.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/utils/NavControllerExt.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/utils/NavControllerExt.kt diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/utils/NavGraphBuilderDestinationExtensions.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/utils/NavGraphBuilderDestinationExtensions.kt similarity index 84% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/utils/NavGraphBuilderDestinationExtensions.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/utils/NavGraphBuilderDestinationExtensions.kt index f2dcef3c..43e2013b 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/utils/NavGraphBuilderDestinationExtensions.kt +++ b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/utils/NavGraphBuilderDestinationExtensions.kt @@ -9,7 +9,6 @@ import com.ramcosta.composedestinations.scope.AnimatedNavGraphBuilderDestination import com.ramcosta.composedestinations.scope.AnimatedNavGraphBuilderDestinationScopeImpl import com.ramcosta.composedestinations.scope.NavGraphBuilderDestinationScope import com.ramcosta.composedestinations.scope.NavGraphBuilderDestinationScopeImpl -import com.ramcosta.composedestinations.spec.ActivityDestinationSpec import com.ramcosta.composedestinations.spec.DestinationSpec import com.ramcosta.composedestinations.spec.DestinationStyle import com.ramcosta.composedestinations.spec.TypedDestinationSpec @@ -81,7 +80,7 @@ fun NavGraphBuilder.composable( throw IllegalArgumentException("You need to use `dialogComposable` for Dialog destinations!") } - is DestinationStyle.Activity -> { + else -> { throw IllegalArgumentException("You need to use `activity` for Activity destinations!") } } @@ -129,24 +128,3 @@ fun NavGraphBuilder.dialogComposable( scope.content() } } - -/** - * Like [androidx.navigation.activity] but accepts - * a [ActivityDestinationSpec] to get the route, arguments and deep links. - * - * Useful if you opt to use [androidx.navigation.compose.NavHost] instead of - * [com.ramcosta.composedestinations.DestinationsNavHost]. - * This way, you can build the navigation graph in the "vanilla compose navigation" way. - * If you do this, you should also disable the `NavGraphs` generation - * in build.gradle: - * ``` - * ksp { - * arg("compose-destinations.generateNavGraphs", "false") - * } - * ``` - */ -fun NavGraphBuilder.activity( - destination: ActivityDestinationSpec, -) = with(destination.style as DestinationStyle.Activity) { - addComposable(destination) -} diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/utils/NavGraphSpecHolder.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/utils/NavGraphSpecHolder.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/utils/NavGraphSpecHolder.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/utils/NavGraphSpecHolder.kt diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/utils/SpecExtensions.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/utils/SpecExtensions.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/utils/SpecExtensions.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/utils/SpecExtensions.kt diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/wrapper/DestinationWrapper.kt b/compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/wrapper/DestinationWrapper.kt similarity index 100% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/wrapper/DestinationWrapper.kt rename to compose-destinations/src/commonMain/kotlin/com/ramcosta/composedestinations/wrapper/DestinationWrapper.kt diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/serializable/DefaultSerializableNavTypeSerializer.kt b/compose-destinations/src/jvmMain/kotlin/com/ramcosta/composedestinations/navargs/serializable/DefaultSerializableNavTypeSerializer.kt similarity index 89% rename from compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/serializable/DefaultSerializableNavTypeSerializer.kt rename to compose-destinations/src/jvmMain/kotlin/com/ramcosta/composedestinations/navargs/serializable/DefaultSerializableNavTypeSerializer.kt index 7992f4a8..32b484ff 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/serializable/DefaultSerializableNavTypeSerializer.kt +++ b/compose-destinations/src/jvmMain/kotlin/com/ramcosta/composedestinations/navargs/serializable/DefaultSerializableNavTypeSerializer.kt @@ -3,7 +3,11 @@ package com.ramcosta.composedestinations.navargs.serializable import com.ramcosta.composedestinations.navargs.DestinationsNavTypeSerializer import com.ramcosta.composedestinations.navargs.utils.base64ToByteArray import com.ramcosta.composedestinations.navargs.utils.toBase64Str -import java.io.* +import java.io.ByteArrayInputStream +import java.io.ByteArrayOutputStream +import java.io.ObjectInputStream +import java.io.ObjectOutputStream +import java.io.Serializable /** * Default [DestinationsNavTypeSerializer] for [Serializable]s which converts them to Base64 strings diff --git a/compose-destinations/src/jvmMain/kotlin/com/ramcosta/composedestinations/navargs/utils/NavArgEncodingUtils.jvm.kt b/compose-destinations/src/jvmMain/kotlin/com/ramcosta/composedestinations/navargs/utils/NavArgEncodingUtils.jvm.kt new file mode 100644 index 00000000..d83b210d --- /dev/null +++ b/compose-destinations/src/jvmMain/kotlin/com/ramcosta/composedestinations/navargs/utils/NavArgEncodingUtils.jvm.kt @@ -0,0 +1,17 @@ +package com.ramcosta.composedestinations.navargs.utils + +import java.net.URLEncoder +import java.nio.charset.StandardCharsets +import java.util.Base64 + +actual fun encodeForRoute(arg: String): String { + return URLEncoder.encode(arg, StandardCharsets.UTF_8.toString()) +} + +actual fun String.base64ToByteArray(): ByteArray { + return Base64.getUrlDecoder().decode(toByteArray(StandardCharsets.UTF_8)) +} + +actual fun ByteArray.toBase64Str(): String { + return Base64.getUrlEncoder().encodeToString(this) +} \ No newline at end of file diff --git a/compose-destinations/src/main/AndroidManifest.xml b/compose-destinations/src/main/AndroidManifest.xml deleted file mode 100644 index a5918e68..00000000 --- a/compose-destinations/src/main/AndroidManifest.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/CommonConstants.kt b/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/CommonConstants.kt deleted file mode 100644 index 41c25c10..00000000 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/primitives/CommonConstants.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.ramcosta.composedestinations.navargs.primitives - -const val ENCODED_NULL = "%02null%03" -const val DECODED_NULL: String = "\u0002null\u0003" - -const val encodedComma = "%2C" - -@Suppress("RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS") -fun > Class.valueOfIgnoreCase(enumValueName: String): E { - return enumConstants.firstOrNull { constant -> - constant.name.equals(enumValueName, ignoreCase = true) - } ?: throw IllegalArgumentException( - "Enum value $enumValueName not found for type ${this.name}." - ) -} \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 115458a5..890725dc 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -6,8 +6,8 @@ targetSdk = "34" kotlin = "1.9.24" dependencyCheckPluginVersion = "0.51.0" -agp = "8.4.0" -mavenPublishPluginVersion = "0.27.0" +agp = "8.2.0" +mavenPublish = "0.27.0" composeViewModel = "2.8.0" activityCompose = "1.9.0" @@ -32,15 +32,16 @@ composeWear = "1.3.0" [plugins] dependencyCheckPlugin = { id = "com.github.ben-manes.versions", version.ref = "dependencyCheckPluginVersion" } +androidLibrary = { id = "com.android.library", version.ref = "agp" } +androidApplication = { id = "com.android.application", version.ref = "agp" } +kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } +kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } +kotlinSerialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } -[libraries] +mavenPublish = { id = "com.vanniktech.maven.publish", version.ref = "mavenPublish" } -# Plugins -kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } -kotlinSerialization = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "kotlin" } -agp = { module = "com.android.tools.build:gradle", version.ref = "agp" } -mavenPublishPlugin = { module = "com.vanniktech:gradle-maven-publish-plugin", version.ref = "mavenPublishPluginVersion" } +[libraries] # Android androidMaterial = { module = "com.google.android.material:material", version.ref = "material" } diff --git a/playground/app/build.gradle.kts b/playground/app/build.gradle.kts index 0f5041d9..b0e5ede4 100644 --- a/playground/app/build.gradle.kts +++ b/playground/app/build.gradle.kts @@ -1,6 +1,6 @@ plugins { - id("com.android.application") - kotlin("android") + alias(libs.plugins.androidApplication) + alias(libs.plugins.kotlinAndroid) id("com.google.devtools.ksp") version libs.versions.ksp.get() kotlin("plugin.parcelize") kotlin("plugin.serialization") diff --git a/playground/app/src/main/java/com/ramcosta/samples/playground/AppNavigation.kt b/playground/app/src/main/java/com/ramcosta/samples/playground/AppNavigation.kt index 76ce023a..3d40b4c0 100644 --- a/playground/app/src/main/java/com/ramcosta/samples/playground/AppNavigation.kt +++ b/playground/app/src/main/java/com/ramcosta/samples/playground/AppNavigation.kt @@ -19,6 +19,7 @@ import androidx.navigation.navigation import com.ramcosta.composedestinations.DestinationsNavHost import com.ramcosta.composedestinations.bottomsheet.utils.bottomSheetComposable import com.ramcosta.composedestinations.manualcomposablecalls.ManualComposableCallsBuilder +import com.ramcosta.composedestinations.manualcomposablecalls.addDeepLink import com.ramcosta.composedestinations.manualcomposablecalls.composable import com.ramcosta.composedestinations.navigation.dependency import com.ramcosta.composedestinations.navigation.destination @@ -87,7 +88,7 @@ fun AppNavigation( } } ) { - TestScreenDestination addDeepLink { uriPattern = "runtimeschema://${TestScreenDestination.route}" } + addDeepLink(TestScreenDestination) { uriPattern = "runtimeschema://${TestScreenDestination.route}" } TestScreenDestination animateWith object: DestinationStyle.Animated() { override val enterTransition: AnimatedContentTransitionScope.() -> EnterTransition = @@ -173,6 +174,7 @@ fun SampleAppAnimatedNavHostExample( id = navArgs.id, asd = navArgs.asd, stuff1 = navArgs.stuff1, + stuffn = navArgs.stuffn, stuff2 = navArgs.stuff2, stuff3 = navArgs.stuff3, stuff5 = navArgs.stuff5, diff --git a/playground/app/src/main/java/com/ramcosta/samples/playground/commons/composables/MyDrawer.kt b/playground/app/src/main/java/com/ramcosta/samples/playground/commons/composables/MyDrawer.kt index d44ba542..9795d9ad 100644 --- a/playground/app/src/main/java/com/ramcosta/samples/playground/commons/composables/MyDrawer.kt +++ b/playground/app/src/main/java/com/ramcosta/samples/playground/commons/composables/MyDrawer.kt @@ -11,6 +11,7 @@ import com.ramcosta.composedestinations.spec.DestinationSpec import com.ramcosta.composedestinations.spec.DirectionDestinationSpec import com.ramcosta.composedestinations.utils.destination import com.ramcosta.composedestinations.utils.startDestination +import com.ramcosta.composedestinations.utils.toDestinationsNavigator import com.ramcosta.samples.playground.commons.DrawerContent import com.ramcosta.samples.playground.ui.screens.NavGraphs import com.ramcosta.samples.playground.ui.screens.destinations.ProfileSettingsProfileSettingsScreenDestination @@ -35,7 +36,7 @@ fun MyDrawer( if (navController.currentBackStackEntry?.lifecycle?.currentState == Lifecycle.State.RESUMED && navController.currentBackStackEntry?.destination() != clickedDestination ) { - navController.navigate(clickedDestination as DirectionDestinationSpec) + navController.toDestinationsNavigator().navigate(clickedDestination as DirectionDestinationSpec) coroutineScope.launch { scaffoldState.drawerState.close() } } } @@ -45,14 +46,14 @@ fun MyDrawer( ProfileSettingsProfileSettingsScreenDestination.DrawerContent( isSelected = destination == ProfileSettingsProfileSettingsScreenDestination, onDestinationClick = { - navController.navigate(ProfileSettingsProfileSettingsScreenDestination(true)) + navController.toDestinationsNavigator().navigate(ProfileSettingsProfileSettingsScreenDestination(true)) } ) RootProfileSettingsScreenDestination.DrawerContent( isSelected = destination == RootProfileSettingsScreenDestination, onDestinationClick = { - navController.navigate(RootProfileSettingsScreenDestination(false)) + navController.toDestinationsNavigator().navigate(RootProfileSettingsScreenDestination(false)) } ) } \ No newline at end of file diff --git a/playground/app/src/main/java/com/ramcosta/samples/playground/ui/screens/TestScreen.kt b/playground/app/src/main/java/com/ramcosta/samples/playground/ui/screens/TestScreen.kt index b70e68d0..4508990e 100644 --- a/playground/app/src/main/java/com/ramcosta/samples/playground/ui/screens/TestScreen.kt +++ b/playground/app/src/main/java/com/ramcosta/samples/playground/ui/screens/TestScreen.kt @@ -60,6 +60,7 @@ fun TestScreen( asd: String, stuff1: ArrayList = arrayListOf(), stuff2: Array?, + @Suppress("UNUSED_PARAMETER") stuffn: ArrayList?, //TODO RACOSTA stuff3: ArrayList? = arrayListOf(), stuff4: SerializableExampleWithNavTypeSerializer? = SerializableExampleWithNavTypeSerializer(), stuff5: Color, diff --git a/playground/app/src/main/java/com/ramcosta/samples/playground/ui/screens/greeting/GreetingScreen.kt b/playground/app/src/main/java/com/ramcosta/samples/playground/ui/screens/greeting/GreetingScreen.kt index 5ea7b587..5bffabf7 100644 --- a/playground/app/src/main/java/com/ramcosta/samples/playground/ui/screens/greeting/GreetingScreen.kt +++ b/playground/app/src/main/java/com/ramcosta/samples/playground/ui/screens/greeting/GreetingScreen.kt @@ -194,6 +194,7 @@ private fun SharedTransitionScope.GreetingScreenContent( // id = "test-id", asd = "test asd+qwe_-!.~'()*", stuff1 = arrayListOf("%sqwe", "asd", "4", "zxc"), + stuffn = arrayListOf(Stuff.STUFF2, Stuff.STUFF2, Stuff.STUFF1), stuff2 = arrayOf(Stuff.STUFF2, Stuff.STUFF2, Stuff.STUFF1), stuff3 = arrayListOf(Color.Blue, Color.Red, Color.Green, Color.Cyan), stuff5 = Color.DarkGray, diff --git a/playground/app/src/main/java/com/ramcosta/samples/playground/ui/screens/profile/ProfileScreenNavArgs.kt b/playground/app/src/main/java/com/ramcosta/samples/playground/ui/screens/profile/ProfileScreenNavArgs.kt index 221386eb..62e9899b 100644 --- a/playground/app/src/main/java/com/ramcosta/samples/playground/ui/screens/profile/ProfileScreenNavArgs.kt +++ b/playground/app/src/main/java/com/ramcosta/samples/playground/ui/screens/profile/ProfileScreenNavArgs.kt @@ -14,6 +14,8 @@ data class ProfileScreenNavArgs( val source: SomeSource = aSource(), val sourceId: SomeSource.Id? = someSourceId(), val stuff: Stuff = Stuff.STUFF1, + val stuff2: Array = stuffs2(), + val stuff3: ArrayList = stuffs3(), val groupName: String? = DEFAULT_GROUP, val whatever: Int? = 12333, val things: ArgumentThings? = null, @@ -24,6 +26,10 @@ data class ProfileScreenNavArgs( val color: Color ) +fun stuffs3() = arrayListOf(Stuff.STUFF1) + +fun stuffs2() = arrayOf(Stuff.STUFF1) + fun aSource() = SomeSource.ASource(SomeSource.Id("source-id")) fun someSourceId() = SomeSource.Id("source-id") diff --git a/playground/featurex/build.gradle.kts b/playground/featurex/build.gradle.kts index 9e1c4a90..f1db63ed 100644 --- a/playground/featurex/build.gradle.kts +++ b/playground/featurex/build.gradle.kts @@ -1,6 +1,6 @@ plugins { - id("com.android.library") - kotlin("android") + alias(libs.plugins.androidLibrary) + alias(libs.plugins.kotlinAndroid) id("com.google.devtools.ksp") version libs.versions.ksp.get() kotlin("plugin.serialization") } @@ -12,7 +12,6 @@ android { defaultConfig { minSdk = libs.versions.minSdk.get().toIntOrNull() - targetSdk = libs.versions.targetSdk.get().toIntOrNull() testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles.add(File("consumer-rules.pro")) diff --git a/playground/featurey/build.gradle.kts b/playground/featurey/build.gradle.kts index a1264bd8..418f35e2 100644 --- a/playground/featurey/build.gradle.kts +++ b/playground/featurey/build.gradle.kts @@ -1,6 +1,6 @@ plugins { - id("com.android.library") - kotlin("android") + alias(libs.plugins.androidLibrary) + alias(libs.plugins.kotlinAndroid) id("com.google.devtools.ksp") version libs.versions.ksp.get() kotlin("plugin.serialization") } @@ -12,7 +12,6 @@ android { defaultConfig { minSdk = libs.versions.minSdk.get().toIntOrNull() - targetSdk = libs.versions.targetSdk.get().toIntOrNull() testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles.add(File("consumer-rules.pro")) diff --git a/playground/featurey/sub/build.gradle.kts b/playground/featurey/sub/build.gradle.kts index eb14794c..f6d9a607 100644 --- a/playground/featurey/sub/build.gradle.kts +++ b/playground/featurey/sub/build.gradle.kts @@ -1,6 +1,6 @@ plugins { - id("com.android.library") - kotlin("android") + alias(libs.plugins.androidLibrary) + alias(libs.plugins.kotlinAndroid) id("com.google.devtools.ksp") version libs.versions.ksp.get() kotlin("plugin.serialization") } @@ -12,7 +12,6 @@ android { defaultConfig { minSdk = libs.versions.minSdk.get().toIntOrNull() - targetSdk = libs.versions.targetSdk.get().toIntOrNull() testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles.add(File("consumer-rules.pro")) diff --git a/playground/featurez/build.gradle.kts b/playground/featurez/build.gradle.kts index 9db37b72..3bed87a0 100644 --- a/playground/featurez/build.gradle.kts +++ b/playground/featurez/build.gradle.kts @@ -1,6 +1,6 @@ plugins { - id("com.android.library") - kotlin("android") + alias(libs.plugins.androidLibrary) + alias(libs.plugins.kotlinAndroid) id("com.google.devtools.ksp") version libs.versions.ksp.get() kotlin("plugin.serialization") } @@ -12,7 +12,6 @@ android { defaultConfig { minSdk = libs.versions.minSdk.get().toIntOrNull() - targetSdk = libs.versions.targetSdk.get().toIntOrNull() testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles.add(File("consumer-rules.pro")) diff --git a/publish.gradle b/publish.gradle index b549d03d..cf94100a 100644 --- a/publish.gradle +++ b/publish.gradle @@ -3,7 +3,7 @@ apply plugin: "com.vanniktech.maven.publish" def tag = "git describe --tags --abbrev=0".execute().text.trim() group = "io.github.raamcosta.compose-destinations" -version = tag +version = "local-kmp-1" mavenPublishing { publishToMavenCentral("S01") diff --git a/sample-wear/build.gradle.kts b/sample-wear/build.gradle.kts index b6ed2a90..55d4af85 100644 --- a/sample-wear/build.gradle.kts +++ b/sample-wear/build.gradle.kts @@ -1,6 +1,6 @@ plugins { - id("com.android.application") - kotlin("android") + alias(libs.plugins.androidApplication) + alias(libs.plugins.kotlinAndroid) id("com.google.devtools.ksp") version libs.versions.ksp.get() } diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index ceefb6b3..567c0dc6 100644 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -1,6 +1,6 @@ plugins { - id("com.android.application") - kotlin("android") + alias(libs.plugins.androidApplication) + alias(libs.plugins.kotlinAndroid) id("com.google.devtools.ksp") version libs.versions.ksp.get() } diff --git a/settings.gradle.kts b/settings.gradle.kts index 7695d54e..c60f78a7 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,5 +1,12 @@ +pluginManagement { + repositories { + google() + mavenCentral() + gradlePluginPortal() + } +} + dependencyResolutionManagement { - repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral()