Skip to content

Commit 17bdff9

Browse files
committed
library: Optimize hapticFeedback experience
1 parent 9c996ab commit 17bdff9

File tree

9 files changed

+25
-21
lines changed

9 files changed

+25
-21
lines changed

composeApp/src/commonMain/kotlin/UITest.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import androidx.compose.runtime.setValue
2626
import androidx.compose.runtime.snapshotFlow
2727
import androidx.compose.ui.Modifier
2828
import androidx.compose.ui.graphics.Color
29+
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
30+
import androidx.compose.ui.platform.LocalHapticFeedback
2931
import androidx.compose.ui.platform.LocalUriHandler
3032
import androidx.compose.ui.unit.dp
3133
import kotlinx.coroutines.FlowPreview
@@ -107,6 +109,7 @@ fun UITest(
107109
val showBottomPopup = remember { mutableStateOf(false) }
108110

109111
val uriHandler = LocalUriHandler.current
112+
val hapticFeedback = LocalHapticFeedback.current
110113

111114
Scaffold(
112115
modifier = Modifier.fillMaxSize(),
@@ -142,6 +145,7 @@ fun UITest(
142145
coroutineScope.launch {
143146
pagerState.animateScrollToPage(index)
144147
}
148+
hapticFeedback.performHapticFeedback(HapticFeedbackType.ContextClick)
145149
dismissPopup(showTopPopup)
146150
isTopPopupExpanded.value = false
147151
},
@@ -190,6 +194,7 @@ fun UITest(
190194
coroutineScope.launch {
191195
pagerState.animateScrollToPage(index)
192196
}
197+
hapticFeedback.performHapticFeedback(HapticFeedbackType.ContextClick)
193198
dismissPopup(showTopPopup)
194199
isTopPopupExpanded.value = false
195200
},
@@ -243,6 +248,7 @@ fun UITest(
243248
coroutineScope.launch {
244249
pagerState.animateScrollToPage(index)
245250
}
251+
hapticFeedback.performHapticFeedback(HapticFeedbackType.ContextClick)
246252
dismissPopup(showBottomPopup)
247253
isBottomPopupExpanded.value = false
248254
},

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ fun Checkbox(
7878
value = isChecked,
7979
onValueChange = {
8080
onCheckedChange(it)
81-
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
81+
if (it) hapticFeedback.performHapticFeedback(HapticFeedbackType.ToggleOn)
82+
else hapticFeedback.performHapticFeedback(HapticFeedbackType.ToggleOff)
8283
},
8384
enabled = enabled,
8485
role = Role.Checkbox,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ fun Slider(
9696
currentValue = calculateProgress(dragOffset, size.width)
9797
updatedOnProgressChange(currentValue)
9898
if ((currentValue == minValue || currentValue == maxValue) && !hapticTriggered) {
99-
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
99+
hapticFeedback.performHapticFeedback(HapticFeedbackType.GestureEnd)
100100
hapticTriggered = true
101101
} else if (currentValue != minValue && currentValue != maxValue) {
102102
hapticTriggered = false

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fun SmallTitle(
3232
modifier = modifier.then(paddingModifier),
3333
text = text,
3434
fontSize = MiuixTheme.textStyles.subtitle.fontSize,
35-
fontWeight = FontWeight.Medium,
35+
fontWeight = FontWeight.Bold,
3636
color = textColor
3737
)
3838
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ fun Switch(
9797
value = isChecked,
9898
onValueChange = {
9999
onCheckedChange(it)
100-
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
100+
if (it) hapticFeedback.performHapticFeedback(HapticFeedbackType.ToggleOn)
101+
else hapticFeedback.performHapticFeedback(HapticFeedbackType.ToggleOff)
101102
},
102103
enabled = enabled,
103104
role = Role.Switch,
@@ -241,4 +242,4 @@ class SwitchColors(
241242
@Stable
242243
internal fun uncheckedTrackColor(enabled: Boolean): Color =
243244
if (enabled) uncheckedTrackColor else disabledUncheckedTrackColor
244-
}
245+
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import androidx.compose.ui.platform.LocalDensity
2020
import androidx.compose.ui.semantics.Role
2121
import androidx.compose.ui.semantics.role
2222
import androidx.compose.ui.semantics.semantics
23+
import androidx.compose.ui.text.font.FontWeight
2324
import androidx.compose.ui.unit.Dp
2425
import androidx.compose.ui.unit.dp
2526
import androidx.compose.ui.unit.times
@@ -58,8 +59,7 @@ fun TabRow(
5859
val density = LocalDensity.current
5960
var tabWidth: Dp
6061
with(density) {
61-
tabWidth =
62-
((windowSize.width.toDp() - (tabs.size - 1) * 9.dp) / tabs.size).coerceAtLeast(62.dp)
62+
tabWidth = ((windowSize.width.toDp() - (tabs.size - 1) * 9.dp) / tabs.size).coerceAtLeast(62.dp)
6363
}
6464

6565
val shape = remember { derivedStateOf { SmoothRoundedCornerShape(cornerRadius) } }
@@ -78,11 +78,11 @@ fun TabRow(
7878
onSelect?.invoke(index)
7979
},
8080
enabled = onSelect != null,
81-
color =
82-
if (selectedTabIndex == index) selectedBackgroundColor
83-
else backgroundColor,
84-
modifier = Modifier.fillMaxHeight()
85-
.width(tabWidth).semantics { role = Role.Tab }
81+
color = if (selectedTabIndex == index) selectedBackgroundColor else backgroundColor,
82+
modifier = Modifier
83+
.fillMaxHeight()
84+
.width(tabWidth)
85+
.semantics { role = Role.Tab }
8686
) {
8787
Box(
8888
modifier = Modifier.fillMaxSize(),
@@ -91,11 +91,11 @@ fun TabRow(
9191
Text(
9292
text = tabText,
9393
color = if (selectedTabIndex == index) selectedColor else contentColor,
94+
fontWeight = if (selectedTabIndex == index) FontWeight.Bold else FontWeight.Normal,
9495
maxLines = 1
9596
)
9697
}
9798
}
9899
}
99100
}
100-
101101
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ fun SuperDropdown(
150150
optionSize = items.size,
151151
isSelected = selectedIndex == index,
152152
onSelectedIndexChange = {
153-
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
153+
hapticFeedback.performHapticFeedback(HapticFeedbackType.Confirm)
154154
onSelectedIndexChange?.let { it1 -> it1(it) }
155155
dismissPopup(showPopup)
156156
isDropdownExpanded.value = false
@@ -189,7 +189,7 @@ fun SuperDropdown(
189189
if (enabled) {
190190
onClick?.invoke()
191191
isDropdownExpanded.value = enabled
192-
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
192+
hapticFeedback.performHapticFeedback(HapticFeedbackType.ContextClick)
193193
coroutineScope.launch {
194194
interactionSource.emit(HoldDownInteraction.Hold().also {
195195
held.value = it

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ fun SuperSpinner(
335335
if (enabled) {
336336
onClick?.invoke()
337337
isDropdownExpanded.value = true
338-
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
338+
hapticFeedback.performHapticFeedback(HapticFeedbackType.ContextClick)
339339
coroutineScope.launch {
340340
interactionSource.emit(HoldDownInteraction.Hold().also {
341341
held.value = it
@@ -367,7 +367,7 @@ fun SuperSpinner(
367367
index = index,
368368
dialogMode = true
369369
) {
370-
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
370+
hapticFeedback.performHapticFeedback(HapticFeedbackType.Confirm)
371371
onSelectedIndexChange?.let { it1 -> it1(it) }
372372
dismissDialog(isDropdownExpanded)
373373
}

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import androidx.compose.runtime.remember
99
import androidx.compose.runtime.rememberUpdatedState
1010
import androidx.compose.runtime.setValue
1111
import androidx.compose.ui.Modifier
12-
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
13-
import androidx.compose.ui.platform.LocalHapticFeedback
1412
import top.yukonga.miuix.kmp.basic.BasicComponent
1513
import top.yukonga.miuix.kmp.basic.BasicComponentColors
1614
import top.yukonga.miuix.kmp.basic.BasicComponentDefaults
@@ -53,7 +51,6 @@ fun SuperSwitch(
5351
) {
5452
var isChecked by remember { mutableStateOf(checked) }
5553
val updatedOnCheckedChange by rememberUpdatedState(onCheckedChange)
56-
val localHapticFeedback = LocalHapticFeedback.current
5754

5855
if (isChecked != checked) isChecked = checked
5956

@@ -79,7 +76,6 @@ fun SuperSwitch(
7976
onClick?.invoke()
8077
isChecked = !isChecked
8178
updatedOnCheckedChange?.invoke(isChecked)
82-
localHapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
8379
}
8480
},
8581
enabled = enabled

0 commit comments

Comments
 (0)