11package com.texthip.thip.ui.common.buttons
22
3+ import android.annotation.SuppressLint
34import androidx.compose.foundation.layout.Arrangement
5+ import androidx.compose.foundation.layout.Column
46import androidx.compose.foundation.layout.Row
57import androidx.compose.foundation.layout.Spacer
68import androidx.compose.foundation.layout.fillMaxWidth
9+ import androidx.compose.foundation.layout.height
710import androidx.compose.foundation.layout.width
811import androidx.compose.foundation.shape.RoundedCornerShape
912import androidx.compose.runtime.Composable
13+ import androidx.compose.ui.Alignment
1014import androidx.compose.ui.Modifier
1115import androidx.compose.ui.draw.clip
16+ import androidx.compose.ui.platform.LocalConfiguration
1217import androidx.compose.ui.tooling.preview.Preview
1318import androidx.compose.ui.unit.dp
1419import com.texthip.thip.ui.theme.ThipTheme
1520
21+ @SuppressLint(" ConfigurationScreenWidthHeight" )
1622@Composable
1723fun GenreChipRow (
1824 modifier : Modifier = Modifier .width(4.dp),
@@ -21,35 +27,95 @@ fun GenreChipRow(
2127 onSelect : (Int ) -> Unit ,
2228 horizontalArrangement : Arrangement .Horizontal = Arrangement .Center
2329) {
24- Row (
25- modifier = Modifier .fillMaxWidth(),
26- horizontalArrangement = horizontalArrangement
27- ) {
28- genres.forEachIndexed { idx, genre ->
29- OptionChipButton (
30- modifier = Modifier
31- .clip(RoundedCornerShape (20 .dp)), // 버튼 모양에 맞게 클리핑
32- text = genre,
33- isFilled = true ,
34- isSelected = selectedIndex == idx,
35- onClick = {
36- if (selectedIndex == idx) {
37- onSelect(- 1 )
38- } else {
39- onSelect(idx)
30+ val configuration = LocalConfiguration .current
31+ val screenWidthDp = configuration.screenWidthDp
32+
33+ if (screenWidthDp < 360 ) {
34+ Column (
35+ horizontalAlignment = Alignment .CenterHorizontally ,
36+ modifier = Modifier .fillMaxWidth()
37+ ) {
38+ Row (
39+ horizontalArrangement = Arrangement .Center
40+ ) {
41+ genres.take(3 ).forEachIndexed { idx, genre ->
42+ OptionChipButton (
43+ modifier = Modifier
44+ .clip(RoundedCornerShape (20 .dp)),
45+ text = genre,
46+ isFilled = true ,
47+ isSelected = selectedIndex == idx,
48+ onClick = {
49+ if (selectedIndex == idx) {
50+ onSelect(- 1 )
51+ } else {
52+ onSelect(idx)
53+ }
54+ }
55+ )
56+ if (idx < 2 ) {
57+ Spacer (modifier = modifier)
58+ }
59+ }
60+ }
61+ Spacer (modifier = Modifier .height(8 .dp))
62+
63+ Row (
64+ horizontalArrangement = Arrangement .Center
65+ ) {
66+ genres.drop(3 ).forEachIndexed { relativeIdx, genre ->
67+ val idx = relativeIdx + 3
68+ OptionChipButton (
69+ modifier = Modifier
70+ .clip(RoundedCornerShape (20 .dp)),
71+ text = genre,
72+ isFilled = true ,
73+ isSelected = selectedIndex == idx,
74+ onClick = {
75+ if (selectedIndex == idx) {
76+ onSelect(- 1 )
77+ } else {
78+ onSelect(idx)
79+ }
80+ }
81+ )
82+ if (relativeIdx < genres.drop(3 ).size - 1 ) {
83+ Spacer (modifier = modifier)
4084 }
4185 }
42- )
43- if (idx < genres.size - 1 ) {
44- Spacer (modifier = modifier)
86+ }
87+ }
88+ } else {
89+ Row (
90+ modifier = Modifier .fillMaxWidth(),
91+ horizontalArrangement = horizontalArrangement
92+ ) {
93+ genres.forEachIndexed { idx, genre ->
94+ OptionChipButton (
95+ modifier = Modifier
96+ .clip(RoundedCornerShape (20 .dp)),
97+ text = genre,
98+ isFilled = true ,
99+ isSelected = selectedIndex == idx,
100+ onClick = {
101+ if (selectedIndex == idx) {
102+ onSelect(- 1 )
103+ } else {
104+ onSelect(idx)
105+ }
106+ }
107+ )
108+ if (idx < genres.size - 1 ) {
109+ Spacer (modifier = modifier)
110+ }
45111 }
46112 }
47113 }
48114}
49115
50- @Preview()
116+ @Preview(name = " Normal Screen (>=360dp) " , widthDp = 400 )
51117@Composable
52- fun PreviewGenreChipRow () {
118+ fun PreviewGenreChipRowNormal () {
53119 ThipTheme {
54120 GenreChipRow (
55121 genres = listOf (" 문학" , " 과학·IT" , " 사회과학" , " 인문학" , " 예술" ),
@@ -58,3 +124,15 @@ fun PreviewGenreChipRow() {
58124 )
59125 }
60126}
127+
128+ @Preview(name = " Small Screen (<360dp)" , widthDp = 320 )
129+ @Composable
130+ fun PreviewGenreChipRowSmall () {
131+ ThipTheme {
132+ GenreChipRow (
133+ genres = listOf (" 문학" , " 과학·IT" , " 사회과학" , " 인문학" , " 예술" ),
134+ selectedIndex = 2 ,
135+ onSelect = {}
136+ )
137+ }
138+ }
0 commit comments