Skip to content

Commit

Permalink
Add NavGraph builders for material3 bottom sheet (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
eygraber authored Nov 17, 2024
1 parent 47ad616 commit 63aa1b8
Show file tree
Hide file tree
Showing 8 changed files with 234 additions and 35 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ buildscript-publish = { module = "com.vanniktech:gradle-maven-publish-plugin", v

compose-lifecycle = { module = "org.jetbrains.androidx.lifecycle:lifecycle-runtime-compose", version.ref = "composeLifecycle" }
compose-navigation = "org.jetbrains.androidx.navigation:navigation-compose:2.8.0-alpha10"
compose-navigationMaterial = "org.jetbrains.compose.material:material-navigation:1.7.0-beta02"
compose-navigationAndroid = "androidx.navigation:navigation-compose:2.8.4"
compose-navigationMaterial3 = "com.eygraber:compose-material3-navigation:0.0.1"

detektEygraber-formatting = { module = "com.eygraber.detekt.rules:formatting", version.ref = "detektEygraber" }
detektEygraber-style = { module = "com.eygraber.detekt.rules:style", version.ref = "detektEygraber" }
Expand Down
148 changes: 145 additions & 3 deletions kotlin-js-store/package-lock.json

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

1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ include(":samples:nav:shared")
include(":samples:nav:wasmJsApp")
include(":vice-core")
include(":vice-nav")
include(":vice-nav-material3")
include(":vice-portal")
include(":vice-sources")

Expand Down
29 changes: 29 additions & 0 deletions vice-nav-material3/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
plugins {
id("com.eygraber.conventions-kotlin-multiplatform")
id("com.eygraber.conventions-android-library")
id("com.eygraber.conventions-compose-jetbrains")
id("com.eygraber.conventions-detekt")
id("com.eygraber.conventions-publish-maven-central")
}

android {
namespace = "com.eygraber.vice.nav.material3"
}

kotlin {
defaultKmpTargets(
project = project,
)

sourceSets {
commonMain.dependencies {
api(projects.viceNav)

api(libs.compose.navigation)
api(libs.compose.navigationMaterial3)

implementation(compose.material3)
implementation(compose.runtime)
}
}
}
3 changes: 3 additions & 0 deletions vice-nav-material3/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
POM_ARTIFACT_ID=vice-nav-material3
POM_NAME=VICE Nav for compose material3 navigation
POM_DESCRIPTION=A VICE integration with Compose Navigation and material3 ModalBottomSheet
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.eygraber.vice.nav.material3

import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ModalBottomSheetDefaults
import androidx.compose.material3.ModalBottomSheetProperties
import androidx.compose.runtime.remember
import androidx.navigation.NamedNavArgument
import androidx.navigation.NavBackStackEntry
import androidx.navigation.NavDeepLink
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavType
import androidx.navigation.toRoute
import com.eygraber.compose.material3.navigation.bottomSheet
import com.eygraber.vice.nav.TypedNavBackStackEntry
import com.eygraber.vice.nav.ViceDestination
import kotlin.jvm.JvmSuppressWildcards
import kotlin.reflect.KType

@ExperimentalMaterial3Api
public fun NavGraphBuilder.viceBottomSheet(
route: String,
arguments: List<NamedNavArgument> = emptyList(),
deepLinks: List<NavDeepLink> = emptyList(),
modalBottomSheetProperties: ModalBottomSheetProperties = ModalBottomSheetDefaults.properties,
skipPartiallyExpanded: Boolean = false,
destinationFactory: (NavBackStackEntry) -> ViceDestination<*, *, *, *>,
) {
bottomSheet(
route = route,
arguments = arguments,
deepLinks = deepLinks,
modalBottomSheetProperties = modalBottomSheetProperties,
skipPartiallyExpanded = skipPartiallyExpanded,
) {
remember(it.id) { destinationFactory(it) }.Vice()
}
}

@ExperimentalMaterial3Api
public inline fun <reified T : Any> NavGraphBuilder.viceBottomSheet(
typeMap: Map<KType, @JvmSuppressWildcards NavType<*>> = emptyMap(),
deepLinks: List<NavDeepLink> = emptyList(),
modalBottomSheetProperties: ModalBottomSheetProperties = ModalBottomSheetDefaults.properties,
skipPartiallyExpanded: Boolean = false,
crossinline destinationFactory: (TypedNavBackStackEntry<T>) -> ViceDestination<*, *, *, *>,
) {
bottomSheet<T>(
typeMap = typeMap,
deepLinks = deepLinks,
modalBottomSheetProperties = modalBottomSheetProperties,
skipPartiallyExpanded = skipPartiallyExpanded,
) {
remember(it.id) { destinationFactory(TypedNavBackStackEntry(it.toRoute<T>(), it)) }.Vice()
}
}
1 change: 0 additions & 1 deletion vice-nav/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ kotlin {
api(projects.viceCore)

api(libs.compose.navigation)
api(libs.compose.navigationMaterial)

implementation(compose.runtime)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import androidx.compose.animation.AnimatedContentTransitionScope
import androidx.compose.animation.EnterTransition
import androidx.compose.animation.ExitTransition
import androidx.compose.animation.SizeTransform
import androidx.compose.material.navigation.bottomSheet
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.remember
import androidx.compose.ui.window.DialogProperties
Expand Down Expand Up @@ -119,32 +118,3 @@ public inline fun <reified T : Any> NavGraphBuilder.viceDialog(
remember(it.id) { destinationFactory(TypedNavBackStackEntry(it.toRoute<T>(), it)) }.Vice()
}
}

public fun NavGraphBuilder.viceBottomSheet(
route: String,
arguments: List<NamedNavArgument> = emptyList(),
deepLinks: List<NavDeepLink> = emptyList(),
destinationFactory: (NavBackStackEntry) -> ViceDestination<*, *, *, *>,
) {
bottomSheet(
route = route,
arguments = arguments,
deepLinks = deepLinks,
) {
remember(it.id) { destinationFactory(it) }.Vice()
}
}

// TODO: Only available starting Compose 1.8.0
// public inline fun <reified T : Any> NavGraphBuilder.viceBottomSheet(
// typeMap: Map<KType, @JvmSuppressWildcards NavType<*>> = emptyMap(),
// deepLinks: List<NavDeepLink> = emptyList(),
// crossinline destinationFactory: (TypedNavBackStackEntry<T>) -> ViceDestination<*, *, *, *>,
// ) {
// bottomSheet<T>(
// typeMap = typeMap,
// deepLinks = deepLinks,
// ) {
// remember(it.id) { destinationFactory(TypedNavBackStackEntry(it.toRoute<T>(), it)) }.Vice()
// }
// }

0 comments on commit 63aa1b8

Please sign in to comment.