@@ -2,6 +2,7 @@ package com.nexters.bandalart.feature.home.ui.bandalart
2
2
3
3
import androidx.compose.foundation.background
4
4
import androidx.compose.foundation.layout.Box
5
+ import androidx.compose.foundation.layout.BoxWithConstraints
5
6
import androidx.compose.foundation.layout.fillMaxWidth
6
7
import androidx.compose.foundation.shape.RoundedCornerShape
7
8
import androidx.compose.runtime.Composable
@@ -10,8 +11,6 @@ import androidx.compose.ui.Modifier
10
11
import androidx.compose.ui.draw.clip
11
12
import androidx.compose.ui.layout.Layout
12
13
import androidx.compose.ui.layout.layoutId
13
- import androidx.compose.ui.platform.LocalConfiguration
14
- import androidx.compose.ui.platform.LocalContext
15
14
import androidx.compose.ui.unit.Constraints
16
15
import androidx.compose.ui.unit.dp
17
16
import bandalart.composeapp.generated.resources.Res
@@ -33,82 +32,81 @@ fun BandalartChart(
33
32
onHomeUiAction : (HomeUiAction ) -> Unit ,
34
33
modifier : Modifier = Modifier ,
35
34
) {
36
- val screenWidthDp = LocalConfiguration .current.screenWidthDp.dp
37
- val paddedMaxWidth = remember(screenWidthDp) {
38
- screenWidthDp - (15 .dp * 2 )
39
- }
35
+ BoxWithConstraints {
36
+ val paddedMaxWidth = remember(maxWidth) { maxWidth - (15 .dp * 2 ) }
40
37
41
- val subCellList = persistentListOf(
42
- SubCell (2 , 3 , 1 , 1 , bandalartCellData.children[0 ]),
43
- SubCell (3 , 2 , 1 , 0 , bandalartCellData.children[1 ]),
44
- SubCell (3 , 2 , 1 , 1 , bandalartCellData.children[2 ]),
45
- SubCell (2 , 3 , 0 , 1 , bandalartCellData.children[3 ]),
46
- )
38
+ val subCellList = persistentListOf(
39
+ SubCell (2 , 3 , 1 , 1 , bandalartCellData.children[0 ]),
40
+ SubCell (3 , 2 , 1 , 0 , bandalartCellData.children[1 ]),
41
+ SubCell (3 , 2 , 1 , 1 , bandalartCellData.children[2 ]),
42
+ SubCell (2 , 3 , 0 , 1 , bandalartCellData.children[3 ]),
43
+ )
47
44
48
- Layout (
49
- modifier = modifier
50
- .fillMaxWidth()
51
- .clip(RoundedCornerShape (8 .dp)),
52
- content = {
53
- for (index in subCellList.indices) {
45
+ Layout (
46
+ modifier = modifier
47
+ .fillMaxWidth()
48
+ .clip(RoundedCornerShape (8 .dp)),
49
+ content = {
50
+ for (index in subCellList.indices) {
51
+ Box (
52
+ modifier = Modifier
53
+ .layoutId(stringResource(Res .string.home_layout_id, index + 1 ))
54
+ .clip(RoundedCornerShape (12 .dp))
55
+ .background(color = Gray300 ),
56
+ ) {
57
+ BandalartCellGrid (
58
+ bandalartData = bandalartData,
59
+ subCell = subCellList[index],
60
+ rows = subCellList[index].rowCnt,
61
+ cols = subCellList[index].colCnt,
62
+ onHomeUiAction = onHomeUiAction,
63
+ )
64
+ }
65
+ }
54
66
Box (
55
67
modifier = Modifier
56
- .layoutId(stringResource(Res .string.home_layout_id, index + 1 ))
57
- .clip(RoundedCornerShape (12 .dp))
58
- .background(color = Gray300 ),
68
+ .layoutId(stringResource(Res .string.home_main_id ))
69
+ .clip(RoundedCornerShape (10 .dp))
70
+ .background(color = bandalartData.mainColor.toColor() ),
59
71
) {
60
- BandalartCellGrid (
72
+ BandalartCell (
73
+ cellType = CellType .MAIN ,
61
74
bandalartData = bandalartData,
62
- subCell = subCellList[index],
63
- rows = subCellList[index].rowCnt,
64
- cols = subCellList[index].colCnt,
75
+ cellData = bandalartCellData,
65
76
onHomeUiAction = onHomeUiAction,
66
77
)
67
78
}
68
- }
69
- Box (
70
- modifier = Modifier
71
- .layoutId(stringResource(Res .string.home_main_id))
72
- .clip(RoundedCornerShape (10 .dp))
73
- .background(color = bandalartData.mainColor.toColor()),
74
- ) {
75
- BandalartCell (
76
- cellType = CellType .MAIN ,
77
- bandalartData = bandalartData,
78
- cellData = bandalartCellData,
79
- onHomeUiAction = onHomeUiAction,
80
- )
81
- }
82
- },
83
- ) { measurables, constraints ->
84
- val sub1 = measurables.first { it.layoutId == " Sub 1" }
85
- val sub2 = measurables.first { it.layoutId == " Sub 2" }
86
- val sub3 = measurables.first { it.layoutId == " Sub 3" }
87
- val sub4 = measurables.first { it.layoutId == " Sub 4" }
88
- val main = measurables.first { it.layoutId == " Main" }
79
+ },
80
+ ) { measurables, constraints ->
81
+ val sub1 = measurables.first { it.layoutId == " Sub 1" }
82
+ val sub2 = measurables.first { it.layoutId == " Sub 2" }
83
+ val sub3 = measurables.first { it.layoutId == " Sub 3" }
84
+ val sub4 = measurables.first { it.layoutId == " Sub 4" }
85
+ val main = measurables.first { it.layoutId == " Main" }
89
86
90
- val chartWidth = paddedMaxWidth.roundToPx()
91
- val mainWidth = chartWidth / 5
92
- val padding = 1 .dp.roundToPx()
87
+ val chartWidth = paddedMaxWidth.roundToPx()
88
+ val mainWidth = chartWidth / 5
89
+ val padding = 1 .dp.roundToPx()
93
90
94
- val mainConstraints = Constraints .fixed(width = mainWidth, height = mainWidth)
95
- val sub1Constraints = Constraints .fixed(width = mainWidth * 3 - padding, height = mainWidth * 2 - padding)
96
- val sub2Constraints = Constraints .fixed(width = mainWidth * 2 - padding, height = mainWidth * 3 - padding)
97
- val sub3Constraints = Constraints .fixed(width = mainWidth * 2 - padding, height = mainWidth * 3 - padding)
98
- val sub4Constraints = Constraints .fixed(width = mainWidth * 3 - padding, height = mainWidth * 2 - padding)
91
+ val mainConstraints = Constraints .fixed(width = mainWidth, height = mainWidth)
92
+ val sub1Constraints = Constraints .fixed(width = mainWidth * 3 - padding, height = mainWidth * 2 - padding)
93
+ val sub2Constraints = Constraints .fixed(width = mainWidth * 2 - padding, height = mainWidth * 3 - padding)
94
+ val sub3Constraints = Constraints .fixed(width = mainWidth * 2 - padding, height = mainWidth * 3 - padding)
95
+ val sub4Constraints = Constraints .fixed(width = mainWidth * 3 - padding, height = mainWidth * 2 - padding)
99
96
100
- val mainPlaceable = main.measure(mainConstraints)
101
- val sub1Placeable = sub1.measure(sub1Constraints)
102
- val sub2Placeable = sub2.measure(sub2Constraints)
103
- val sub3Placeable = sub3.measure(sub3Constraints)
104
- val sub4Placeable = sub4.measure(sub4Constraints)
97
+ val mainPlaceable = main.measure(mainConstraints)
98
+ val sub1Placeable = sub1.measure(sub1Constraints)
99
+ val sub2Placeable = sub2.measure(sub2Constraints)
100
+ val sub3Placeable = sub3.measure(sub3Constraints)
101
+ val sub4Placeable = sub4.measure(sub4Constraints)
105
102
106
- layout(width = chartWidth, height = chartWidth) {
107
- mainPlaceable.place(x = mainWidth * 2 , y = mainWidth * 2 )
108
- sub1Placeable.place(x = 0 , y = 0 )
109
- sub2Placeable.place(x = mainWidth * 3 + padding, y = 0 )
110
- sub3Placeable.place(x = 0 , y = mainWidth * 2 + padding)
111
- sub4Placeable.place(x = mainWidth * 2 + padding, y = mainWidth * 3 + padding)
103
+ layout(width = chartWidth, height = chartWidth) {
104
+ mainPlaceable.place(x = mainWidth * 2 , y = mainWidth * 2 )
105
+ sub1Placeable.place(x = 0 , y = 0 )
106
+ sub2Placeable.place(x = mainWidth * 3 + padding, y = 0 )
107
+ sub3Placeable.place(x = 0 , y = mainWidth * 2 + padding)
108
+ sub4Placeable.place(x = mainWidth * 2 + padding, y = mainWidth * 3 + padding)
109
+ }
112
110
}
113
111
}
114
112
}
0 commit comments