Skip to content

Commit

Permalink
[Delete]
Browse files Browse the repository at this point in the history
 - Delete BottomNavBar.kt
[Add]
 - Add TopAppBar.kt
  • Loading branch information
KanuKim97 committed Jan 28, 2024
1 parent 3e62016 commit 21fdc1b
Show file tree
Hide file tree
Showing 24 changed files with 331 additions and 279 deletions.
8 changes: 4 additions & 4 deletions .idea/appInsightsSettings.xml

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

80 changes: 2 additions & 78 deletions app/src/main/java/com/example/whats_eat/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,9 @@ package com.example.whats_eat
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Icon
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.navigation.NavDestination.Companion.hierarchy
import androidx.navigation.NavHostController
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import com.example.collection.navigation.collectionRoute
import com.example.designsystem.component.BottomAppNavBar
import com.example.designsystem.component.BottomNavAppBarItem
import com.example.designsystem.theme.EatTheme
import com.example.designsystem.theme.Typography
import com.example.detail.navigation.detailRoute
import com.example.home.navigation.homeRoute
import com.example.whats_eat.navigation.NavigationMenu
import com.example.whats_eat.navigation.WhatsEatNavHost
import dagger.hilt.android.AndroidEntryPoint

Expand All @@ -31,68 +16,7 @@ class MainActivity : ComponentActivity() {

setContent {
val navHostController: NavHostController = rememberNavController()
val navBackStackEntry by navHostController.currentBackStackEntryAsState()
val currentDestination = navBackStackEntry?.destination
val navMenu = listOf(
NavigationMenu.Home,
NavigationMenu.Collection
)
var bottomBarVisible: Boolean

navBackStackEntry?.destination?.route.let { route ->
bottomBarVisible = when(route) {
homeRoute -> true
collectionRoute -> true
detailRoute -> false
else -> false
}
}

EatTheme {
Scaffold(
modifier = Modifier.fillMaxSize(),
bottomBar = {
if (bottomBarVisible) {
BottomAppNavBar {
navMenu.forEach { navigationMenu ->
BottomNavAppBarItem(
onClick = { navHostController.navigate(navigationMenu.route) },
selected = currentDestination
?.hierarchy
?.any { destination ->
destination.route == navigationMenu.route
} == true,
icon = {
Icon(
imageVector = navigationMenu.icon,
contentDescription = navigationMenu.screenName
)
},
selectedIcon = {
Icon(
imageVector = navigationMenu.selectedIcon,
contentDescription = navigationMenu.screenName
)
},
label = {
Text(
text = navigationMenu.screenName,
style = Typography.labelMedium
)
}
)
}
}
}
},
content = { paddingValues ->
WhatsEatNavHost(
scaffoldPaddingValues = paddingValues,
navController = navHostController
)
}
)
}
EatTheme { WhatsEatNavHost(navController = navHostController) }
}
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,32 @@ package com.example.whats_eat.navigation

import androidx.compose.animation.EnterTransition
import androidx.compose.animation.ExitTransition
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.runtime.Composable
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import com.example.collection.navigation.collectionScreen
import com.example.collection.navigation.toCollectionScreen
import com.example.detail.navigation.detailScreen
import com.example.detail.navigation.onNavigateDetail
import com.example.home.navigation.homeRoute
import com.example.home.navigation.homeScreen

@Composable
fun WhatsEatNavHost(
scaffoldPaddingValues: PaddingValues,
navController: NavHostController
) {
fun WhatsEatNavHost(navController: NavHostController) {
NavHost(
navController = navController,
startDestination = homeRoute,
enterTransition = { EnterTransition.None },
exitTransition = { ExitTransition.None }
) {
homeScreen(
scaffoldPaddingValues = scaffoldPaddingValues,
navigateToDetail = { id -> navController.onNavigateDetail(id) }
navigateToDetail = { id -> navController.onNavigateDetail(id) },
navigateToCollection = { navController.toCollectionScreen() }
)
collectionScreen(navigationIconClick = { navController.popBackStack() })
detailScreen(
navigationIconOnClick = { navController.popBackStack() },
navigateToCollectionScreen = { navController.toCollectionScreen() }
)
collectionScreen(scaffoldPaddingValues = scaffoldPaddingValues)
detailScreen()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package com.example.designsystem.component

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.RowScope
import androidx.compose.material3.CenterAlignedTopAppBar
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.LargeTopAppBar
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.TopAppBarScrollBehavior
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.text.font.FontWeight
import com.example.designsystem.theme.EatTypography

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun EatCenterAlignedAppBar(
title: @Composable () -> Unit,
navigationIcon: @Composable () -> Unit,
actions: @Composable RowScope.() -> Unit,
modifier: Modifier = Modifier,
scrollBehavior: TopAppBarScrollBehavior? = null
) {
CenterAlignedTopAppBar(
title = title,
modifier = modifier,
navigationIcon = navigationIcon,
actions = actions,
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(
containerColor = MaterialTheme.colorScheme.surface,
navigationIconContentColor = MaterialTheme.colorScheme.onSurface,
titleContentColor = MaterialTheme.colorScheme.onSurface,
actionIconContentColor = MaterialTheme.colorScheme.onSurfaceVariant
),
scrollBehavior = scrollBehavior
)
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun EatCenterAlignedAppBar(
navigationIcon: ImageVector,
navigationIconOnClick: () -> Unit,
actions: @Composable RowScope.() -> Unit,
modifier: Modifier = Modifier
) {
EatCenterAlignedAppBar(
title = { /* Nothing Here */ },
modifier = modifier,
navigationIcon = {
IconButton(
onClick = navigationIconOnClick,
content = {
Icon(
imageVector = navigationIcon,
contentDescription = "Icon Button"
)
}
)
},
actions = actions
)
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun EatCenterAlignedAppBar(
navigationIcon: ImageVector,
navigationIconOnClick: () -> Unit,
modifier: Modifier = Modifier
) {
EatCenterAlignedAppBar(
title = { /* Nothing Here */ },
modifier = modifier,
navigationIcon = {
IconButton(
onClick = navigationIconOnClick,
content = {
Icon(
imageVector = navigationIcon,
contentDescription = "Icon Button"
)
}
)
},
actions = { /* Nothing Here */ }
)
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun EatLargeTopAppBar(
modifier: Modifier = Modifier,
title: @Composable () -> Unit,
actions: @Composable RowScope.() -> Unit
) {
LargeTopAppBar(
title = title,
modifier = modifier,
actions = actions
)
}

@Composable
fun EatLargeTopAppBar(
mainTitle: String,
subTitle: String,
actionIcon: ImageVector,
actionIconOnClick: () -> Unit,
modifier: Modifier = Modifier,
) {
EatLargeTopAppBar(
title = {
Column {
Text(
text = mainTitle,
fontWeight = FontWeight.Bold,
style = EatTypography.headlineMedium
)
Text(
text = subTitle,
fontWeight = FontWeight.Medium,
style = EatTypography.titleSmall
)
}
},
modifier = modifier,
actions = {
IconButton(
onClick = actionIconOnClick,
content = {
Icon(
imageVector = actionIcon,
contentDescription = "Icon"
)
}
)
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import com.example.designsystem.icons.EatIcons
import com.example.designsystem.theme.EatTheme
import com.example.designsystem.theme.Gray700
import com.example.designsystem.theme.Gray900
import com.example.designsystem.theme.Typography
import com.example.designsystem.theme.EatTypography

@Composable
fun BottomAppNavBar(
Expand Down Expand Up @@ -83,7 +83,7 @@ fun PreviewItem() {
Text(
text = item,
fontWeight = FontWeight.Bold,
style = Typography.labelMedium
style = EatTypography.labelMedium
)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.request.RequestOptions
import com.example.designsystem.theme.EatShape
import com.example.designsystem.theme.Gray
import com.example.designsystem.theme.Typography
import com.example.designsystem.theme.EatTypography
import com.skydoves.landscapist.ImageOptions
import com.skydoves.landscapist.glide.GlideImage
import com.skydoves.landscapist.glide.GlideImageState
Expand Down Expand Up @@ -73,7 +73,7 @@ fun EatImageLoader(
content = {
Text(
text = "이미지 불러오기에 실패하였습니다.",
style = Typography.labelLarge
style = EatTypography.labelLarge
)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import androidx.compose.ui.unit.dp
import com.example.designsystem.icons.EatIcons
import com.example.designsystem.theme.EatShape
import com.example.designsystem.theme.EatTheme
import com.example.designsystem.theme.Typography
import com.example.designsystem.theme.EatTypography

@Composable
fun NoticeSnackBar(
Expand Down Expand Up @@ -50,7 +50,7 @@ fun NoticeSnackBar(
Spacer(modifier = modifier.size(8.dp))
Text(
text = text,
style = Typography.labelLarge
style = EatTypography.labelLarge
)
}
)
Expand Down
Loading

0 comments on commit 21fdc1b

Please sign in to comment.