Skip to content

Commit 4fda6f7

Browse files
committed
library: Remove ripple effect for disabled components
1 parent eb83646 commit 4fda6f7

File tree

15 files changed

+75
-50
lines changed

15 files changed

+75
-50
lines changed

composeApp/src/commonMain/kotlin/component/TextComponent.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ fun TextComponent() {
7777
Text(text = "Right1")
7878
Spacer(Modifier.width(6.dp))
7979
Text(text = "Right2")
80-
},
81-
onClick = {}
80+
}
8281
)
8382

8483
SuperArrow(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ import androidx.compose.ui.Modifier
88
* Returns modifier to be used for the current platform.
99
*/
1010
@SuppressLint("ModifierFactoryExtensionFunction")
11-
actual fun modifierPlatform(modifier: Modifier, isHovered: MutableState<Boolean>): Modifier = modifier
11+
actual fun modifierPlatform(modifier: Modifier, isHovered: MutableState<Boolean>, isEnable: Boolean): Modifier = modifier

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

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

3+
import androidx.compose.foundation.Indication
4+
import androidx.compose.foundation.LocalIndication
35
import androidx.compose.foundation.interaction.MutableInteractionSource
46
import androidx.compose.foundation.layout.Arrangement
57
import androidx.compose.foundation.layout.Row
@@ -33,6 +35,7 @@ import top.yukonga.miuix.kmp.utils.squircleshape.SquircleShape
3335
* @param submit Whether the [Button] is a submit button.
3436
* @param cornerRadius The corner radius of the [Button].
3537
* @param interactionSource The interaction source to be applied to the [Button].
38+
* @param indication The indication to be applied to the [Button].
3639
*/
3740
@Composable
3841
fun Button(
@@ -42,7 +45,8 @@ fun Button(
4245
enabled: Boolean = true,
4346
submit: Boolean = false,
4447
cornerRadius: Dp = 18.dp,
45-
interactionSource: MutableInteractionSource? = null
48+
interactionSource: MutableInteractionSource? = null,
49+
indication: Indication? = LocalIndication.current,
4650
) {
4751
@Suppress("NAME_SHADOWING")
4852
val interactionSource = interactionSource ?: remember { MutableInteractionSource() }
@@ -59,7 +63,8 @@ fun Button(
5963
modifier = modifier.semantics { role = Role.Button },
6064
shape = SquircleShape(cornerRadius),
6165
color = color,
62-
interactionSource = interactionSource
66+
interactionSource = interactionSource,
67+
indication = indication
6368
) {
6469
Row(
6570
Modifier

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import androidx.compose.animation.core.animateDpAsState
55
import androidx.compose.animation.core.animateFloatAsState
66
import androidx.compose.animation.core.tween
77
import androidx.compose.foundation.Canvas
8+
import androidx.compose.foundation.Indication
89
import androidx.compose.foundation.background
910
import androidx.compose.foundation.gestures.detectDragGestures
1011
import androidx.compose.foundation.gestures.detectTapGestures
@@ -42,14 +43,16 @@ import top.yukonga.miuix.kmp.utils.squircleshape.SquircleShape
4243
* @param modifier The modifier to be applied to the [Checkbox].
4344
* @param enabled Whether the [Checkbox] is enabled.
4445
* @param interactionSource The interaction source to be applied to the [Checkbox].
46+
* @param indication The indication to be applied to the [Checkbox].
4547
*/
4648
@Composable
4749
fun Checkbox(
4850
checked: Boolean,
4951
onCheckedChange: ((Boolean) -> Unit)?,
5052
modifier: Modifier = Modifier,
5153
enabled: Boolean = true,
52-
interactionSource: MutableInteractionSource? = null
54+
interactionSource: MutableInteractionSource? = null,
55+
indication: Indication? = null,
5356
) {
5457
@Suppress("NAME_SHADOWING")
5558
val interactionSource = interactionSource ?: remember { MutableInteractionSource() }
@@ -72,27 +75,24 @@ fun Checkbox(
7275
if (onCheckedChange != null) {
7376
Modifier.toggleable(
7477
value = isChecked,
75-
onValueChange = {
76-
onCheckedChange(it)
77-
},
78+
onValueChange = { onCheckedChange(it) },
7879
enabled = enabled,
7980
role = Role.Checkbox,
8081
interactionSource = interactionSource,
81-
indication = null
82+
indication = indication
8283
)
8384
} else {
8485
Modifier
8586
}
8687
}
8788

88-
Box(
89+
Surface(
90+
shape = SquircleShape(100f),
8991
modifier = modifier
90-
.then(toggleableModifier)
9192
.wrapContentSize(Alignment.Center)
9293
.size(22.dp)
94+
.clip(SquircleShape(100f))
9395
.requiredSize(checkboxSize)
94-
.clip(SquircleShape(100.dp))
95-
.background(if (enabled) backgroundColor else disabledBackgroundColor)
9696
.pointerInput(Unit) {
9797
detectTapGestures(
9898
onPress = {
@@ -119,9 +119,12 @@ fun Checkbox(
119119
}
120120
)
121121
}
122+
.then(toggleableModifier)
122123
) {
123124
Canvas(
124-
modifier = Modifier.requiredSize(checkboxSize)
125+
modifier = Modifier
126+
.requiredSize(checkboxSize)
127+
.background(if (enabled) backgroundColor else disabledBackgroundColor)
125128
) {
126129
val svgPath =
127130
"m400-416 236-236q11-11 28-11t28 11q11 11 11 28t-11 28L428-332q-12 12-28 12t-28-12L268-436q-11-11-11-28t11-28q11-11 28-11t28 11l76 76Z"

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

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

33
import androidx.compose.foundation.Indication
4+
import androidx.compose.foundation.LocalIndication
45
import androidx.compose.foundation.clickable
56
import androidx.compose.foundation.interaction.MutableInteractionSource
67
import androidx.compose.foundation.layout.Arrangement
@@ -18,7 +19,6 @@ import androidx.compose.ui.text.font.FontWeight
1819
import androidx.compose.ui.unit.DpSize
1920
import androidx.compose.ui.unit.dp
2021
import top.yukonga.miuix.kmp.theme.MiuixTheme
21-
import top.yukonga.miuix.kmp.utils.createRipple
2222

2323
/**
2424
* A basic component with Miuix style. Widely used in other extension components.
@@ -34,6 +34,7 @@ import top.yukonga.miuix.kmp.utils.createRipple
3434
* @param onClick The callback when the [BasicComponent] is clicked.
3535
* @param interactionSource The interaction source to be applied to the [BasicComponent].
3636
* @param indication The indication to be applied to the [BasicComponent].
37+
* @param enabled Whether the [BasicComponent] is enabled.
3738
*/
3839
@Composable
3940
@Suppress("NAME_SHADOWING")
@@ -48,23 +49,22 @@ fun BasicComponent(
4849
rightActions: @Composable RowScope.() -> Unit = {},
4950
onClick: (() -> Unit)? = null,
5051
interactionSource: MutableInteractionSource? = null,
51-
indication: Indication? = null,
52+
indication: Indication? = LocalIndication.current,
5253
enabled: Boolean = true
5354
) {
5455
val interactionSource = interactionSource ?: remember { MutableInteractionSource() }
55-
val indication = indication ?: createRipple()
5656
val insideMargin = remember { insideMargin } ?: remember { DpSize(16.dp, 16.dp) }
5757
val paddingModifier = remember(insideMargin) {
5858
Modifier.padding(horizontal = insideMargin.width, vertical = insideMargin.height)
5959
}
6060
val titleColor = if (enabled) titleColor else MiuixTheme.colorScheme.disabledOnSecondaryVariant
6161
val summaryColor = if (enabled) summaryColor else MiuixTheme.colorScheme.disabledOnSecondaryVariant
6262
Row(
63-
modifier = if (onClick != null) {
63+
modifier = if (onClick != null && enabled) {
6464
modifier
6565
.clickable(
6666
interactionSource = interactionSource,
67-
indication = indication
67+
indication = indication,
6868
) {
6969
onClick.invoke()
7070
}

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package top.yukonga.miuix.kmp.basic
22

3+
import androidx.compose.foundation.Indication
4+
import androidx.compose.foundation.LocalIndication
35
import androidx.compose.foundation.interaction.MutableInteractionSource
46
import androidx.compose.foundation.layout.Box
57
import androidx.compose.foundation.layout.defaultMinSize
@@ -16,6 +18,18 @@ import androidx.compose.ui.semantics.semantics
1618
import androidx.compose.ui.unit.dp
1719
import top.yukonga.miuix.kmp.theme.MiuixTheme
1820

21+
/**
22+
* A floating action button component with Miuix style.
23+
*
24+
* @param onClick The callback when the [FloatingActionButton] is clicked.
25+
* @param modifier The modifier to be applied to the [FloatingActionButton].
26+
* @param shape The shape of the [FloatingActionButton].
27+
* @param containerColor The color of the [FloatingActionButton].
28+
* @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].
31+
* @param content The [Composable] content of the [FloatingActionButton].
32+
*/
1933
@Composable
2034
fun FloatingActionButton(
2135
onClick: () -> Unit,
@@ -24,6 +38,7 @@ fun FloatingActionButton(
2438
containerColor: Color = MiuixTheme.colorScheme.primary,
2539
shadowElevation: Float = 18f,
2640
interactionSource: MutableInteractionSource? = null,
41+
indication: Indication? = LocalIndication.current,
2742
content: @Composable () -> Unit,
2843
) {
2944
@Suppress("NAME_SHADOWING")
@@ -34,7 +49,8 @@ fun FloatingActionButton(
3449
shape = shape,
3550
color = containerColor,
3651
shadowElevation = shadowElevation,
37-
interactionSource = interactionSource
52+
interactionSource = interactionSource,
53+
indication = indication,
3854
) {
3955
Box(
4056
modifier =

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
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
46
import androidx.compose.foundation.background
57
import androidx.compose.foundation.border
68
import androidx.compose.foundation.clickable
@@ -17,7 +19,6 @@ import androidx.compose.ui.graphics.RectangleShape
1719
import androidx.compose.ui.graphics.Shape
1820
import androidx.compose.ui.graphics.graphicsLayer
1921
import top.yukonga.miuix.kmp.theme.MiuixTheme
20-
import top.yukonga.miuix.kmp.utils.createRipple
2122

2223
/**
2324
* A surface component with Miuix style.
@@ -64,6 +65,7 @@ fun Surface(
6465
* @param border The border of the [Surface].
6566
* @param shadowElevation The shadow elevation of the [Surface].
6667
* @param interactionSource The interaction source to be applied to the [Surface].
68+
* @param indication The indication to be applied to the [Surface].
6769
* @param content The [Composable] content of the [Surface].
6870
*/
6971
@Composable
@@ -77,6 +79,7 @@ fun Surface(
7779
border: BorderStroke? = null,
7880
shadowElevation: Float = 0f,
7981
interactionSource: MutableInteractionSource? = null,
82+
indication: Indication? = LocalIndication.current,
8083
content: @Composable () -> Unit
8184
) {
8285
@Suppress("NAME_SHADOWING")
@@ -93,7 +96,7 @@ fun Surface(
9396
.minimumInteractiveComponentSize()
9497
.clickable(
9598
interactionSource = interactionSource,
96-
indication = createRipple(),
99+
indication = indication,
97100
enabled = enabled,
98101
onClick = onClick
99102
),

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import androidx.compose.animation.core.Spring
55
import androidx.compose.animation.core.animateDpAsState
66
import androidx.compose.animation.core.spring
77
import androidx.compose.animation.core.tween
8+
import androidx.compose.foundation.Indication
89
import androidx.compose.foundation.background
910
import androidx.compose.foundation.gestures.detectDragGestures
1011
import androidx.compose.foundation.gestures.detectTapGestures
@@ -41,14 +42,16 @@ import kotlin.math.absoluteValue
4142
* @param modifier The modifier to be applied to the [Switch].
4243
* @param enabled Whether the [Switch] is enabled.
4344
* @param interactionSource The interaction source to be applied to the [Switch].
45+
* @param indication The indication to be applied to the [Switch].
4446
*/
4547
@Composable
4648
fun Switch(
4749
checked: Boolean,
4850
onCheckedChange: ((Boolean) -> Unit)?,
4951
modifier: Modifier = Modifier,
5052
enabled: Boolean = true,
51-
interactionSource: MutableInteractionSource? = null
53+
interactionSource: MutableInteractionSource? = null,
54+
indication: Indication? = null
5255
) {
5356
@Suppress("NAME_SHADOWING")
5457
val interactionSource = interactionSource ?: remember { MutableInteractionSource() }
@@ -99,7 +102,7 @@ fun Switch(
99102
enabled = enabled,
100103
role = Role.Switch,
101104
interactionSource = interactionSource,
102-
indication = null
105+
indication = indication
103106
)
104107
} else {
105108
Modifier

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/extra/SuperDropdown.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package top.yukonga.miuix.kmp.extra
22

33
import androidx.compose.foundation.Image
4+
import androidx.compose.foundation.Indication
5+
import androidx.compose.foundation.LocalIndication
46
import androidx.compose.foundation.background
57
import androidx.compose.foundation.clickable
68
import androidx.compose.foundation.gestures.detectTapGestures
@@ -66,15 +68,14 @@ import top.yukonga.miuix.kmp.theme.MiuixTheme
6668
import top.yukonga.miuix.kmp.utils.BackHandler
6769
import top.yukonga.miuix.kmp.utils.MiuixPopupUtil.Companion.dismissPopup
6870
import top.yukonga.miuix.kmp.utils.MiuixPopupUtil.Companion.showPopup
69-
import top.yukonga.miuix.kmp.utils.createRipple
7071
import top.yukonga.miuix.kmp.utils.getWindowSize
7172
import top.yukonga.miuix.kmp.utils.squircleshape.SquircleShape
7273
import kotlin.math.roundToInt
7374

7475
/**
7576
* Returns modifier to be used for the current platform.
7677
*/
77-
expect fun modifierPlatform(modifier: Modifier, isHovered: MutableState<Boolean>): Modifier
78+
expect fun modifierPlatform(modifier: Modifier, isHovered: MutableState<Boolean>, isEnable: Boolean): Modifier
7879

7980
/**
8081
* A dropdown with a title and a summary.
@@ -106,12 +107,15 @@ fun SuperDropdown(
106107
defaultWindowInsetsPadding: Boolean = true,
107108
selectedIndex: Int,
108109
onSelectedIndexChange: (Int) -> Unit,
110+
interactionSource: MutableInteractionSource? = null,
111+
indication: Indication? = null,
109112
enabled: Boolean = true
110113
) {
114+
@Suppress("NAME_SHADOWING")
115+
val interactionSource = interactionSource ?: remember { MutableInteractionSource() }
111116
val hapticFeedback = LocalHapticFeedback.current
112117
val density = LocalDensity.current
113118
val coroutineScope = rememberCoroutineScope()
114-
val interactionSource = remember { MutableInteractionSource() }
115119
val isDropdownExpanded = remember { mutableStateOf(false) }
116120
var alignLeft by rememberSaveable { mutableStateOf(true) }
117121
val textMeasurer = rememberTextMeasurer()
@@ -147,9 +151,9 @@ fun SuperDropdown(
147151
)
148152

149153
BasicComponent(
150-
modifier = modifierPlatform(modifier = Modifier, isHovered = isHovered)
154+
modifier = modifierPlatform(modifier = Modifier, isHovered = isHovered, isEnable = enabled)
151155
.background(if (isHovered.value) MiuixTheme.colorScheme.onBackground.copy(0.08f) else Color.Transparent)
152-
.indication(interactionSource, createRipple())
156+
.indication(interactionSource, if (enabled) indication ?: LocalIndication.current else null)
153157
.pointerInput(Unit) {
154158
detectTapGestures(
155159
onPress = { offset ->
@@ -314,7 +318,7 @@ fun DropdownImpl(
314318
modifier = Modifier
315319
.clickable(
316320
interactionSource = dropdownInteractionSource,
317-
indication = createRipple(),
321+
indication = LocalIndication.current,
318322
) {
319323
onSelectedIndexChange(index)
320324
}

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/theme/MiuixTheme.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package top.yukonga.miuix.kmp.theme
22

3+
import androidx.compose.foundation.LocalIndication
4+
import androidx.compose.material3.ripple
35
import androidx.compose.runtime.Composable
46
import androidx.compose.runtime.CompositionLocalProvider
57
import androidx.compose.runtime.ReadOnlyComposable
@@ -31,7 +33,8 @@ fun MiuixTheme(
3133
}
3234
CompositionLocalProvider(
3335
LocalMiuixColor provides colorScheme,
34-
LocalMiuixTextStyles provides miuixTextStyles
36+
LocalMiuixTextStyles provides miuixTextStyles,
37+
LocalIndication provides ripple(),
3538
) {
3639
content()
3740
}

0 commit comments

Comments
 (0)