From 6c2d672be34af535e16cac246312a224fc6586f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20M=C4=9Bs=C3=AD=C4=8Dek?= Date: Thu, 9 May 2024 20:14:56 +0200 Subject: [PATCH] Delete bottomSheet --- app/build.gradle.kts | 3 - .../navigation/Destinations.kt | 32 +-------- .../navigation/NavRouter.kt | 1 - .../navigation/NavRouterImpl.kt | 2 - .../tools/extensions/ModifierExtensions.kt | 22 ------ .../androidprojecttemplate/ui/AppUI.kt | 2 - .../androidprojecttemplate/ui/NavGraph.kt | 45 +++--------- .../_templateScreen/_TEMPLATEScreen.kt | 3 +- .../ui/screens/detail/DetailEvents.kt | 2 - .../ui/screens/detail/DetailScreen.kt | 14 ---- .../ui/screens/detail/DetailViewModel.kt | 4 -- .../ui/screens/info/InfoEvent.kt | 7 -- .../ui/screens/info/InfoScreen.kt | 72 ------------------- .../ui/screens/info/InfoViewModel.kt | 14 ---- .../ui/screens/info/InfoViewState.kt | 8 --- buildSrc/src/main/kotlin/Dependencies.kt | 4 -- buildSrc/src/main/kotlin/Versions.kt | 7 +- 17 files changed, 17 insertions(+), 225 deletions(-) delete mode 100644 app/src/main/kotlin/app/futured/androidprojecttemplate/tools/extensions/ModifierExtensions.kt delete mode 100644 app/src/main/kotlin/app/futured/androidprojecttemplate/ui/screens/info/InfoEvent.kt delete mode 100644 app/src/main/kotlin/app/futured/androidprojecttemplate/ui/screens/info/InfoScreen.kt delete mode 100644 app/src/main/kotlin/app/futured/androidprojecttemplate/ui/screens/info/InfoViewModel.kt delete mode 100644 app/src/main/kotlin/app/futured/androidprojecttemplate/ui/screens/info/InfoViewState.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index c11843c..791aad7 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -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) diff --git a/app/src/main/kotlin/app/futured/androidprojecttemplate/navigation/Destinations.kt b/app/src/main/kotlin/app/futured/androidprojecttemplate/navigation/Destinations.kt index 889e3a8..1ee95fa 100644 --- a/app/src/main/kotlin/app/futured/androidprojecttemplate/navigation/Destinations.kt +++ b/app/src/main/kotlin/app/futured/androidprojecttemplate/navigation/Destinations.kt @@ -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 @@ -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 @@ -26,10 +23,6 @@ internal val screens = listOf( Destination.Detail, ) -internal val bottomSheetDialogs = listOf( - Destination.Info, -) - internal val dialogs = listOf() sealed class Destination( @@ -66,13 +59,6 @@ sealed class Destination( .withArgument("subtitle", subtitle) .withArgument("value", value) } - - data object Info : Destination( - route = "info", - destinationScreen = { InfoScreen(navigation = it) }, - ) { - fun buildRoute() = route - } } /** @@ -80,7 +66,7 @@ sealed class Destination( */ fun NavGraphBuilder.composableScreen( destination: Destination, - content: @Composable AnimatedVisibilityScope.(NavBackStackEntry) -> Unit, + content: @Composable AnimatedContentScope.(NavBackStackEntry) -> Unit, ) = composable( route = destination.route, arguments = destination.arguments, @@ -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]. diff --git a/app/src/main/kotlin/app/futured/androidprojecttemplate/navigation/NavRouter.kt b/app/src/main/kotlin/app/futured/androidprojecttemplate/navigation/NavRouter.kt index a6a0b13..e77eee0 100644 --- a/app/src/main/kotlin/app/futured/androidprojecttemplate/navigation/NavRouter.kt +++ b/app/src/main/kotlin/app/futured/androidprojecttemplate/navigation/NavRouter.kt @@ -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 navigateBackWithResult(key: String, value: T) fun setCurrentResult(key: String, value: T) diff --git a/app/src/main/kotlin/app/futured/androidprojecttemplate/navigation/NavRouterImpl.kt b/app/src/main/kotlin/app/futured/androidprojecttemplate/navigation/NavRouterImpl.kt index 5d9dbde..18f66e4 100644 --- a/app/src/main/kotlin/app/futured/androidprojecttemplate/navigation/NavRouterImpl.kt +++ b/app/src/main/kotlin/app/futured/androidprojecttemplate/navigation/NavRouterImpl.kt @@ -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 navigateBackWithResult(key: String, value: T) { navController.previousBackStackEntry?.savedStateHandle?.also { it[key] = value diff --git a/app/src/main/kotlin/app/futured/androidprojecttemplate/tools/extensions/ModifierExtensions.kt b/app/src/main/kotlin/app/futured/androidprojecttemplate/tools/extensions/ModifierExtensions.kt deleted file mode 100644 index 25800d0..0000000 --- a/app/src/main/kotlin/app/futured/androidprojecttemplate/tools/extensions/ModifierExtensions.kt +++ /dev/null @@ -1,22 +0,0 @@ -package app.futured.androidprojecttemplate.tools.extensions - -import android.annotation.SuppressLint -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.heightIn -import androidx.compose.foundation.layout.navigationBarsPadding -import androidx.compose.foundation.layout.wrapContentSize -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.platform.LocalConfiguration -import androidx.compose.ui.unit.Dp -import androidx.compose.ui.unit.dp - -@SuppressLint("ComposeModifierWithoutDefault", "ComposeComposableModifier") -@Composable -fun Modifier.bottomSheetSize( - maxHeight: Dp = LocalConfiguration.current.screenHeightDp.dp, -): Modifier = - fillMaxWidth() - .wrapContentSize() - .heightIn(max = maxHeight) - .navigationBarsPadding() diff --git a/app/src/main/kotlin/app/futured/androidprojecttemplate/ui/AppUI.kt b/app/src/main/kotlin/app/futured/androidprojecttemplate/ui/AppUI.kt index f47e23a..ab0e7c3 100644 --- a/app/src/main/kotlin/app/futured/androidprojecttemplate/ui/AppUI.kt +++ b/app/src/main/kotlin/app/futured/androidprojecttemplate/ui/AppUI.kt @@ -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 { diff --git a/app/src/main/kotlin/app/futured/androidprojecttemplate/ui/NavGraph.kt b/app/src/main/kotlin/app/futured/androidprojecttemplate/ui/NavGraph.kt index 3e80c27..52c9542 100644 --- a/app/src/main/kotlin/app/futured/androidprojecttemplate/ui/NavGraph.kt +++ b/app/src/main/kotlin/app/futured/androidprojecttemplate/ui/NavGraph.kt @@ -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 @@ -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) } } } } diff --git a/app/src/main/kotlin/app/futured/androidprojecttemplate/ui/screens/_templateScreen/_TEMPLATEScreen.kt b/app/src/main/kotlin/app/futured/androidprojecttemplate/ui/screens/_templateScreen/_TEMPLATEScreen.kt index be4678c..e3bdd1a 100644 --- a/app/src/main/kotlin/app/futured/androidprojecttemplate/ui/screens/_templateScreen/_TEMPLATEScreen.kt +++ b/app/src/main/kotlin/app/futured/androidprojecttemplate/ui/screens/_templateScreen/_TEMPLATEScreen.kt @@ -85,8 +85,7 @@ object TEMPLATE { Column( verticalArrangement = Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally, - modifier = - Modifier + modifier = Modifier .fillMaxSize() .padding(contentPadding), ) { diff --git a/app/src/main/kotlin/app/futured/androidprojecttemplate/ui/screens/detail/DetailEvents.kt b/app/src/main/kotlin/app/futured/androidprojecttemplate/ui/screens/detail/DetailEvents.kt index 6449e1d..6dbe139 100644 --- a/app/src/main/kotlin/app/futured/androidprojecttemplate/ui/screens/detail/DetailEvents.kt +++ b/app/src/main/kotlin/app/futured/androidprojecttemplate/ui/screens/detail/DetailEvents.kt @@ -4,5 +4,3 @@ import app.futured.arkitekt.core.event.Event sealed class DetailEvents : Event() data object NavigateBackEvent : DetailEvents() - -data object NavigateToInfoEvent : DetailEvents() diff --git a/app/src/main/kotlin/app/futured/androidprojecttemplate/ui/screens/detail/DetailScreen.kt b/app/src/main/kotlin/app/futured/androidprojecttemplate/ui/screens/detail/DetailScreen.kt index 64c091e..89cefc3 100644 --- a/app/src/main/kotlin/app/futured/androidprojecttemplate/ui/screens/detail/DetailScreen.kt +++ b/app/src/main/kotlin/app/futured/androidprojecttemplate/ui/screens/detail/DetailScreen.kt @@ -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 @@ -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( @@ -39,9 +35,6 @@ fun DetailScreen( onEvent { navigation.popBackStack() } - onEvent { - navigation.navigateToInfo() - } } Detail.Content( @@ -55,8 +48,6 @@ object Detail { interface Actions { fun onNavigateBack() - fun onNavigateToInfo() - fun onIncrementCounter() } @@ -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") - } } } } @@ -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, diff --git a/app/src/main/kotlin/app/futured/androidprojecttemplate/ui/screens/detail/DetailViewModel.kt b/app/src/main/kotlin/app/futured/androidprojecttemplate/ui/screens/detail/DetailViewModel.kt index 265154a..15aa24c 100644 --- a/app/src/main/kotlin/app/futured/androidprojecttemplate/ui/screens/detail/DetailViewModel.kt +++ b/app/src/main/kotlin/app/futured/androidprojecttemplate/ui/screens/detail/DetailViewModel.kt @@ -15,8 +15,4 @@ class DetailViewModel @Inject constructor( override fun onIncrementCounter() { viewState.counter++ } - - override fun onNavigateToInfo() { - sendEvent(NavigateToInfoEvent) - } } diff --git a/app/src/main/kotlin/app/futured/androidprojecttemplate/ui/screens/info/InfoEvent.kt b/app/src/main/kotlin/app/futured/androidprojecttemplate/ui/screens/info/InfoEvent.kt deleted file mode 100644 index 9131b67..0000000 --- a/app/src/main/kotlin/app/futured/androidprojecttemplate/ui/screens/info/InfoEvent.kt +++ /dev/null @@ -1,7 +0,0 @@ -package app.futured.androidprojecttemplate.ui.screens.info - -import app.futured.arkitekt.core.event.Event - -sealed class InfoEvent : Event() - -data object NavigateBackEvent : InfoEvent() diff --git a/app/src/main/kotlin/app/futured/androidprojecttemplate/ui/screens/info/InfoScreen.kt b/app/src/main/kotlin/app/futured/androidprojecttemplate/ui/screens/info/InfoScreen.kt deleted file mode 100644 index d1fbe93..0000000 --- a/app/src/main/kotlin/app/futured/androidprojecttemplate/ui/screens/info/InfoScreen.kt +++ /dev/null @@ -1,72 +0,0 @@ -package app.futured.androidprojecttemplate.ui.screens.info - -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.padding -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.runtime.Stable -import androidx.compose.ui.Modifier -import androidx.hilt.navigation.compose.hiltViewModel -import app.futured.androidprojecttemplate.navigation.NavRouter -import app.futured.androidprojecttemplate.tools.arch.EventsEffect -import app.futured.androidprojecttemplate.tools.arch.onEvent -import app.futured.androidprojecttemplate.tools.compose.ScreenPreviews -import app.futured.androidprojecttemplate.tools.extensions.bottomSheetSize -import app.futured.androidprojecttemplate.ui.components.Showcase -import app.futured.androidprojecttemplate.ui.theme.Grid - -@Composable -fun InfoScreen( - navigation: NavRouter, - viewModel: InfoViewModel = hiltViewModel(), -) { - with(viewModel) { - EventsEffect { - onEvent { - navigation.popBackStack() - } - } - - Info.Content( - actions = this, - ) - } -} - -object Info { - - @Stable - interface Actions { - fun onNavigateBack() - } - - @Composable - fun Content( - actions: Actions, - modifier: Modifier = Modifier, - ) { - Column( - modifier = modifier.bottomSheetSize(), - ) { - Text( - modifier = Modifier.padding(Grid.d4), - text = - "This is a BottomSheet, a commonly used user interface component in Android and other mobile operating systems." + - " It is used to display content that slides up from the bottom of the screen, providing users with additional choices and " + - "actions. This particular BottomSheet is part of a mock-up, serving purely for testing purposes. " + - "Please note that the text displayed here is only placeholder text and does not represent any actual content or functionalities. " + - "The aim of this testing is to validate the design, layout, and overall user experience of the BottomSheet component.", - ) - } - } -} - -@ScreenPreviews -@Composable -fun InfoContentPreview() = Showcase { - Info.Content( - actions = object : Info.Actions { - override fun onNavigateBack() = Unit - }, - ) -} diff --git a/app/src/main/kotlin/app/futured/androidprojecttemplate/ui/screens/info/InfoViewModel.kt b/app/src/main/kotlin/app/futured/androidprojecttemplate/ui/screens/info/InfoViewModel.kt deleted file mode 100644 index 39cd395..0000000 --- a/app/src/main/kotlin/app/futured/androidprojecttemplate/ui/screens/info/InfoViewModel.kt +++ /dev/null @@ -1,14 +0,0 @@ -package app.futured.androidprojecttemplate.ui.screens.info - -import app.futured.androidprojecttemplate.tools.arch.BaseViewModel -import dagger.hilt.android.lifecycle.HiltViewModel -import javax.inject.Inject - -@HiltViewModel -class InfoViewModel @Inject constructor( - override val viewState: InfoViewState, -) : BaseViewModel(), Info.Actions { - override fun onNavigateBack() { - sendEvent(NavigateBackEvent) - } -} diff --git a/app/src/main/kotlin/app/futured/androidprojecttemplate/ui/screens/info/InfoViewState.kt b/app/src/main/kotlin/app/futured/androidprojecttemplate/ui/screens/info/InfoViewState.kt deleted file mode 100644 index 17d186a..0000000 --- a/app/src/main/kotlin/app/futured/androidprojecttemplate/ui/screens/info/InfoViewState.kt +++ /dev/null @@ -1,8 +0,0 @@ -package app.futured.androidprojecttemplate.ui.screens.info - -import app.futured.arkitekt.core.ViewState -import dagger.hilt.android.scopes.ViewModelScoped -import javax.inject.Inject - -@ViewModelScoped -class InfoViewState @Inject constructor() : ViewState diff --git a/buildSrc/src/main/kotlin/Dependencies.kt b/buildSrc/src/main/kotlin/Dependencies.kt index 15a5f49..0ee66a6 100644 --- a/buildSrc/src/main/kotlin/Dependencies.kt +++ b/buildSrc/src/main/kotlin/Dependencies.kt @@ -40,10 +40,6 @@ object Dependencies { const val preference = "androidx.preference:preference-ktx:${Versions.preference}" } - object Accompanist { - const val navigationMaterial = "com.google.accompanist:accompanist-navigation-material:${Versions.accompanist}" - } - object NavigationComponents { const val navigation = "androidx.navigation:navigation-compose:${Versions.navigation}" const val navigationHilt = "androidx.hilt:hilt-navigation-compose:${Versions.hiltNavigation}" diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index 6ac3c9d..2bacd6d 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -6,9 +6,9 @@ object Versions { const val androidGradlePlugin = "8.4.0" // plugins - const val detekt = "1.23.6" - const val ktlintGradle = "12.1.1" - const val ktlint = "1.2.1" + const val detekt = "1.22.0" + const val ktlintGradle = "11.2.0" + const val ktlint = "0.48.2" // kotlin const val kotlin = "1.9.23" @@ -25,7 +25,6 @@ object Versions { const val constraintLayout = "1.0.1" const val vectorDrawable = "1.2.0-beta01" const val preference = "1.2.1" - const val accompanist = "0.34.0" const val activity = "1.9.0" const val desugarLibs = "2.0.4"