Skip to content

Commit

Permalink
fix #week4 : NavHost 전체 innerPadding 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
tunaunnie committed Dec 3, 2024
1 parent 26c22c1 commit 0512b01
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 168 deletions.
131 changes: 54 additions & 77 deletions app/src/main/java/org/sopt/and/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@ import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHostState
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.rememberNavController
import org.sopt.and.ui.theme.ANDANDROIDTheme
Expand All @@ -34,88 +29,70 @@ class MainActivity : ComponentActivity() {
enableEdgeToEdge()
setContent {
ANDANDROIDTheme {
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
val navController = rememberNavController()
Scaffold(
modifier = Modifier.fillMaxSize(),
content = { it
val navController = rememberNavController()

val context = navController.context
val userInfoLocalDataSource = UserInfoLocalDataSourceImpl(context)
val context = navController.context
val userInfoLocalDataSource = UserInfoLocalDataSourceImpl(context)

NavHost(
navController = navController,
startDestination = Route.SignUpScreen(userName = "", password = ""),
modifier = Modifier.padding(innerPadding)
){
composable<Route.SignUpScreen> { backStackEntry ->
val item = backStackEntry.toRoute<Route.SignUpScreen>()
SignUpScreen(
navigateToLoginScreen = {
navController.navigate(Route.LoginScreen){
popUpTo<Route.SignUpScreen> { inclusive = true }
launchSingleTop = true
NavHost(
navController = navController,
startDestination = Route.SignUpScreen(userName = "", password = ""),
modifier = Modifier
){
composable<Route.SignUpScreen> { backStackEntry ->
val item = backStackEntry.toRoute<Route.SignUpScreen>()
SignUpScreen(
navigateToLoginScreen = {
navController.navigate(Route.LoginScreen){
popUpTo<Route.SignUpScreen> { inclusive = true }
launchSingleTop = true
}
}
}
)
}
)
}

composable<Route.LoginScreen> { backStackEntry ->
val item = backStackEntry.toRoute<Route.LoginScreen>()
LoginScreen(
loginViewModel = LoginViewModel(userInfoLocalDataSource = userInfoLocalDataSource),
navigateToHomeScreen = {
navController.navigate(Route.HomeScreen){
popUpTo<Route.HomeScreen> { inclusive = true}
launchSingleTop = true
}
},
)
}
composable<Route.LoginScreen> { backStackEntry ->
val item = backStackEntry.toRoute<Route.LoginScreen>()
LoginScreen(
loginViewModel = LoginViewModel(userInfoLocalDataSource = userInfoLocalDataSource),
navigateToHomeScreen = {
navController.navigate(Route.HomeScreen){
popUpTo<Route.HomeScreen> { inclusive = true}
launchSingleTop = true
}
},
)
}

composable<Route.HomeScreen> { backStackEntry ->
val item = backStackEntry.toRoute<Route.HomeScreen>()
HomeScreen(
homeViewModel = HomeViewModel(),
navController = navController,
)
}
composable<Route.HomeScreen> { backStackEntry ->
val item = backStackEntry.toRoute<Route.HomeScreen>()
HomeScreen(
homeViewModel = HomeViewModel(),
navController = navController,
)
}

composable<Route.SearchScreen> { backStackEntry ->
val item = backStackEntry.toRoute<Route.SearchScreen>()
SearchScreen(
navController = navController
)
}
composable<Route.SearchScreen> { backStackEntry ->
val item = backStackEntry.toRoute<Route.SearchScreen>()
SearchScreen(
navController = navController
)
}

composable<Route.MypageScreen> { backStackEntry ->
val item = backStackEntry.toRoute<Route.MypageScreen>()
MypageScreen(
mypageViewModel = MypageViewModel(userInfoLocalDataSource = userInfoLocalDataSource),
navController = navController
)
composable<Route.MypageScreen> { backStackEntry ->
val item = backStackEntry.toRoute<Route.MypageScreen>()
MypageScreen(
mypageViewModel = MypageViewModel(userInfoLocalDataSource = userInfoLocalDataSource),
navController = navController
)
}
}

// composable("home") {
// HomeScreen(
// navController = navController,
// homeViewModel = HomeViewModel()
// )
// }
//
// composable("search") {
// SearchScreen(
// navController = navController
// )
// }

// composable("profile") {
//
// MypageScreen(
// navController = navController,
// mypageViewModel = mypageViewModel
// )
// }

}
}
})
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
@file:OptIn(ExperimentalMaterial3Api::class)

package org.sopt.and.presentation.homeScreen

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
Expand All @@ -16,7 +14,6 @@ import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
Expand All @@ -41,36 +38,33 @@ import org.sopt.and.ui.components.TopBar.CustomTopAppBarSecond
import org.sopt.and.ui.theme.ANDANDROIDTheme


//@Serializable
//data object HomeScreen

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun HomeScreen(
modifier: Modifier = Modifier,
navController: NavController, // navController를 넘겨 받아 사용
navController: NavController,
homeViewModel: HomeViewModel = viewModel()
) {
val context = LocalContext.current
val scrollState = rememberScrollState()

Scaffold(
topBar = {
Column {
Column(
modifier = modifier.fillMaxWidth()
){
CustomTopAppBar(navController = navController)
CustomTopAppBarSecond(navController = navController)
}
},
bottomBar = {
CustomBottomAppBar(navController = navController)
}
) { innerPadding ->
) { it
Column(
modifier = Modifier
.fillMaxSize()
.verticalScroll(scrollState)
.background(Color(0xFF1B1B1B))
.padding(innerPadding) // 패딩 적용
.padding(all = 10.dp)
) {

Expand Down Expand Up @@ -144,49 +138,9 @@ fun HomeScreenPreview() {
val navController = rememberNavController()
val homeViewModel = HomeViewModel()

ANDANDROIDTheme {
Scaffold(
modifier = Modifier.fillMaxSize(),
topBar = {
Column{
CustomTopAppBar(navController = navController)
CustomTopAppBarSecond(navController = navController)

}

},
bottomBar = {
CustomBottomAppBar(navController = navController)
}
) {
innerPadding ->
Column(
modifier = Modifier
.fillMaxSize()
.background(Color(0xFF1B1B1B))
.padding(innerPadding)
){
NavHost(
navController = navController,
startDestination = "home",
){
composable("home") {HomeScreen(
navController = navController,
homeViewModel = homeViewModel
)}
composable("search") {
SearchScreen(
navController = navController
)
}
composable("profile") {
MypageScreen(
navController = navController,
)
}
}
}
HomeScreen(
navController = navController,
homeViewModel = homeViewModel
)

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ fun MypageScreen(
navController: NavController,
mypageViewModel: MypageViewModel = viewModel()
) {

val user by mypageViewModel.user.collectAsState()

Scaffold(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import kotlinx.coroutines.launch
import org.sopt.and.data.datalocal.datasource.UserInfoLocalDataSource
import org.sopt.and.data.network.ServicePool
import org.sopt.and.domain.User
import org.sopt.and.presentation.main.UserViewModel


class MypageViewModel(
private val userInfoLocalDataSource: UserInfoLocalDataSource
Expand Down Expand Up @@ -52,36 +50,4 @@ class MypageViewModel(
}
}



// fun getUserHobby(request: RequestGetUserHobbyDto, userViewModel: UserViewModel) {
// val TAG = "UserService"
//
// userService.getMyHobby(request).enqueue(object : Callback<ResponseGetUserHobbyWrapperDto> {
// override fun onResponse(
// call: Call<ResponseGetUserHobbyWrapperDto>,
// response: Response<ResponseGetUserHobbyWrapperDto>
// ) {
// if (response.isSuccessful) {
// // 성공 응답 처리
// val body = response.body()
// if (body != null) {
// val userHobby = body.success.result?.userHobby ?: "default hobby"
// Log.d("UserService", "유저 취미: $userHobby")
// userViewModel.setHobby(userHobby)
// } else {
// Log.e("UserService", "응답 본문 없음")
// }
// } else {
// // 실패 응답 처리
// }
// }
//
// override fun onFailure(call: Call<ResponseGetUserHobbyWrapperDto>, t: Throwable) {
// // 네트워크 오류 처리
// Log.e("UserService", "API 호출 실패: ${t.message}")
// }
// })
//
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import androidx.navigation.compose.rememberNavController
import org.sopt.and.R

@Composable
Expand Down Expand Up @@ -55,4 +57,11 @@ fun CustomTopAppBar(navController: NavController){
)
}
)
}

@Preview(showBackground = true)
@Composable
fun AppbarFirstPreivew(){
val navController = rememberNavController()
CustomTopAppBar(navController = navController)
}

0 comments on commit 0512b01

Please sign in to comment.