Skip to content

Commit 6e97982

Browse files
committed
library: Used Modifier.hoverable
1 parent 0bd00da commit 6e97982

File tree

8 files changed

+11
-159
lines changed

8 files changed

+11
-159
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/extra/SuperDropdown.kt

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import androidx.compose.foundation.LocalIndication
55
import androidx.compose.foundation.background
66
import androidx.compose.foundation.clickable
77
import androidx.compose.foundation.gestures.detectTapGestures
8+
import androidx.compose.foundation.hoverable
89
import androidx.compose.foundation.indication
9-
import androidx.compose.foundation.interaction.HoverInteraction
1010
import androidx.compose.foundation.interaction.MutableInteractionSource
1111
import androidx.compose.foundation.interaction.PressInteraction
1212
import androidx.compose.foundation.layout.Arrangement
@@ -129,7 +129,6 @@ fun SuperDropdown(
129129
val hapticFeedback = LocalHapticFeedback.current
130130
val actionColor = if (enabled) MiuixTheme.colorScheme.onSurfaceVariantActions else MiuixTheme.colorScheme.disabledOnSecondaryVariant
131131
var alignLeft by rememberSaveable { mutableStateOf(true) }
132-
val isHovered = remember { mutableStateOf(false) }
133132
var componentInnerOffsetXPx by remember { mutableIntStateOf(0) }
134133
var componentInnerOffsetYPx by remember { mutableIntStateOf(0) }
135134
var componentInnerHeightPx by remember { mutableIntStateOf(0) }
@@ -154,27 +153,17 @@ fun SuperDropdown(
154153
}
155154
held.value = null
156155
}
157-
if (isHovered.value) {
158-
coroutineScope.launch {
159-
interactionSource.emit(HoverInteraction.Enter())
160-
}
161-
} else {
162-
coroutineScope.launch {
163-
interactionSource.emit(HoverInteraction.Exit(HoverInteraction.Enter()))
164-
}
165-
}
166156
}
167157

168158
BasicComponent(
169-
modifier = modifierPlatform(
170-
modifier = modifier,
171-
isHovered = isHovered,
172-
isEnable = enabled
173-
)
159+
modifier = modifier
174160
.indication(
175161
interactionSource = interactionSource,
176162
indication = LocalIndication.current
177163
)
164+
.hoverable(
165+
interactionSource = interactionSource
166+
)
178167
.pointerInput(Unit) {
179168
detectTapGestures(
180169
onPress = { position ->
@@ -524,9 +513,4 @@ val dropdownStates = mutableStateListOf<MutableState<Boolean>>()
524513
enum class DropDownMode {
525514
Normal,
526515
AlwaysOnRight
527-
}
528-
529-
/**
530-
* Returns modifier to be used for the current platform.
531-
*/
532-
expect fun modifierPlatform(modifier: Modifier, isHovered: MutableState<Boolean>, isEnable: Boolean): Modifier
516+
}

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

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import androidx.compose.foundation.LocalIndication
55
import androidx.compose.foundation.background
66
import androidx.compose.foundation.clickable
77
import androidx.compose.foundation.gestures.detectTapGestures
8+
import androidx.compose.foundation.hoverable
89
import androidx.compose.foundation.indication
9-
import androidx.compose.foundation.interaction.HoverInteraction
1010
import androidx.compose.foundation.interaction.MutableInteractionSource
1111
import androidx.compose.foundation.interaction.PressInteraction
1212
import androidx.compose.foundation.layout.Arrangement
@@ -133,7 +133,6 @@ fun SuperSpinner(
133133
val hapticFeedback = LocalHapticFeedback.current
134134
val actionColor = if (enabled) MiuixTheme.colorScheme.onSurfaceVariantActions else MiuixTheme.colorScheme.disabledOnSecondaryVariant
135135
var alignLeft by rememberSaveable { mutableStateOf(true) }
136-
val isHovered = remember { mutableStateOf(false) }
137136
var componentInnerOffsetXPx by remember { mutableIntStateOf(0) }
138137
var componentInnerOffsetYPx by remember { mutableIntStateOf(0) }
139138
var componentInnerHeightPx by remember { mutableIntStateOf(0) }
@@ -158,27 +157,17 @@ fun SuperSpinner(
158157
}
159158
held.value = null
160159
}
161-
if (isHovered.value) {
162-
coroutineScope.launch {
163-
interactionSource.emit(HoverInteraction.Enter())
164-
}
165-
} else {
166-
coroutineScope.launch {
167-
interactionSource.emit(HoverInteraction.Exit(HoverInteraction.Enter()))
168-
}
169-
}
170160
}
171161

172162
BasicComponent(
173-
modifier = modifierPlatform(
174-
modifier = modifier,
175-
isHovered = isHovered,
176-
isEnable = enabled
177-
)
163+
modifier = modifier
178164
.indication(
179165
interactionSource = interactionSource,
180166
indication = LocalIndication.current
181167
)
168+
.hoverable(
169+
interactionSource = interactionSource
170+
)
182171
.pointerInput(Unit) {
183172
detectTapGestures(
184173
onPress = { position ->

miuix/src/desktopMain/kotlin/top/yukonga/miuix/kmp/extra/SuperDropdown.desktop.kt

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

miuix/src/iosMain/kotlin/top/yukonga/miuix/kmp/extra/SuperDropdown.ios.kt

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

miuix/src/jsMain/kotlin/top/yukonga/miuix/kmp/extra/SuperDropdown.js.kt

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

miuix/src/macosMain/kotlin/top/yukonga/miuix/kmp/extra/SuperDropdown.macos.kt

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

miuix/src/wasmJsMain/kotlin/top/yukonga/miuix/kmp/extra/SuperDropdown.wasmJs.kt

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

0 commit comments

Comments
 (0)