-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Week2 과제 ... #3
base: develop
Are you sure you want to change the base?
Week2 과제 ... #3
Changes from all commits
30c36c8
13be207
4d16ed9
343b468
4e432d3
04a86e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
@file:OptIn(ExperimentalMaterial3Api::class) | ||
|
||
package org.sopt.and | ||
|
||
import androidx.compose.foundation.ExperimentalFoundationApi | ||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.pager.HorizontalPager | ||
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 | ||
import androidx.compose.ui.draw.clip | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.layout.ContentScale | ||
import androidx.compose.ui.platform.LocalContext | ||
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.NavHost | ||
import androidx.navigation.compose.composable | ||
import androidx.navigation.compose.rememberNavController | ||
import kotlinx.serialization.Serializable | ||
import org.sopt.and.ui.components.BottomBar.CustomBottomAppBar | ||
import org.sopt.and.ui.components.HomeScreen.HomeLazyRow | ||
import org.sopt.and.ui.components.TopBar.CustomTopAppBar | ||
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를 넘겨 받아 사용 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 하위 컴포저블 함수에 NavController를 인자로 받는 것은 권장하지 않는 방법입니다. |
||
) { | ||
val context = LocalContext.current | ||
val scrollState = rememberScrollState() | ||
|
||
Scaffold( | ||
topBar = { | ||
Column { | ||
CustomTopAppBar(navController = navController) | ||
CustomTopAppBarSecond(navController = navController) | ||
} | ||
}, | ||
bottomBar = { | ||
CustomBottomAppBar(navController = navController) | ||
} | ||
Comment on lines
+53
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 코드가 Home, Search, My에서 중복되고 있는 것 같아요. 외부로 빼는건 어떨까요?
NavHost 자체를 Scaffold로 감싸는 방법도 있을 것 같아요. 그렇게 되면 SignUp과 같은 화면에도 topBar와 bottomBar가 나올거에요. 그 때 조건을 통해 특정 화면일 때에만 나오도록 설정할 수 있어요! 물론 다른 방법이 있다면 그렇게 하는 것도 좋아요! 저는 여러 방법중 하나를 제안드리는거지 절대 정답은 아닙니다 :) |
||
) { innerPadding -> | ||
Column( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LazyColumn을 사용하는 것이 성능상으로 더 좋을 것 같아요 |
||
modifier = Modifier | ||
.fillMaxSize() | ||
.verticalScroll(scrollState) | ||
.background(Color(0xFF1B1B1B)) | ||
.padding(innerPadding) // 패딩 적용 | ||
.padding(all = 10.dp) | ||
) { | ||
|
||
val images = listOf( | ||
R.drawable.food_pic1, | ||
R.drawable.food_pic2, | ||
R.drawable.food_pic3, | ||
R.drawable.food_pic4, | ||
R.drawable.food_pic5 | ||
) | ||
Comment on lines
+73
to
+79
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 세미나 때 AAC 뷰모델에 대해 배웠었죠? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 추가적으로 |
||
|
||
val pagerState = rememberPagerState { images.size } | ||
|
||
HorizontalPager( | ||
state = pagerState, | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.height(400.dp) | ||
) { idx -> | ||
Image( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.padding(16.dp) | ||
.clip(RoundedCornerShape(16.dp)), | ||
painter = painterResource(id = images[idx]), | ||
contentDescription = "imagePager", | ||
contentScale = ContentScale.Crop | ||
) | ||
} | ||
|
||
HomeLazyRow( | ||
title = "믿고 보는 웨이브 에디터 추천작", | ||
images = images, | ||
height = 230, | ||
width = 140, | ||
) | ||
Spacer(modifier = Modifier.height(10.dp)) | ||
|
||
HomeLazyRow( | ||
title = "실시간 인기 콘텐츠", | ||
images = images, | ||
height = 230, | ||
width = 140, | ||
) | ||
Spacer(modifier = Modifier.height(10.dp)) | ||
|
||
HomeLazyRow( | ||
title = "오직 웨이브에서", | ||
images = images, | ||
height = 230, | ||
width = 140, | ||
) | ||
Spacer(modifier = Modifier.height(10.dp)) | ||
|
||
HomeLazyRow( | ||
title = "오늘의 TOP 20", | ||
images = images, | ||
height = 260, | ||
width = 180, | ||
) | ||
Spacer(modifier = Modifier.height(10.dp)) | ||
|
||
HomeLazyRow( | ||
title = "당한 대로 갚아줄게", | ||
images = images, | ||
height = 230, | ||
width = 140, | ||
) | ||
Spacer(modifier = Modifier.height(10.dp)) | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
@Preview(showBackground = true) | ||
@Composable | ||
fun HomeScreenPreview() { | ||
val navController = rememberNavController() | ||
|
||
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 | ||
)} | ||
composable("search") {SearchScreen( | ||
navController = navController | ||
)} | ||
composable("profile") {MypageScreen( | ||
navController = navController, | ||
)} | ||
} | ||
} | ||
|
||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이번주 과제가 SAA 적용이었죠?
Single Activity가 되려면 말 그대로 액티비티가 하나여야 합니다.
즉, manifest에 등록한 액티비티가 하나여야 해요!
이를 바탕으로 리팩해보시면 좋을 것 같아요!