From 2584d0ff54655591c1db13adadf2e999884771c0 Mon Sep 17 00:00:00 2001 From: Jaesung Lee Date: Wed, 5 Jul 2023 14:24:20 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20#111=20=EB=84=A4=EB=B9=84=EA=B2=8C?= =?UTF-8?q?=EC=9D=B4=EC=85=98=EB=B0=94=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/mashup/presentation/KeyLinkApp.kt | 9 +- .../mashup/presentation/KeyLinkAppState.kt | 6 +- .../ui/common/KeyLinkNavigationBar.kt | 113 ++++++++++++++++++ 3 files changed, 119 insertions(+), 9 deletions(-) create mode 100644 presentation/src/main/java/com/mashup/presentation/ui/common/KeyLinkNavigationBar.kt diff --git a/presentation/src/main/java/com/mashup/presentation/KeyLinkApp.kt b/presentation/src/main/java/com/mashup/presentation/KeyLinkApp.kt index b6d120d1a..27d61a0ae 100644 --- a/presentation/src/main/java/com/mashup/presentation/KeyLinkApp.kt +++ b/presentation/src/main/java/com/mashup/presentation/KeyLinkApp.kt @@ -9,6 +9,8 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import com.mashup.presentation.navigation.KeyLinkNavHost +import com.mashup.presentation.navigation.TopLevelDestination +import com.mashup.presentation.ui.common.KeyLinkNavigationBar import com.mashup.presentation.ui.common.KeyLinkSnackBar import com.mashup.presentation.ui.theme.Black @@ -26,7 +28,7 @@ fun KeyLinkApp( Scaffold( bottomBar = { if (appState.isBottomBarVisible()) { - KeyLinkBottomNavigationBar() +// KeyLinkNavigationBar() } }, backgroundColor = Black, @@ -46,8 +48,3 @@ fun KeyLinkApp( ) } } - -@Composable -fun KeyLinkBottomNavigationBar() { - -} diff --git a/presentation/src/main/java/com/mashup/presentation/KeyLinkAppState.kt b/presentation/src/main/java/com/mashup/presentation/KeyLinkAppState.kt index 329da09da..2c89a86f6 100644 --- a/presentation/src/main/java/com/mashup/presentation/KeyLinkAppState.kt +++ b/presentation/src/main/java/com/mashup/presentation/KeyLinkAppState.kt @@ -9,7 +9,7 @@ import androidx.navigation.NavHostController import androidx.navigation.compose.currentBackStackEntryAsState import androidx.navigation.compose.rememberNavController import androidx.navigation.navOptions -import com.mashup.presentation.navigation.TopLevelDestinations +import com.mashup.presentation.navigation.TopLevelDestination /** * Ssam_D_Android @@ -54,7 +54,7 @@ class KeyLinkAppState( * Home, Chat Route로 다시 돌아와야 하는 경우 호출하는 메서드 * singleTop으로 동작 및 backstack 유지 */ - fun navigateToTopLevelDestination(topLevelDestination: TopLevelDestinations) { + fun navigateToTopLevelDestination(topLevelDestination: TopLevelDestination) { val topLevelNavOptions = navOptions { popUpTo(id = navController.graph.findStartDestination().id) { saveState = true @@ -63,7 +63,7 @@ class KeyLinkAppState( restoreState = true } when (topLevelDestination) { - TopLevelDestinations.HOME -> {} + TopLevelDestination.HOME -> {} else -> {} } } diff --git a/presentation/src/main/java/com/mashup/presentation/ui/common/KeyLinkNavigationBar.kt b/presentation/src/main/java/com/mashup/presentation/ui/common/KeyLinkNavigationBar.kt new file mode 100644 index 000000000..46f97466d --- /dev/null +++ b/presentation/src/main/java/com/mashup/presentation/ui/common/KeyLinkNavigationBar.kt @@ -0,0 +1,113 @@ +package com.mashup.presentation.ui.common + +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.selection.selectableGroup +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material.* +import androidx.compose.runtime.getValue +import androidx.compose.runtime.setValue +import androidx.compose.runtime.Composable +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.saveable.rememberSaveable +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import com.mashup.presentation.ui.theme.* +import com.mashup.presentation.R + +/** + * Ssam_D_Android + * @author jaesung + * @created 2023/07/04 + */ +@Composable +fun KeyLinkNavigationBar( + modifier: Modifier = Modifier, + content: @Composable RowScope.() -> Unit +) { + Surface( + color = Gray01, + shape = RoundedCornerShape(topStart = 20.dp, topEnd = 20.dp), + elevation = BottomNavigationDefaults.Elevation, + modifier = modifier + ) { + Row( + modifier = Modifier + .fillMaxWidth() + .height(76.dp) + .selectableGroup(), + horizontalArrangement = Arrangement.SpaceBetween, + content = content + ) + } +} + +@Composable +fun RowScope.KeyLinkNavigationBarItem( + selected: Boolean, + onClick: () -> Unit, + modifier: Modifier = Modifier, + alwaysShowLabel: Boolean = true, + enabled: Boolean = true, + icon: @Composable () -> Unit, + selectedIcon: @Composable () -> Unit, + label: @Composable (() -> Unit)? = null +) { + BottomNavigationItem( + selected = selected, + onClick = onClick, + icon = if (selected) selectedIcon else icon, + label = label, + enabled = enabled, + modifier = modifier, + alwaysShowLabel = alwaysShowLabel, + selectedContentColor = White, + unselectedContentColor = Gray04, + ) +} + +@Preview(showBackground = true) +@Composable +fun KeyLinkNavigationBarPreview() { + var selectedItem by rememberSaveable { mutableStateOf(0) } + val items = listOf("홈", "시그널 보내기", "채팅") + val icons = listOf( + painterResource(id = R.drawable.ic_home_fill_32), + painterResource(id = R.drawable.ic_home_fill_32), + painterResource(id = R.drawable.ic_chat_fill_32) + ) + + val selectedIcons = listOf( + painterResource(id = R.drawable.ic_home_fill_32), + painterResource(id = R.drawable.ic_home_fill_32), + painterResource(id = R.drawable.ic_chat_fill_32) + ) + SsamDTheme { + Surface(color = Black) { + KeyLinkNavigationBar { + items.forEachIndexed { index, item -> + KeyLinkNavigationBarItem( + selected = selectedItem == index, + onClick = { selectedItem = index }, + icon = { + Icon( + painter = icons[index], + contentDescription = "" + ) + }, + selectedIcon = { + Icon( + painter = selectedIcons[index], + contentDescription = "" + ) + }, + label = { + Text(text = item) + } + ) + } + } + } + } +} \ No newline at end of file