Modifier
동작
modifier
.fillMaxWidth()
.heightIn(min = 56.dp)
Column
Row
Arragement.spacedBy()
PaddingVlaues(horizontal = 16.dp)
@Composable
fun FavoriteCollectionsGrid(
modifier: Modifier = Modifier
) {
LazyHorizontalGrid(
rows = GridCells.Fixed(2),
contentPadding = PaddingValues(horizontal = 16.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp),
modifier = modifier.height(120.dp) // 그리드 전체 높이 설정
) {
items(favoriteCollectionsData) { item ->
FavoriteCollectionCard(
drawable = item.drawable,
text = item.text,
modifier = Modifier.height(56.dp)
)
}
}
}
슬롯 기반 레이아웃은 개발자가 원하는 대로 채울 수 있도록
UI에 빈 공간을 남겨 둡니다.
슬롯 기반 레이아웃을 사용하면 보다 유연한
레이아웃을 만들 수 있습니다.
👉🏻 슬롯 기반 레이아웃에 관한 섹션
@Composable
fun HomeSection(
@StringRes title: Int,
modifier: Modifier = Modifier,
content: @Composable () -> Unit
) {
Column(modifier) {
Text(
stringResource(title).uppercase(Locale.getDefault()),
style = MaterialTheme.typography.h2,
modifier = Modifier
.paddingFromBaseline(top = 40.dp, bottom = 8.dp)
.padding(horizontal = 16.dp)
)
content()
}
}
목록에 포함된 요소가 많거나
로드해야 할 데이터 세트가 많아서
모든 항목을 동시에 내보내면 성능이 저하되고
앱이 느려지게 되는 경우
Column
또는 Row
사용하여 스크롤 수동 추가@Composable
fun HomeScreen(modifier: Modifier = Modifier) {
Column(
modifier
.verticalScroll(rememberScrollState()) // 👈🏻 Here
.padding(vertical = 16.dp)
) {
SearchBar(Modifier.padding(horizontal = 16.dp))
HomeSection(title = R.string.align_your_body) {
AlignYourBodyRow()
}
HomeSection(title = R.string.favorite_collections) {
FavoriteCollectionsGrid()
}
}
}
// 미리보기 시 스크롤 할 수 있게 화면 크기 제약 > heightDp = 180
@Preview(showBackground = true, backgroundColor = 0xFFF0EAE2, heightDp = 180)
@Composable
fun ScreenContentPreview() {
MySootheTheme { HomeScreen() }
}
@Composable
private fun SootheBottomNavigation(modifier: Modifier = Modifier) {
BottomNavigation(
backgroundColor = MaterialTheme.colors.background, // 하단 전체 네비 색상 변경
modifier = modifier
) {
BottomNavigationItem( // 바텀 네비 메뉴
icon = {
Icon(
imageVector = Icons.Default.Spa,
contentDescription = null
)
},
label = {
Text(stringResource(R.string.bottom_navigation_home))
},
selected = true,
onClick = { }
)
BottomNavigationItem( // 바텀 네비 메뉴
icon = {
Icon(
imageVector = Icons.Default.AccountCircle,
contentDescription = null
)
},
label = {
Text(stringResource(R.string.bottom_navigation_profile))
},
selected = false,
onClick = { }
)
}
}
MySootheTheme
Material 테마 적용Scaffold
추가SootheBottomNavigation
컴포저블이 되도록 설정HomeScreen
컴포저블이 되도록 설정 @Composable
fun MySootheApp() {
MySootheTheme {
Scaffold(
bottomBar = { SootheBottomNavigation() }
) { padding ->
HomeScreen(Modifier.padding(padding))
}
}
}