Skip to content

Commit

Permalink
Delete bottomSheet
Browse files Browse the repository at this point in the history
  • Loading branch information
PavelMesicek committed May 9, 2024
1 parent 82e1a06 commit 6c2d672
Show file tree
Hide file tree
Showing 17 changed files with 17 additions and 225 deletions.
3 changes: 0 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,6 @@ dependencies {
implementation(Dependencies.Support.vectordrawable)
implementation(Dependencies.Support.preference)

// Accompanist
implementation(Dependencies.Accompanist.navigationMaterial)

// Compose
implementation(Dependencies.Compose.animation)
implementation(Dependencies.Compose.foundation)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package app.futured.androidprojecttemplate.navigation

import androidx.compose.animation.AnimatedContentScope
import androidx.compose.animation.AnimatedVisibilityScope
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.runtime.Composable
import androidx.compose.ui.window.DialogProperties
import androidx.navigation.NamedNavArgument
Expand All @@ -14,9 +14,6 @@ import androidx.navigation.compose.dialog
import androidx.navigation.navArgument
import app.futured.androidprojecttemplate.ui.screens.detail.DetailScreen
import app.futured.androidprojecttemplate.ui.screens.home.HomeScreen
import app.futured.androidprojecttemplate.ui.screens.info.InfoScreen
import com.google.accompanist.navigation.material.ExperimentalMaterialNavigationApi
import com.google.accompanist.navigation.material.bottomSheet

typealias DestinationArgumentKey = String
typealias DestinationArgumentValue = String
Expand All @@ -26,10 +23,6 @@ internal val screens = listOf(
Destination.Detail,
)

internal val bottomSheetDialogs = listOf(
Destination.Info,
)

internal val dialogs = listOf<Destination>()

sealed class Destination(
Expand Down Expand Up @@ -66,21 +59,14 @@ sealed class Destination(
.withArgument("subtitle", subtitle)
.withArgument("value", value)
}

data object Info : Destination(
route = "info",
destinationScreen = { InfoScreen(navigation = it) },
) {
fun buildRoute() = route
}
}

/**
* Registers provided [destination] as a composable in [NavGraphBuilder].
*/
fun NavGraphBuilder.composableScreen(
destination: Destination,
content: @Composable AnimatedVisibilityScope.(NavBackStackEntry) -> Unit,
content: @Composable AnimatedContentScope.(NavBackStackEntry) -> Unit,
) = composable(
route = destination.route,
arguments = destination.arguments,
Expand All @@ -103,20 +89,6 @@ fun NavGraphBuilder.composableDialog(
content = content,
)

/**
* Registers provided [destination] as a bottomSheet in [NavGraphBuilder].
*/
@OptIn(ExperimentalMaterialNavigationApi::class)
fun NavGraphBuilder.composableBottomSheetDialog(
destination: Destination,
content: @Composable ColumnScope.(backstackEntry: NavBackStackEntry) -> Unit,
) = bottomSheet(
route = destination.route,
arguments = destination.arguments,
deepLinks = destination.deepLinks,
content = content,
)

/**
* Replaces an argument placeholder defined by [key] in
* route string with value provided in [argument].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ interface NavRouter {
fun navigateBack(popUpToDestination: Destination, inclusive: Boolean = false)

fun navigateToDetail(title: String, subtitle: String? = null, value: String? = null)
fun navigateToInfo()

fun <T> navigateBackWithResult(key: String, value: T)
fun <T> setCurrentResult(key: String, value: T)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ class NavRouterImpl(private val navController: NavController) : NavRouter {
override fun navigateToDetail(title: String, subtitle: String?, value: String?) =
Destination.Detail.buildRoute(title, subtitle, value).execute()

override fun navigateToInfo() = Destination.Info.buildRoute().execute()

override fun <T> navigateBackWithResult(key: String, value: T) {
navController.previousBackStackEntry?.savedStateHandle?.also {
it[key] = value
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package app.futured.androidprojecttemplate.ui

import androidx.compose.runtime.Composable
import app.futured.androidprojecttemplate.ui.theme.AppTheme
import com.google.accompanist.navigation.material.ExperimentalMaterialNavigationApi

@OptIn(ExperimentalMaterialNavigationApi::class)
@Composable
fun AppUI() {
AppTheme {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package app.futured.androidprojecttemplate.ui

import androidx.activity.compose.LocalOnBackPressedDispatcherOwner
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.navigation.NavHostController
Expand All @@ -11,53 +9,32 @@ import androidx.navigation.compose.rememberNavController
import app.futured.androidprojecttemplate.navigation.Destination
import app.futured.androidprojecttemplate.navigation.NavRouter
import app.futured.androidprojecttemplate.navigation.NavRouterImpl
import app.futured.androidprojecttemplate.navigation.bottomSheetDialogs
import app.futured.androidprojecttemplate.navigation.composableBottomSheetDialog
import app.futured.androidprojecttemplate.navigation.composableDialog
import app.futured.androidprojecttemplate.navigation.composableScreen
import app.futured.androidprojecttemplate.navigation.dialogs
import app.futured.androidprojecttemplate.navigation.screens
import app.futured.androidprojecttemplate.ui.theme.Grid
import com.google.accompanist.navigation.material.BottomSheetNavigator
import com.google.accompanist.navigation.material.ExperimentalMaterialNavigationApi
import com.google.accompanist.navigation.material.ModalBottomSheetLayout
import com.google.accompanist.navigation.material.rememberBottomSheetNavigator

@OptIn(ExperimentalMaterialNavigationApi::class)
@Composable
fun NavGraph(
bottomSheetNavigator: BottomSheetNavigator = rememberBottomSheetNavigator(),
navController: NavHostController = rememberNavController(bottomSheetNavigator),
navController: NavHostController = rememberNavController(),
navigation: NavRouter = remember { NavRouterImpl(navController) },
) {
LocalOnBackPressedDispatcherOwner.current?.onBackPressedDispatcher?.let {
navController.navigateUp()
}

ModalBottomSheetLayout(
bottomSheetNavigator = bottomSheetNavigator,
sheetShape = RoundedCornerShape(Grid.d3),
sheetElevation = Grid.d4,
sheetBackgroundColor = MaterialTheme.colorScheme.background,
NavHost(
navController = navController,
startDestination = Destination.Home.route,
) {
NavHost(
navController = navController,
startDestination = Destination.Home.route,
) {
// Destinations without navbar at the bottom
screens.forEach { destination ->
composableScreen(destination) { destination.destinationScreen(navigation) }
}

// Bottom sheet dialogs
bottomSheetDialogs.forEach { destination ->
composableBottomSheetDialog(destination) { destination.destinationScreen(navigation) }
}
// Destinations without navbar at the bottom
screens.forEach { destination ->
composableScreen(destination) { destination.destinationScreen(navigation) }
}

// Dialogs
dialogs.forEach { destination ->
composableDialog(destination) { destination.destinationScreen(navigation) }
}
// Dialogs
dialogs.forEach { destination ->
composableDialog(destination) { destination.destinationScreen(navigation) }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ object TEMPLATE {
Column(
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally,
modifier =
Modifier
modifier = Modifier
.fillMaxSize()
.padding(contentPadding),
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@ import app.futured.arkitekt.core.event.Event

sealed class DetailEvents : Event<DetailViewState>()
data object NavigateBackEvent : DetailEvents()

data object NavigateToInfoEvent : DetailEvents()
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@ package app.futured.androidprojecttemplate.ui.screens.detail

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material3.Button
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
Expand All @@ -27,7 +24,6 @@ import app.futured.androidprojecttemplate.tools.arch.onEvent
import app.futured.androidprojecttemplate.tools.compose.ScreenPreviews
import app.futured.androidprojecttemplate.ui.components.AddFloatingActionButton
import app.futured.androidprojecttemplate.ui.components.Showcase
import app.futured.androidprojecttemplate.ui.theme.Grid

@Composable
fun DetailScreen(
Expand All @@ -39,9 +35,6 @@ fun DetailScreen(
onEvent<NavigateBackEvent> {
navigation.popBackStack()
}
onEvent<NavigateToInfoEvent> {
navigation.navigateToInfo()
}
}

Detail.Content(
Expand All @@ -55,8 +48,6 @@ object Detail {
interface Actions {
fun onNavigateBack()

fun onNavigateToInfo()

fun onIncrementCounter()
}

Expand Down Expand Up @@ -96,10 +87,6 @@ object Detail {
.padding(contentPadding),
) {
Text(text = "Detail: $counter")
Spacer(modifier = Modifier.height(Grid.d4))
Button(onClick = { actions.onNavigateToInfo() }) {
Text(text = "Open bottom sheet")
}
}
}
}
Expand All @@ -112,7 +99,6 @@ fun DetailContentPreview() {
Detail.Content(
actions = object : Detail.Actions {
override fun onNavigateBack() = Unit
override fun onNavigateToInfo() = Unit
override fun onIncrementCounter() = Unit
},
counter = 5,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,4 @@ class DetailViewModel @Inject constructor(
override fun onIncrementCounter() {
viewState.counter++
}

override fun onNavigateToInfo() {
sendEvent(NavigateToInfoEvent)
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 6c2d672

Please sign in to comment.