Траблы с bottomNavBar'ом. ПОКА ЧТО все работает. Посмотрим что будет дальше!
This commit is contained in:
parent
1a76a041f0
commit
8d7f7cccab
@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17_PREVIEW" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,17 @@
|
||||
package com.example.shawarma.screens.cart
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
|
||||
@Composable
|
||||
fun CartScreen() {
|
||||
Box(
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Text(
|
||||
text = "Cart"
|
||||
)
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.example.shawarma.screens.discount
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
|
||||
@Composable
|
||||
fun DiscountScreen() {
|
||||
Box(
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Text(
|
||||
text = "Discount"
|
||||
)
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.example.shawarma.screens.home
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
|
||||
@Composable
|
||||
fun HomeScreen() {
|
||||
Box(
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Text(
|
||||
text = "Home"
|
||||
)
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.example.shawarma.utils
|
||||
|
||||
import com.example.shawarma.R
|
||||
|
||||
sealed class BottomNavItem(var title:String, var icon:Int, var screen_route:String) {
|
||||
object Home : BottomNavItem("Home", R.drawable.home_icon,ScreenPaths.home.name)
|
||||
object Discount : BottomNavItem("Discount", R.drawable.discount_icon,ScreenPaths.discount.name)
|
||||
object Cart : BottomNavItem("Cart", R.drawable.cart_icon,ScreenPaths.cart.name)
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
package com.example.shawarma.utils
|
||||
|
||||
enum class ScreenPaths {
|
||||
authorization, registration
|
||||
authorization, registration, home, discount, cart, orders
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package com.example.shawarma.widgets
|
||||
|
||||
import androidx.compose.material.BottomNavigation
|
||||
import androidx.compose.material.BottomNavigationItem
|
||||
import androidx.compose.material.Icon
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.navigation.NavController
|
||||
import androidx.navigation.compose.currentBackStackEntryAsState
|
||||
import com.example.shawarma.utils.BottomNavItem
|
||||
|
||||
@Composable
|
||||
fun BottomNavBar(navController: NavController) {
|
||||
val items = listOf(
|
||||
BottomNavItem.Home,
|
||||
BottomNavItem.Discount,
|
||||
BottomNavItem.Cart,
|
||||
)
|
||||
BottomNavigation(
|
||||
backgroundColor = Color.Green,
|
||||
contentColor = Color.Cyan
|
||||
|
||||
) {
|
||||
val navBackStackEntry by navController.currentBackStackEntryAsState()
|
||||
val currentRoute = navBackStackEntry?.destination?.route
|
||||
items.forEach { item ->
|
||||
BottomNavigationItem(
|
||||
icon = { Icon(painterResource(id = item.icon), contentDescription = item.title) },
|
||||
label = {
|
||||
Text(
|
||||
text = item.title,
|
||||
fontSize = 9.sp
|
||||
) },
|
||||
selectedContentColor = Color.Black,
|
||||
unselectedContentColor = Color.Black.copy(0.4f),
|
||||
alwaysShowLabel = true,
|
||||
selected = currentRoute == item.screen_route,
|
||||
onClick = {
|
||||
navController.navigate(item.screen_route) {
|
||||
navController.graph.startDestinationRoute?.let { screen_route ->
|
||||
popUpTo(screen_route) {
|
||||
saveState = true
|
||||
}
|
||||
}
|
||||
launchSingleTop = true
|
||||
restoreState = true
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
BIN
app/src/main/res/drawable/cart_icon.png
Normal file
BIN
app/src/main/res/drawable/cart_icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 839 B |
BIN
app/src/main/res/drawable/discount_icon.png
Normal file
BIN
app/src/main/res/drawable/discount_icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
BIN
app/src/main/res/drawable/home_icon.png
Normal file
BIN
app/src/main/res/drawable/home_icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 987 B |
10
build.gradle
10
build.gradle
@ -2,9 +2,15 @@ buildscript {
|
||||
ext {
|
||||
compose_ui_version = '1.2.0'
|
||||
}
|
||||
repositories {
|
||||
google()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:4.0.0'
|
||||
}
|
||||
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
plugins {
|
||||
id 'com.android.application' version '8.1.1' apply false
|
||||
id 'com.android.library' version '8.1.1' apply false
|
||||
id 'com.android.application' version '7.4.2' apply false
|
||||
id 'com.android.library' version '7.4.2' apply false
|
||||
id 'org.jetbrains.kotlin.android' version '1.7.0' apply false
|
||||
}
|
@ -23,4 +23,5 @@ kotlin.code.style=official
|
||||
android.nonTransitiveRClass=true
|
||||
android.defaults.buildfeatures.buildconfig=true
|
||||
android.nonFinalResIds=false
|
||||
org.gradle.unsafe.configuration-cache=true
|
||||
org.gradle.unsafe.configuration-cache=true
|
||||
android.suppressUnsupportedCompileSdk=34
|
Loading…
Reference in New Issue
Block a user