-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new
navigation-compose-extended-wear
(#37)
- Loading branch information
Showing
8 changed files
with
188 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
49 changes: 49 additions & 0 deletions
49
...-wear/src/main/kotlin/dev/sergiobelda/navigation/compose/extended/wear/NavGraphBuilder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) | ||
} |
68 changes: 68 additions & 0 deletions
68
...c/main/kotlin/dev/sergiobelda/navigation/compose/extended/wear/SwipeDismissableNavHost.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters