Skip to content

Commit

Permalink
[feat] mash-up-kr#111 TopLevelDestination 수정 및 Navigation Bar Icon 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
JaesungLeee committed Jul 6, 2023
1 parent 2584d0f commit 757e073
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@ import com.mashup.presentation.R
* @created 2023/07/04
*/
enum class TopLevelDestination(
val selectedIconId: Int?,
val unselectedIconId: Int?,
val selectedIconId: Int,
val unselectedIconId: Int,
val iconTextId: Int,
val textLabelId: Int
) {
HOME(
selectedIconId = R.drawable.ic_home_fill_32,
unselectedIconId = R.drawable.ic_home_fill_32, // 수정 필요
unselectedIconId = R.drawable.ic_home_fill_32,
iconTextId = R.string.navigation_home,
textLabelId = R.string.navigation_home,
),
SIGNAL(
selectedIconId = null,
unselectedIconId = null,
selectedIconId = R.drawable.ic_signal_fill_32,
unselectedIconId = R.drawable.ic_signal_fill_32,
iconTextId = R.string.navigation_signal,
textLabelId = R.string.navigation_signal,
),
CHAT(
selectedIconId = R.drawable.ic_chat_fill_32,
unselectedIconId = R.drawable.ic_chat_fill_32, // 수정 필요
unselectedIconId = R.drawable.ic_chat_fill_32,
iconTextId = R.string.navigation_chat,
textLabelId = R.string.navigation_chat,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,62 @@ 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.*
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.navigation.NavDestination
import androidx.navigation.NavDestination.Companion.hierarchy
import com.mashup.presentation.ui.theme.*
import com.mashup.presentation.R
import com.mashup.presentation.navigation.TopLevelDestination

/**
* Ssam_D_Android
* @author jaesung
* @created 2023/07/04
*/
@Composable
fun KeyLinkBottomBar(
destinations: List<TopLevelDestination>,
onNavigateToDestination: (TopLevelDestination) -> Unit,
currentDestination: NavDestination?,
modifier: Modifier = Modifier
) {
KeyLinkNavigationBar(modifier = modifier) {
destinations.forEach { destination ->

val selected = currentDestination?.hierarchy?.any {
it.route?.contains(destination.name, true) ?: false
} ?: false

KeyLinkNavigationBarItem(
selected = selected,
onClick = { onNavigateToDestination(destination) },
icon = {
Icon(
painter = painterResource(id = destination.unselectedIconId),
contentDescription = stringResource(id = destination.iconTextId)
)
},
selectedIcon = {
Icon(
painter = painterResource(id = destination.selectedIconId),
contentDescription = stringResource(id = destination.iconTextId)
)
},
label = {
Text(text = stringResource(id = destination.textLabelId))
},
modifier = modifier,
)
}
}
}

@Composable
fun KeyLinkNavigationBar(
modifier: Modifier = Modifier,
Expand All @@ -47,12 +86,12 @@ fun KeyLinkNavigationBar(
fun RowScope.KeyLinkNavigationBarItem(
selected: Boolean,
onClick: () -> Unit,
modifier: Modifier = Modifier,
alwaysShowLabel: Boolean = true,
enabled: Boolean = true,
label: @Composable () -> Unit,
icon: @Composable () -> Unit,
selectedIcon: @Composable () -> Unit,
label: @Composable (() -> Unit)? = null
modifier: Modifier = Modifier,
alwaysShowLabel: Boolean = true,
enabled: Boolean = true
) {
BottomNavigationItem(
selected = selected,
Expand All @@ -71,16 +110,16 @@ fun RowScope.KeyLinkNavigationBarItem(
@Composable
fun KeyLinkNavigationBarPreview() {
var selectedItem by rememberSaveable { mutableStateOf(0) }
val items = listOf("", "시그널 보내기", "채팅")
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_signal_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_signal_fill_32),
painterResource(id = R.drawable.ic_chat_fill_32)
)
SsamDTheme {
Expand All @@ -91,10 +130,17 @@ fun KeyLinkNavigationBarPreview() {
selected = selectedItem == index,
onClick = { selectedItem = index },
icon = {
Icon(
painter = icons[index],
contentDescription = ""
)
BadgedBox(badge = {
Badge {
Text(text = "8")
}
}) {
Icon(
painter = icons[index],
contentDescription = ""
)
}

},
selectedIcon = {
Icon(
Expand All @@ -103,7 +149,10 @@ fun KeyLinkNavigationBarPreview() {
)
},
label = {
Text(text = item)
Text(
text = item,
style = Caption2
)
}
)
}
Expand Down
10 changes: 10 additions & 0 deletions presentation/src/main/res/drawable/ic_signal_fill_32.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="32dp"
android:height="32dp"
android:viewportWidth="32"
android:viewportHeight="32">
<path
android:fillColor="#7E7E86"
android:fillType="evenOdd"
android:pathData="M24.62,7.826C24.173,8.272 24.179,8.992 24.576,9.482C25.248,10.309 25.797,11.23 26.206,12.218C26.762,13.558 27.047,14.995 27.047,16.446C27.047,17.896 26.762,19.333 26.206,20.673C25.797,21.661 25.248,22.582 24.576,23.409C24.179,23.899 24.173,24.619 24.62,25.066C25.066,25.512 25.794,25.515 26.2,25.032C27.079,23.988 27.794,22.813 28.318,21.548C28.988,19.93 29.333,18.197 29.333,16.446C29.333,14.695 28.988,12.961 28.318,11.343C27.794,10.078 27.079,8.903 26.2,7.859C25.794,7.376 25.066,7.379 24.62,7.826ZM21.279,14.259C21.139,13.918 20.965,13.594 20.763,13.288C20.414,12.762 20.403,12.043 20.849,11.597C21.295,11.15 22.027,11.146 22.405,11.651C22.804,12.184 23.135,12.766 23.391,13.384C23.793,14.354 24,15.395 24,16.445C24,17.496 23.793,18.536 23.391,19.507C23.135,20.125 22.804,20.706 22.405,21.239C22.027,21.744 21.295,21.74 20.849,21.294C20.403,20.848 20.414,20.129 20.763,19.603C20.965,19.297 21.139,18.972 21.279,18.632C21.567,17.939 21.714,17.196 21.714,16.445C21.714,15.695 21.567,14.952 21.279,14.259ZM18.666,16.446C18.666,17.919 17.472,19.113 15.999,19.113C14.526,19.113 13.332,17.919 13.332,16.446C13.332,14.973 14.526,13.779 15.999,13.779C17.472,13.779 18.666,14.973 18.666,16.446ZM10.721,18.632C10.862,18.972 11.035,19.297 11.237,19.603C11.586,20.129 11.598,20.848 11.151,21.294C10.705,21.74 9.974,21.744 9.595,21.239C9.197,20.706 8.865,20.125 8.609,19.507C8.207,18.536 8,17.496 8,16.445C8,15.395 8.207,14.354 8.609,13.384C8.865,12.766 9.197,12.184 9.595,11.651C9.974,11.146 10.705,11.15 11.151,11.597C11.598,12.043 11.586,12.762 11.237,13.288C11.035,13.594 10.862,13.918 10.721,14.259C10.434,14.952 10.286,15.695 10.286,16.445C10.286,17.196 10.434,17.939 10.721,18.632ZM7.379,25.066C7.826,24.619 7.82,23.899 7.423,23.409C6.751,22.582 6.202,21.661 5.793,20.674C5.237,19.333 4.952,17.896 4.952,16.446C4.952,14.995 5.237,13.558 5.793,12.218C6.202,11.23 6.751,10.309 7.423,9.482C7.82,8.992 7.826,8.272 7.379,7.826C6.933,7.379 6.205,7.376 5.799,7.859C4.92,8.904 4.205,10.078 3.681,11.343C3.011,12.961 2.666,14.695 2.666,16.446C2.666,18.197 3.011,19.931 3.681,21.548C4.205,22.813 4.92,23.988 5.799,25.032C6.205,25.515 6.933,25.512 7.379,25.066Z" />
</vector>
4 changes: 2 additions & 2 deletions presentation/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<string name="empty_text" />

<string name="navigation_home">홈</string>
<string name="navigation_signal">시그널 보내기</string>
<string name="navigation_chat">채팅</string>
<string name="navigation_signal">보내기</string>
<string name="navigation_chat">연결됨</string>
<string name="input_maximum_10">최대 10자 입력</string>
<string name="close">닫기</string>
<string name="look_around">둘러보기</string>
Expand Down

0 comments on commit 757e073

Please sign in to comment.