Skip to content

Commit

Permalink
[feat] : #3 MainActivity 바텀 네비게이션 생성 및 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
1971123-seongmin committed Oct 24, 2024
1 parent a6ed804 commit fa85718
Showing 1 changed file with 102 additions and 8 deletions.
110 changes: 102 additions & 8 deletions app/src/main/java/org/sopt/and/presentation/screen/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,133 @@ import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Surface
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Icon
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.sp
import androidx.navigation.NavHostController
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import org.sopt.and.presentation.navigation.BottomNavItem
import org.sopt.and.presentation.navigation.Navigation
import org.sopt.and.presentation.navigation.Routes
import org.sopt.and.ui.theme.ANDANDROIDTheme
import org.sopt.and.ui.theme.Black
import org.sopt.and.ui.theme.DoubleDarkGray
import org.sopt.and.ui.theme.White

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
ANDANDROIDTheme {
WavveApp()
MyApp()
}
}
}
}

@Preview(showSystemUi = true)
@Composable
fun GreetingPreview() {
ANDANDROIDTheme {
fun BottomNavigation(
modifier: Modifier = Modifier,
containerColor: Color, // 배경색
contentColor: Color, // 아이콘, 텍스트 색
indicatorColor: Color, // 탭 아래 표시되는 선택 항목의 색
navController: NavHostController
) {
val navBackStackEntry by navController.currentBackStackEntryAsState() // 현재 사용자의 경로
val currentRoute = navBackStackEntry?.destination?.route
val items = listOf<BottomNavItem>(
BottomNavItem.Home,
BottomNavItem.Search,
BottomNavItem.MyPage
)

NavigationBar (
modifier = Modifier,
containerColor = containerColor,
contentColor = contentColor
) {
items.forEach { item ->
NavigationBarItem(
selected = currentRoute == item.screenRoute,
label = {
Text(
text = stringResource(id = item.title),
style = TextStyle(
fontSize = 12.sp
)
)
},
icon = {
Icon(
painter = painterResource(id = item.icon),
contentDescription = stringResource(id = item.title)
)
},
onClick = {
navController.navigate(item.screenRoute) {
navController.graph.startDestinationRoute?.let {
popUpTo(it) { saveState = true }
}
launchSingleTop = true
restoreState = true
}
},
)
}
}
}

@Composable
fun WavveApp() {
fun MyApp() {
val navController = rememberNavController()

ANDANDROIDTheme {
Surface(modifier = Modifier.fillMaxSize()) {
Navigation()
Scaffold(
modifier = Modifier
.fillMaxSize()
.background(DoubleDarkGray),
bottomBar = {
val navBackStackEntry by navController.currentBackStackEntryAsState()
val currentRoute = navBackStackEntry?.destination?.route
if (currentRoute != Routes.SignInScreen.route && currentRoute != Routes.SignUpScreen.route) {
BottomNavigation(
contentColor = Black,
containerColor = White,
indicatorColor = White,
navController = navController
)
}
}
) {
Box(modifier = Modifier.padding(it)) {
Navigation(navController = navController)
}
}
}
}

@Preview(showSystemUi = true)
@Composable
fun GreetingPreview() {
ANDANDROIDTheme {

}
}

0 comments on commit fa85718

Please sign in to comment.