Skip to content

Commit

Permalink
Bottom bar fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Saifuddin53 committed Jan 1, 2025
1 parent 1edaf3b commit 5569c66
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 115 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ dependencies {
implementation(composeBom)
androidTestImplementation(composeBom)
implementation("androidx.compose.material3:material3")
implementation("androidx.compose.material:material:1.7.6")
implementation("com.google.android.material:material:1.12.0")
implementation("androidx.compose.ui:ui-tooling-preview")
debugImplementation("androidx.compose.ui:ui-tooling")
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/be/scri/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ fun ScribeApp(
pagerState = pagerState,
modifier =
Modifier
.background(color = colorResource(R.color.background_color)),
)
},
modifier = modifier.fillMaxSize(),
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/be/scri/activities/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatDelegate
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.runtime.mutableStateMapOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.navigation.compose.rememberNavController
import be.scri.ScribeApp
Expand Down Expand Up @@ -97,6 +99,7 @@ class MainActivity : ComponentActivity() {
},
context = context,
navController = navController,
modifier = Modifier.navigationBarsPadding()
)
}
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/be/scri/ui/common/ScribeBaseScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ fun ScribeBaseScreen(
Scaffold(
modifier =
modifier
.fillMaxSize(),
.fillMaxSize()
.padding(top = 8.dp),
containerColor = MaterialTheme.colorScheme.background,
) {
Column(
Expand Down
83 changes: 0 additions & 83 deletions app/src/main/java/be/scri/ui/common/bottombar/BottomBarItem.kt

This file was deleted.

110 changes: 80 additions & 30 deletions app/src/main/java/be/scri/ui/common/bottombar/ScribeBottomBar.kt
Original file line number Diff line number Diff line change
@@ -1,59 +1,109 @@
package be.scri.ui.common.bottombar

import android.util.Log
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.consumeWindowInsets
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.pager.PagerState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.BottomNavigation
import androidx.compose.material.BottomNavigationItem
import androidx.compose.material.Icon
import androidx.compose.material3.BottomAppBar
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.google.android.material.bottomnavigation.BottomNavigationItemView

@Composable
fun ScribeBottomBar(
onItemClick: (Int) -> Unit,
pagerState: PagerState,
modifier: Modifier = Modifier,
) {
Column(modifier = modifier) {
BottomAppBar(
containerColor = MaterialTheme.colorScheme.surface,
modifier =
Modifier
.fillMaxWidth()
.height(57.dp),
Column (
modifier = modifier
) {
BottomNavigation(
backgroundColor = MaterialTheme.colorScheme.surface,
modifier = Modifier
) {
bottomBarScreens.forEachIndexed { index, item ->
BottomBarItem(
icon = item.icon,
title = item.label,
isSelected = pagerState.currentPage == index,
onItemClick = {
onItemClick(index)
val isSelected = pagerState.currentPage == index

val iconSize =
if (isSelected) {
26.dp
} else {
24.dp
}

val textSize =
if (isSelected) {
13.sp
} else {
12.sp
}

val color =
if (isSelected) {
MaterialTheme.colorScheme.secondary
} else {
MaterialTheme.colorScheme.onSurface
}

BottomNavigationItem(
selected = pagerState.currentPage == index,
onClick = { onItemClick(index) },
icon = {
androidx.compose.material3.Icon(
painter =
painterResource(
id = item.icon,
),
tint = color,
contentDescription = "Keyboard",
modifier =
Modifier
.clip(MaterialTheme.shapes.medium)
.size(iconSize),
)
},
modifier =
Modifier
.weight(1f)
.padding(
start = 16.dp,
end = 16.dp,
).offset(
y = (-8).dp,
label = {
Text(
text = item.label,
style =
MaterialTheme.typography.labelMedium.copy(
fontSize = textSize,
fontWeight = if (isSelected) FontWeight.ExtraBold else FontWeight.W600,
letterSpacing = (0).sp,
color = color
),
)
},
alwaysShowLabel = true,
selectedContentColor = MaterialTheme.colorScheme.secondary,
unselectedContentColor = MaterialTheme.colorScheme.onSurface
)
}
}
}

// LaunchedEffect(pagerState.currentPage) {
// val route = bottomBarScreens[pagerState.currentPage].route
// navController.navigate("$route/page") {
// // popUpTo(Screen.Installation.route) { saveState = true }
// launchSingleTop = true
// restoreState = true
// }
// }
}

0 comments on commit 5569c66

Please sign in to comment.