Skip to content

Commit

Permalink
Initial kmp related changes
Browse files Browse the repository at this point in the history
  • Loading branch information
raamcosta committed May 23, 2024
1 parent dca44f5 commit cb09ee1
Show file tree
Hide file tree
Showing 121 changed files with 924 additions and 341 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/artifacts/compose_destinations_desktop_2_1_0_beta07.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/artifacts/compose_destinations_jvm_2_1_0_beta07.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/artifacts/compose_destinations_jvm_local_kmp_1.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 7 additions & 14 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Delete>("clean") {
delete(rootProject.buildDir)
delete(rootProject.layout.buildDirectory)
}

/**
Expand Down
20 changes: 13 additions & 7 deletions compose-destinations-bottom-sheet/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
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"
compileSdk = libs.versions.compileSdk.get().toIntOrNull()

defaultConfig {
minSdk = libs.versions.minSdk.get().toIntOrNull()
targetSdk = libs.versions.targetSdk.get().toIntOrNull()

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles.add(File("consumer-rules.pro"))
Expand All @@ -30,10 +40,6 @@ android {
targetCompatibility = JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}

buildFeatures {
compose = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,7 +31,7 @@ fun <T> ManualComposableCallsBuilder.bottomSheetComposable(
content: @Composable BottomSheetDestinationScope<T>.() -> Unit
) {
validateBottomSheet(destination)

this as ManualComposableCallsBuilderImpl
add(
lambda = DestinationLambda.BottomSheet(content),
destination = destination,
Expand All @@ -40,6 +41,7 @@ fun <T> 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'")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
)

Expand All @@ -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}>"
}
}

Expand Down
5 changes: 2 additions & 3 deletions compose-destinations-wear/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -101,7 +102,7 @@ internal class WearNavHostEngine(
)
}

is DestinationStyle.Activity -> {
is ActivityDestinationStyle -> {
with(defaultNavHostEngine) {
composable(destination, navController, dependenciesContainerBuilder, manualComposableCalls)
}
Expand Down
60 changes: 42 additions & 18 deletions compose-destinations/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,18 +1,57 @@
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"
compileSdk = libs.versions.compileSdk.get().toIntOrNull()

defaultConfig {
minSdk = libs.versions.minSdk.get().toIntOrNull()
targetSdk = libs.versions.targetSdk.get().toIntOrNull()

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles.add(File("consumer-rules.pro"))
Expand All @@ -34,10 +73,6 @@ android {
targetCompatibility = JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}

buildFeatures {
compose = true
}
Expand All @@ -46,14 +81,3 @@ android {
kotlinCompilerExtensionVersion = libs.versions.composeCompiler.get()
}
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
kotlinOptions.freeCompilerArgs += listOf(
"-opt-in=kotlin.RequiresOptIn",
"-opt-in=com.ramcosta.composedestinations.annotation.internal.InternalDestinationsApi"
)
}

dependencies {
api(libs.compose.navigation)
}
4 changes: 4 additions & 0 deletions compose-destinations/src/androidMain/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest>

</manifest>
Original file line number Diff line number Diff line change
@@ -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))
}
Original file line number Diff line number Diff line change
@@ -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<Serializable> {
//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 <T> base64ToSerializable(base64: String): T {
val bytes = base64.base64ToByteArray()
return ObjectInputStream(ByteArrayInputStream(bytes)).use {
it.readObject() as T
}
}
}
Loading

0 comments on commit cb09ee1

Please sign in to comment.