Skip to content

Commit 6dc395c

Browse files
committed
library: Optimize SuperDropdown & Cleanup code
1 parent 32355cd commit 6dc395c

File tree

25 files changed

+92
-265
lines changed

25 files changed

+92
-265
lines changed

miuix/src/androidMain/kotlin/top/yukonga/miuix/kmp/extra/SuperDropdown.android.kt

Lines changed: 0 additions & 11 deletions
This file was deleted.

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/basic/Button.kt

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
package top.yukonga.miuix.kmp.basic
22

3-
import androidx.compose.foundation.Indication
4-
import androidx.compose.foundation.LocalIndication
5-
import androidx.compose.foundation.interaction.MutableInteractionSource
63
import androidx.compose.foundation.layout.Arrangement
74
import androidx.compose.foundation.layout.Row
85
import androidx.compose.foundation.layout.defaultMinSize
96
import androidx.compose.foundation.layout.padding
107
import androidx.compose.runtime.Composable
118
import androidx.compose.runtime.getValue
12-
import androidx.compose.runtime.remember
139
import androidx.compose.runtime.rememberUpdatedState
1410
import androidx.compose.ui.Alignment
1511
import androidx.compose.ui.Modifier
@@ -28,28 +24,22 @@ import top.yukonga.miuix.kmp.utils.squircleshape.SquircleShape
2824
/**
2925
* A button component with Miuix style.
3026
*
27+
* @param modifier The modifier to be applied to the [Button].
3128
* @param text The text of the [Button].
3229
* @param onClick The callback when the [Button] is clicked.
33-
* @param modifier The modifier to be applied to the [Button].
3430
* @param enabled Whether the [Button] is enabled.
3531
* @param submit Whether the [Button] is a submit button.
3632
* @param cornerRadius The corner radius of the [Button].
37-
* @param interactionSource The interaction source to be applied to the [Button].
38-
* @param indication The indication to be applied to the [Button].
3933
*/
4034
@Composable
4135
fun Button(
36+
modifier: Modifier = Modifier,
4237
text: String,
4338
onClick: () -> Unit,
44-
modifier: Modifier = Modifier,
4539
enabled: Boolean = true,
4640
submit: Boolean = false,
47-
cornerRadius: Dp = 18.dp,
48-
interactionSource: MutableInteractionSource? = null,
49-
indication: Indication? = LocalIndication.current,
41+
cornerRadius: Dp = 18.dp
5042
) {
51-
@Suppress("NAME_SHADOWING")
52-
val interactionSource = interactionSource ?: remember { MutableInteractionSource() }
5343
val hapticFeedback = LocalHapticFeedback.current
5444
val color by rememberUpdatedState(getButtonColor(enabled, submit))
5545
val textColor by rememberUpdatedState(getTextColor(enabled, submit))
@@ -62,9 +52,7 @@ fun Button(
6252
enabled = enabled,
6353
modifier = modifier.semantics { role = Role.Button },
6454
shape = SquircleShape(cornerRadius),
65-
color = color,
66-
interactionSource = interactionSource,
67-
indication = indication
55+
color = color
6856
) {
6957
Row(
7058
Modifier

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/basic/Checkbox.kt

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import androidx.compose.animation.core.tween
77
import androidx.compose.foundation.Canvas
88
import androidx.compose.foundation.background
99
import androidx.compose.foundation.gestures.detectTapGestures
10-
import androidx.compose.foundation.interaction.MutableInteractionSource
1110
import androidx.compose.foundation.layout.requiredSize
1211
import androidx.compose.foundation.layout.size
1312
import androidx.compose.foundation.layout.wrapContentSize
@@ -36,22 +35,18 @@ import top.yukonga.miuix.kmp.utils.squircleshape.SquircleShape
3635
/**
3736
* A checkbox component with Miuix style.
3837
*
38+
* @param modifier The modifier to be applied to the [Checkbox].
3939
* @param checked The current state of the [Checkbox].
4040
* @param onCheckedChange The callback to be called when the state of the [Checkbox] changes.
41-
* @param modifier The modifier to be applied to the [Checkbox].
4241
* @param enabled Whether the [Checkbox] is enabled.
43-
* @param interactionSource The interaction source to be applied to the [Checkbox].
4442
*/
4543
@Composable
4644
fun Checkbox(
45+
modifier: Modifier = Modifier,
4746
checked: Boolean,
4847
onCheckedChange: ((Boolean) -> Unit)?,
49-
modifier: Modifier = Modifier,
5048
enabled: Boolean = true,
51-
interactionSource: MutableInteractionSource? = null,
5249
) {
53-
@Suppress("NAME_SHADOWING")
54-
val interactionSource = interactionSource ?: remember { MutableInteractionSource() }
5550
val isChecked by rememberUpdatedState(checked)
5651
var isPressed by remember { mutableStateOf(false) }
5752
val backgroundColor by animateColorAsState(if (isChecked) MiuixTheme.colorScheme.primary else MiuixTheme.colorScheme.secondary)
@@ -74,8 +69,8 @@ fun Checkbox(
7469
onValueChange = { onCheckedChange(it) },
7570
enabled = enabled,
7671
role = Role.Checkbox,
77-
interactionSource = interactionSource,
78-
indication = null
72+
indication = null,
73+
interactionSource = null
7974
)
8075
} else {
8176
Modifier

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/basic/Component.kt

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package top.yukonga.miuix.kmp.basic
22

3-
import androidx.compose.foundation.Indication
4-
import androidx.compose.foundation.LocalIndication
53
import androidx.compose.foundation.clickable
6-
import androidx.compose.foundation.interaction.MutableInteractionSource
74
import androidx.compose.foundation.layout.Arrangement
85
import androidx.compose.foundation.layout.Column
96
import androidx.compose.foundation.layout.Row
@@ -32,8 +29,6 @@ import top.yukonga.miuix.kmp.theme.MiuixTheme
3229
* @param leftAction The [Composable] content that on the left side of the [BasicComponent].
3330
* @param rightActions The [Composable] content on the right side of the [BasicComponent].
3431
* @param onClick The callback when the [BasicComponent] is clicked.
35-
* @param interactionSource The interaction source to be applied to the [BasicComponent].
36-
* @param indication The indication to be applied to the [BasicComponent].
3732
* @param enabled Whether the [BasicComponent] is enabled.
3833
*/
3934
@Composable
@@ -48,11 +43,8 @@ fun BasicComponent(
4843
leftAction: @Composable (() -> Unit?)? = null,
4944
rightActions: @Composable RowScope.() -> Unit = {},
5045
onClick: (() -> Unit)? = null,
51-
interactionSource: MutableInteractionSource? = null,
52-
indication: Indication? = LocalIndication.current,
5346
enabled: Boolean = true
5447
) {
55-
val interactionSource = interactionSource ?: remember { MutableInteractionSource() }
5648
val insideMargin = remember { insideMargin } ?: remember { DpSize(16.dp, 16.dp) }
5749
val paddingModifier = remember(insideMargin) {
5850
Modifier.padding(horizontal = insideMargin.width, vertical = insideMargin.height)
@@ -62,12 +54,7 @@ fun BasicComponent(
6254
Row(
6355
modifier = if (onClick != null && enabled) {
6456
modifier
65-
.clickable(
66-
interactionSource = interactionSource,
67-
indication = indication,
68-
) {
69-
onClick.invoke()
70-
}
57+
.clickable { onClick.invoke() }
7158
} else {
7259
modifier
7360
}

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/basic/FloatingActionButton.kt

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,36 +21,28 @@ import top.yukonga.miuix.kmp.theme.MiuixTheme
2121
/**
2222
* A floating action button component with Miuix style.
2323
*
24-
* @param onClick The callback when the [FloatingActionButton] is clicked.
2524
* @param modifier The modifier to be applied to the [FloatingActionButton].
25+
* @param onClick The callback when the [FloatingActionButton] is clicked.
2626
* @param shape The shape of the [FloatingActionButton].
2727
* @param containerColor The color of the [FloatingActionButton].
2828
* @param shadowElevation The shadow elevation of the [FloatingActionButton].
29-
* @param interactionSource The interaction source to be applied to the [FloatingActionButton].
30-
* @param indication The indication to be applied to the [FloatingActionButton].
3129
* @param content The [Composable] content of the [FloatingActionButton].
3230
*/
3331
@Composable
3432
fun FloatingActionButton(
35-
onClick: () -> Unit,
3633
modifier: Modifier = Modifier,
34+
onClick: () -> Unit,
3735
shape: Shape = RoundedCornerShape(50.dp),
3836
containerColor: Color = MiuixTheme.colorScheme.primary,
3937
shadowElevation: Float = 18f,
40-
interactionSource: MutableInteractionSource? = null,
41-
indication: Indication? = LocalIndication.current,
4238
content: @Composable () -> Unit,
4339
) {
44-
@Suppress("NAME_SHADOWING")
45-
val interactionSource = interactionSource ?: remember { MutableInteractionSource() }
4640
Surface(
4741
onClick = onClick,
4842
modifier = modifier.semantics { role = Role.Button },
4943
shape = shape,
5044
color = containerColor,
51-
shadowElevation = shadowElevation,
52-
interactionSource = interactionSource,
53-
indication = indication,
45+
shadowElevation = shadowElevation
5446
) {
5547
Box(
5648
modifier =

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/basic/NavigationBar.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,18 @@ import top.yukonga.miuix.kmp.utils.platform
4444
/**
4545
* A navigation bar that with 2 to 5 items.
4646
*
47+
* @param modifier The modifier to be applied to the [NavigationBar].
4748
* @param items The items of the [NavigationBar].
4849
* @param selected The selected index of the [NavigationBar].
49-
* @param modifier The modifier to be applied to the [NavigationBar].
5050
* @param color The color of the [NavigationBar].
5151
* @param onClick The callback when the item of the [NavigationBar] is clicked.
5252
* @param defaultWindowInsetsPadding whether to apply default window insets padding to the [NavigationBar].
5353
*/
5454
@Composable
5555
fun NavigationBar(
56+
modifier: Modifier = Modifier,
5657
items: List<NavigationItem>,
5758
selected: Int,
58-
modifier: Modifier = Modifier,
5959
color: Color = MiuixTheme.colorScheme.surfaceContainer,
6060
onClick: (Int) -> Unit,
6161
defaultWindowInsetsPadding: Boolean = true

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/basic/SearchBar.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,22 @@ import top.yukonga.miuix.kmp.utils.squircleshape.SquircleShape
3737
/**
3838
* A search bar with Miuix style.
3939
*
40-
* @param inputField the input field to input a query in the search bar.
41-
* @param expanded whether the search bar is expanded and showing search results.
42-
* @param onExpandedChange the callback to be invoked when the search bar's expanded state is
40+
* @param modifier the [Modifier] to be applied to the [SearchBar].
41+
* @param inputField the input field to input a query in the [SearchBar].
42+
* @param expanded whether the [SearchBar] is expanded and showing search results.
43+
* @param onExpandedChange the callback to be invoked when the [SearchBar]'s expanded state is
4344
* changed.
44-
* @param outsideRightAction the action to be shown at the right side of the search bar when it is
45+
* @param outsideRightAction the action to be shown at the right side of the [SearchBar] when it is
4546
* expanded.
46-
* @param modifier the [Modifier] to be applied to this search bar.
47-
* @param content the content to be shown when the search bar is expanded.
47+
* @param content the content to be shown when the [SearchBar] is expanded.
4848
*/
4949
@Composable
5050
fun SearchBar(
51+
modifier: Modifier = Modifier,
5152
inputField: @Composable () -> Unit,
5253
expanded: Boolean = false,
5354
onExpandedChange: (Boolean) -> Unit,
5455
outsideRightAction: @Composable (() -> Unit)? = null,
55-
modifier: Modifier = Modifier,
5656
content: @Composable ColumnScope.() -> Unit
5757
) {
5858
Surface(

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/basic/SmallTitle.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ import top.yukonga.miuix.kmp.theme.MiuixTheme
1414
/**
1515
* A title component with Miuix style.
1616
*
17+
* @param modifier The modifier to be applied to the [SmallTitle].
1718
* @param text The text to be displayed in the title.
1819
* @param textColor The color of the [SmallTitle].
19-
* @param modifier The modifier to be applied to the [SmallTitle].
2020
* @param insideMargin The margin inside the [SmallTitle].
2121
*/
2222
@Composable
2323
fun SmallTitle(
24+
modifier: Modifier = Modifier,
2425
text: String,
2526
textColor: Color = MiuixTheme.colorScheme.onBackgroundVariant,
26-
modifier: Modifier = Modifier,
2727
insideMargin: DpSize = DpSize(28.dp, 8.dp),
2828
) {
2929
val paddingModifier = remember(insideMargin) {

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/basic/Surface.kt

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
package top.yukonga.miuix.kmp.basic
22

33
import androidx.compose.foundation.BorderStroke
4-
import androidx.compose.foundation.Indication
5-
import androidx.compose.foundation.LocalIndication
64
import androidx.compose.foundation.background
75
import androidx.compose.foundation.border
86
import androidx.compose.foundation.clickable
9-
import androidx.compose.foundation.interaction.MutableInteractionSource
107
import androidx.compose.material3.minimumInteractiveComponentSize
118
import androidx.compose.runtime.Composable
129
import androidx.compose.runtime.NonRestartableComposable
1310
import androidx.compose.runtime.Stable
14-
import androidx.compose.runtime.remember
1511
import androidx.compose.ui.Modifier
1612
import androidx.compose.ui.draw.clip
1713
import androidx.compose.ui.graphics.Color
@@ -57,34 +53,27 @@ fun Surface(
5753
/**
5854
* A surface component with Miuix style.
5955
*
60-
* @param onClick The callback when the [Surface] is clicked.
6156
* @param modifier The modifier to be applied to the [Surface].
57+
* @param onClick The callback when the [Surface] is clicked.
6258
* @param enabled Whether the [Surface] is enabled.
6359
* @param shape The shape of the [Surface].
6460
* @param color The color of the [Surface].
6561
* @param border The border of the [Surface].
6662
* @param shadowElevation The shadow elevation of the [Surface].
67-
* @param interactionSource The interaction source to be applied to the [Surface].
68-
* @param indication The indication to be applied to the [Surface].
6963
* @param content The [Composable] content of the [Surface].
7064
*/
7165
@Composable
7266
@NonRestartableComposable
7367
fun Surface(
74-
onClick: () -> Unit,
7568
modifier: Modifier = Modifier,
69+
onClick: () -> Unit,
7670
enabled: Boolean = true,
7771
shape: Shape = RectangleShape,
7872
color: Color = MiuixTheme.colorScheme.background,
7973
border: BorderStroke? = null,
8074
shadowElevation: Float = 0f,
81-
interactionSource: MutableInteractionSource? = null,
82-
indication: Indication? = LocalIndication.current,
8375
content: @Composable () -> Unit
8476
) {
85-
@Suppress("NAME_SHADOWING")
86-
val interactionSource = interactionSource ?: remember { MutableInteractionSource() }
87-
8877
Box(
8978
modifier = modifier
9079
.surface(
@@ -95,8 +84,6 @@ fun Surface(
9584
)
9685
.minimumInteractiveComponentSize()
9786
.clickable(
98-
interactionSource = interactionSource,
99-
indication = indication,
10087
enabled = enabled,
10188
onClick = onClick
10289
),

0 commit comments

Comments
 (0)