@@ -7,6 +7,7 @@ import androidx.compose.foundation.LocalIndication
77import androidx.compose.foundation.clickable
88import androidx.compose.foundation.interaction.MutableInteractionSource
99import androidx.compose.foundation.layout.Arrangement
10+ import androidx.compose.foundation.layout.Column
1011import androidx.compose.foundation.layout.PaddingValues
1112import androidx.compose.foundation.layout.Row
1213import androidx.compose.foundation.layout.RowScope
@@ -22,7 +23,6 @@ import androidx.compose.runtime.remember
2223import androidx.compose.ui.Alignment
2324import androidx.compose.ui.Modifier
2425import androidx.compose.ui.graphics.Color
25- import androidx.compose.ui.layout.SubcomposeLayout
2626import androidx.compose.ui.text.font.FontWeight
2727import androidx.compose.ui.unit.dp
2828import top.yukonga.miuix.kmp.interfaces.HoldDownInteraction
@@ -50,7 +50,7 @@ fun BasicComponent(
5050 titleColor : BasicComponentColors = BasicComponentDefaults .titleColor(),
5151 summary : String? = null,
5252 summaryColor : BasicComponentColors = BasicComponentDefaults .summaryColor(),
53- leftAction : @Composable (() -> Unit? )? = null,
53+ leftAction : @Composable (() -> Unit )? = null,
5454 rightActions : @Composable RowScope .() -> Unit = {},
5555 modifier : Modifier = Modifier ,
5656 insideMargin : PaddingValues = BasicComponentDefaults .InsideMargin ,
@@ -77,7 +77,7 @@ fun BasicComponent(
7777 }
7878 }
7979
80- val clickableModifier = remember(onClick, enabled, interactionSource) {
80+ val clickableModifier = remember(onClick, enabled, interactionSource, indication ) {
8181 if (onClick != null && enabled) {
8282 Modifier .clickable(
8383 indication = indication,
@@ -87,85 +87,41 @@ fun BasicComponent(
8787 } else Modifier
8888 }
8989
90- val titleContent: (@Composable () -> Unit )? = remember(title, enabled, titleColor) {
91- title?.let { text ->
92- {
90+ Row (
91+ modifier = modifier
92+ .heightIn(min = 56 .dp)
93+ .fillMaxWidth()
94+ .then(clickableModifier)
95+ .padding(insideMargin),
96+ verticalAlignment = Alignment .CenterVertically
97+ ) {
98+ // Left action (optional)
99+ leftAction?.let { it() }
100+
101+ // Content
102+ Column (
103+ modifier = Modifier .weight(1f ),
104+ verticalArrangement = Arrangement .Center
105+ ) {
106+ if (title != null ) {
93107 Text (
94- text = text ,
108+ text = title ,
95109 fontSize = MiuixTheme .textStyles.headline1.fontSize,
96110 fontWeight = FontWeight .Medium ,
97111 color = titleColor.color(enabled)
98112 )
99113 }
100- }
101- }
102-
103- val summaryContent: (@Composable () -> Unit )? = remember(summary, enabled, summaryColor) {
104- summary?.let { text ->
105- {
114+ if (summary != null ) {
106115 Text (
107- text = text ,
116+ text = summary ,
108117 fontSize = MiuixTheme .textStyles.body2.fontSize,
109118 color = summaryColor.color(enabled)
110119 )
111120 }
112121 }
113- }
114122
115- SubcomposeLayout (
116- modifier = modifier
117- .heightIn(min = 56 .dp)
118- .fillMaxWidth()
119- .then(clickableModifier)
120- .padding(insideMargin)
121- ) { constraints ->
122- val looseConstraints = constraints.copy(minWidth = 0 , minHeight = 0 )
123- // 1. leftAction
124- val leftPlaceables = leftAction?.let {
125- subcompose(" leftAction" ) { it() }.map { it -> it.measure(looseConstraints) }
126- } ? : emptyList()
127- val leftWidth = leftPlaceables.maxOfOrNull { it.width } ? : 0
128- val leftHeight = leftPlaceables.maxOfOrNull { it.height } ? : 0
129- // 2. rightActions
130- val rightPlaceables = subcompose(" rightActions" ) {
131- Row (
132- horizontalArrangement = Arrangement .End ,
133- verticalAlignment = Alignment .CenterVertically ,
134- content = rightActions
135- )
136- }.map { it.measure(looseConstraints) }
137- val rightWidth = rightPlaceables.maxOfOrNull { it.width } ? : 0
138- val rightHeight = rightPlaceables.maxOfOrNull { it.height } ? : 0
139- // 3. content
140- val contentMaxWidth = maxOf(0 , constraints.maxWidth - leftWidth - rightWidth - 16 .dp.roundToPx())
141- val titlePlaceable = titleContent
142- ?.let { subcompose(" title" , it).first() }
143- ?.measure(looseConstraints.copy(maxWidth = contentMaxWidth))
144- val summaryPlaceable = summaryContent
145- ?.let { subcompose(" summary" , it).first() }
146- ?.measure(looseConstraints.copy(maxWidth = contentMaxWidth))
147- val contentHeight = (titlePlaceable?.height ? : 0 ) + (summaryPlaceable?.height ? : 0 )
148- val layoutHeight = maxOf(leftHeight, rightHeight, contentHeight)
149- layout(constraints.maxWidth, layoutHeight) {
150- var x = 0
151- // leftAction
152- leftPlaceables.forEach {
153- it.placeRelative(x, (layoutHeight - it.height) / 2 )
154- x + = it.width
155- }
156- // content
157- var contentY = (layoutHeight - contentHeight) / 2
158- titlePlaceable?.let {
159- it.placeRelative(x, contentY)
160- contentY + = it.height
161- }
162- summaryPlaceable?.placeRelative(x, contentY)
163- // rightActions
164- val rightX = constraints.maxWidth - rightWidth
165- rightPlaceables.forEach {
166- it.placeRelative(rightX, (layoutHeight - it.height) / 2 )
167- }
168- }
123+ // Right actions (optional)
124+ rightActions()
169125 }
170126}
171127
0 commit comments