Skip to content

Commit

Permalink
Navigation compose multiplatform support for `:navigation-compose-ext…
Browse files Browse the repository at this point in the history
…ended` (#33)
  • Loading branch information
serbelga authored Apr 19, 2024
1 parent 3507db2 commit 7f8e556
Show file tree
Hide file tree
Showing 63 changed files with 658 additions and 345 deletions.
36 changes: 14 additions & 22 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Kotlin code style for this project: "official" or "obsolete":
#Gradle
org.gradle.jvmargs=-Xmx4096M -Dkotlin.daemon.jvm.options\="-Xmx4096M"

#Kotlin
kotlin.code.style=official
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
kotlin.native.useEmbeddableCompilerJar=true
kotlin.mpp.androidSourceSetLayoutVersion=2

#Android
android.useAndroidX=true
android.nonTransitiveRClass=false
android.nonFinalResIds=false

#Compose Multiplatform
org.jetbrains.compose.experimental.uikit.enabled=true

POM_NAME=Navigation Compose Extended
POM_DESCRIPTION=Navigation Compose Extended is a complementary library for AndroidX Jetpack Navigation Compose to improve creation of navigation elements
Expand Down
13 changes: 8 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@ androidGradlePlugin = "8.3.2"
androidMinSdk = "24"
composeBom = "2024.04.01"
composeCompiler = "1.5.11"
composeMultiplatform = "1.6.10-beta01"
coreKtx = "1.13.0"
dokka = "1.9.20"
espressoCore = "3.5.1"
jetbrainsNavigation = "2.8.0-dev1590"
junit = "4.13.2"
junitVersion = "1.1.5"
kotlin = "1.9.23"
kotlinCoroutines = "1.8.0"
kotlinpoet = "1.16.0"
ksp = "1.9.23-1.0.20"
ktlint = "0.50.0"
lifecycleRuntimeKtx = "2.7.0"
navigationCompose = "2.7.7"
material3 = "1.3.0-alpha05"
navigationCompose = "2.8.0-alpha07"
navigationComposeExtended = "0.3.0"
spotless = "6.25.0"
vanniktechMavenPublishPlugin = "0.28.0"
Expand All @@ -24,14 +28,12 @@ vanniktechMavenPublishPlugin = "0.28.0"
android-gradlePlugin = { group = "com.android.tools.build", name = "gradle", version.ref = "androidGradlePlugin" }
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "activityCompose" }
androidx-compose-bom = { module = "androidx.compose:compose-bom", version.ref = "composeBom" }
androidx-compose-material3 = { module = "androidx.compose.material3:material3" }
androidx-compose-material3 = { module = "androidx.compose.material3:material3", version.ref = "material3" }
androidx-compose-ui = { module = "androidx.compose.ui:ui" }
androidx-core-ktx = { module = "androidx.core:core-ktx", version.ref = "coreKtx" }
androidx-espresso-core = { module = "androidx.test.espresso:espresso-core", version.ref = "espressoCore" }
androidx-junit = { module = "androidx.test.ext:junit", version.ref = "junitVersion" }
androidx-lifecycle-runtime-ktx = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" }
androidx-navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "navigationCompose" }
junit = { module = "junit:junit", version.ref = "junit" }
jetbrains-navigation-compose = { module = "org.jetbrains.androidx.navigation:navigation-compose", version.ref = "jetbrainsNavigation" }
kotlin-gradlePlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
ksp-symbolProcessingApi = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp" }
spotless-gradlePlugin = { module = "com.diffplug.spotless:spotless-plugin-gradle", version.ref = "spotless" }
Expand All @@ -41,6 +43,7 @@ squareup-kotlinpoetKsp = { module = "com.squareup:kotlinpoet-ksp", version.ref =
[plugins]
androidApplication = { id = "com.android.application", version.ref = "androidGradlePlugin" }
androidLibrary = { id = "com.android.library", version.ref = "androidGradlePlugin" }
composeMultiplatform = { id = "org.jetbrains.compose", version.ref = "composeMultiplatform" }
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
kotlin = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
Expand Down
53 changes: 33 additions & 20 deletions navigation-compose-extended/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import com.vanniktech.maven.publish.SonatypeHost

plugins {
kotlin("multiplatform")
alias(libs.plugins.composeMultiplatform)
alias(libs.plugins.androidLibrary)
kotlin("android")
id("dev.sergiobelda.gradle.spotless")
alias(libs.plugins.dokka)
alias(libs.plugins.vanniktechMavenPublish)
Expand All @@ -11,6 +12,36 @@ plugins {
group = "dev.sergiobelda.navigation.compose.extended"
version = libs.versions.navigationComposeExtended.get()

kotlin {
androidTarget()
jvm("desktop")
iosX64()
iosArm64()
iosSimulatorArm64()

sourceSets {
val commonMain by getting {
dependencies {
implementation(libs.jetbrains.navigation.compose)
}
}
val commonTest by getting
val androidMain by getting
val androidUnitTest by getting
val desktopMain by getting
val desktopTest by getting
val iosX64Main by getting
val iosArm64Main by getting
val iosSimulatorArm64Main by getting
val iosMain by creating
val iosTest by creating

all {
languageSettings.optIn("kotlin.RequiresOptIn")
}
}
}

android {
namespace = "dev.sergiobelda.navigation.compose.extended"
compileSdk = libs.versions.androidCompileSdk.get().toInt()
Expand All @@ -21,28 +52,10 @@ android {
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}

kotlin {
jvmToolchain(17)
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = libs.versions.composeCompiler.get()
}
}

dependencies {
implementation(libs.androidx.navigation.compose)
}

mavenPublishing {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,20 @@ class NavAction(private val navController: NavHostController) {
navController.navigate(
route = navRoute.route,
navOptions = navOptions {
// Pop up to the start destination of the graph to
// avoid building up a large stack of destinations
// on the back stack as users select items
popUpTo(navController.graph.findStartDestination().id) {
saveState = true
navController.graph.findStartDestination().route?.let {
// Pop up to the start destination of the graph to
// avoid building up a large stack of destinations
// on the back stack as users select items
popUpTo(it) {
saveState = true
}

// Avoid multiple copies of the same destination when
// reselecting the same item
launchSingleTop = true
// Restore state when reselecting a previously selected item
restoreState = true
}
// Avoid multiple copies of the same destination when
// reselecting the same item
launchSingleTop = true
// Restore state when reselecting a previously selected item
restoreState = true
},
navigatorExtras = navigatorExtras,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import androidx.navigation.NavArgumentBuilder
import androidx.navigation.NavBackStackEntry
import androidx.navigation.NavDeepLink
import androidx.navigation.navArgument
import androidx.navigation.navDeepLink

/**
* Represents some Destination in the Navigation graph. It's defined by a
Expand Down Expand Up @@ -56,9 +55,10 @@ abstract class NavDestination<K> where K : NavArgumentKey {
*/
val deepLinks: List<NavDeepLink>
get() = deepLinkUris.map {
navDeepLink {
uriPattern = it + argumentsRoute
}
// navDeepLink {
// uriPattern = it + argumentsRoute
// }
NavDeepLink.Builder().setUriPattern(it + argumentsRoute).build()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import androidx.navigation.compose.dialog
import androidx.navigation.compose.navigation
import kotlin.jvm.JvmSuppressWildcards

/**
* Add the [Composable] to the [NavGraphBuilder]
Expand Down
2 changes: 0 additions & 2 deletions navigation-compose-extended/src/main/AndroidManifest.xml

This file was deleted.

12 changes: 10 additions & 2 deletions sample-app-annotations/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,23 @@

<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="sample" android:host="home" />

<data
android:scheme="sample"
android:host="home" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="sample" android:host="home_secondary" />

<data
android:scheme="sample"
android:host="home_secondary" />
</intent-filter>
</activity>
</application>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ import dev.sergiobelda.navigation.compose.extended.compiler.annotation.NavDestin
fun SettingsScreen(
@NavArgument userId: Int,
@NavArgument(defaultValue = "Default") text: String?, // Set default value for the NavArgument.
@NavArgument(name = "custom-name", defaultValue = "true") result: Boolean, // Set a custom NavArgument name.
@NavArgument(
name = "custom-name",
defaultValue = "true",
) result: Boolean, // Set a custom NavArgument name.
) {
Box(modifier = Modifier.fillMaxSize()) {
Column {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,58 +16,14 @@

package dev.sergiobelda.navigation.compose.extended.sample.annotations.ui.theme

import android.os.Build
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext

private val DarkColorScheme = darkColorScheme(
primary = Purple80,
secondary = PurpleGrey80,
tertiary = Pink80,
)

private val LightColorScheme = lightColorScheme(
primary = Purple40,
secondary = PurpleGrey40,
tertiary = Pink40,

/* Other default colors to override
background = Color(0xFFFFFBFE),
surface = Color(0xFFFFFBFE),
onPrimary = Color.White,
onSecondary = Color.White,
onTertiary = Color.White,
onBackground = Color(0xFF1C1B1F),
onSurface = Color(0xFF1C1B1F),
*/
)

@Composable
fun SampleTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
// Dynamic color is available on Android 12+
dynamicColor: Boolean = true,
content: @Composable () -> Unit,
) {
val colorScheme = when {
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
val context = LocalContext.current
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
}

darkTheme -> DarkColorScheme
else -> LightColorScheme
}

MaterialTheme(
colorScheme = colorScheme,
typography = Typography,
content = content,
)
}

This file was deleted.

Loading

0 comments on commit 7f8e556

Please sign in to comment.