Skip to content

Commit

Permalink
Add new navigation-compose-extended-wear (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
serbelga authored Apr 22, 2024
1 parent 7a8d547 commit 18581f2
Show file tree
Hide file tree
Showing 8 changed files with 188 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ local.properties
/.idea/
/site/
/navigation-compose-extended-annotation/build/
/navigation-compose-extended-wear/build/
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ activityCompose = "1.9.0"
androidCompileSdk = "34"
androidGradlePlugin = "8.3.2"
androidMinSdk = "24"
androidWearMinSdk = "25"
composeBom = "2024.04.01"
composeCompiler = "1.5.11"
composeMultiplatform = "1.6.10-dev1590"
Expand All @@ -23,6 +24,7 @@ navigationCompose = "2.8.0-alpha07"
navigationComposeExtended = "0.6.0"
spotless = "6.25.0"
vanniktechMavenPublishPlugin = "0.28.0"
wearCompose = "1.3.1"

[libraries]
android-gradlePlugin = { group = "com.android.tools.build", name = "gradle", version.ref = "androidGradlePlugin" }
Expand All @@ -33,6 +35,7 @@ androidx-compose-ui = { module = "androidx.compose.ui:ui" }
androidx-core-ktx = { module = "androidx.core:core-ktx", version.ref = "coreKtx" }
androidx-lifecycle-runtime-ktx = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" }
androidx-navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "navigationCompose" }
androidx-wearCompose-navigation = { module = "androidx.wear.compose:compose-navigation", version.ref = "wearCompose" }
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" }
Expand Down
10 changes: 10 additions & 0 deletions navigation-compose-extended-annotation/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ android {
consumerProguardFiles("consumer-rules.pro")
}

buildTypes {
release {
isMinifyEnabled = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}

kotlin {
jvmToolchain(17)
}
Expand Down
46 changes: 46 additions & 0 deletions navigation-compose-extended-wear/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import com.vanniktech.maven.publish.SonatypeHost

plugins {
alias(libs.plugins.androidLibrary)
kotlin("android")
alias(libs.plugins.dokka)
alias(libs.plugins.vanniktechMavenPublish)
id("dev.sergiobelda.gradle.spotless")
}

android {
namespace = "dev.sergiobelda.navigation.compose.extended.wear"
compileSdk = libs.versions.androidCompileSdk.get().toInt()

defaultConfig {
minSdk = libs.versions.androidWearMinSdk.get().toInt()

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}

buildTypes {
release {
isMinifyEnabled = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}

kotlin {
jvmToolchain(17)
}
}

dependencies {
implementation(projects.navigationComposeExtended)
implementation(libs.androidx.wearCompose.navigation)
}

mavenPublishing {
publishToMavenCentral(SonatypeHost.S01, true)

signAllPublications()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2024 Sergio Belda
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dev.sergiobelda.navigation.compose.extended.wear

import androidx.compose.runtime.Composable
import androidx.navigation.NamedNavArgument
import androidx.navigation.NavBackStackEntry
import androidx.navigation.NavDeepLink
import androidx.navigation.NavGraphBuilder
import androidx.wear.compose.navigation.WearNavigator
import androidx.wear.compose.navigation.composable
import dev.sergiobelda.navigation.compose.extended.NavDestination

/**
* Adds the content composable to the [NavGraphBuilder] as a [WearNavigator.Destination].
*
* @param navDestination navigation destination associated with the composable
* @param arguments list of arguments to associate with destination
* @param deepLinks list of deep links to associate with the destinations
* @param content composable for the destination
*/
@Composable
fun NavGraphBuilder.composable(
navDestination: NavDestination<*>,
arguments: List<NamedNavArgument> = navDestination.arguments,
deepLinks: List<NavDeepLink> = navDestination.deepLinks,
content: @Composable (NavBackStackEntry) -> Unit,
) {
composable(
route = navDestination.route,
arguments = arguments,
deepLinks = deepLinks,
content = content,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright 2024 Sergio Belda
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dev.sergiobelda.navigation.compose.extended.wear

import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavHostController
import androidx.wear.compose.navigation.SwipeDismissableNavHost
import androidx.wear.compose.navigation.SwipeDismissableNavHostState
import androidx.wear.compose.navigation.rememberSwipeDismissableNavHostState
import dev.sergiobelda.navigation.compose.extended.NavDestination

/**
* Provides a place in the Compose hierarchy for self-contained navigation to occur,
* with backwards navigation provided by a swipe gesture.
*
* Once this is called, any Composable within the given [NavGraphBuilder] can be navigated to from
* the provided [navController].
*
* The builder passed into this method is [remember]ed. This means that for this NavHost, the
* contents of the builder cannot be changed.
*
* This function wraps [androidx.wear.compose.navigation.SwipeDismissableNavHost].
*
* @param navController The navController for this host
* @param startNavDestination The start [NavDestination]
* @param modifier The modifier to be applied to the layout
* @param userSwipeEnabled [Boolean] Whether swipe-to-dismiss gesture is enabled.
* @param state State containing information about ongoing swipe and animation.
* @param route The route for the graph
* @param builder The builder used to construct the graph
*/
@Composable
fun SwipeDismissableNavHost(
navController: NavHostController,
startNavDestination: NavDestination<*>,
modifier: Modifier = Modifier,
userSwipeEnabled: Boolean = true,
state: SwipeDismissableNavHostState = rememberSwipeDismissableNavHostState(),
route: String? = null,
builder: NavGraphBuilder.() -> Unit,
) {
SwipeDismissableNavHost(
navController = navController,
startDestination = startNavDestination.route,
modifier = modifier,
userSwipeEnabled = userSwipeEnabled,
state = state,
route = route,
builder = builder,
)
}
10 changes: 10 additions & 0 deletions navigation-compose-extended/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ android {
consumerProguardFiles("consumer-rules.pro")
}

buildTypes {
release {
isMinifyEnabled = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}

kotlin {
jvmToolchain(17)
}
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ rootProject.name = "navigation-compose-extended-root"
include(":navigation-compose-extended")
include(":navigation-compose-extended-annotation")
include(":navigation-compose-extended-compiler")
include(":navigation-compose-extended-wear")
include(":sample-app")
include(":sample-app-annotations")

0 comments on commit 18581f2

Please sign in to comment.