Skip to content

Commit

Permalink
[feat] mash-up-kr#111 네비게이션바 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
JaesungLeee committed Jul 5, 2023
1 parent 68d3051 commit 2584d0f
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -26,7 +28,7 @@ fun KeyLinkApp(
Scaffold(
bottomBar = {
if (appState.isBottomBarVisible()) {
KeyLinkBottomNavigationBar()
// KeyLinkNavigationBar()
}
},
backgroundColor = Black,
Expand All @@ -46,8 +48,3 @@ fun KeyLinkApp(
)
}
}

@Composable
fun KeyLinkBottomNavigationBar() {

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -63,7 +63,7 @@ class KeyLinkAppState(
restoreState = true
}
when (topLevelDestination) {
TopLevelDestinations.HOME -> {}
TopLevelDestination.HOME -> {}
else -> {}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
)
}
}
}
}
}

0 comments on commit 2584d0f

Please sign in to comment.