@@ -7,8 +7,9 @@ import androidx.compose.animation.core.spring
77import androidx.compose.animation.core.tween
88import androidx.compose.foundation.Indication
99import androidx.compose.foundation.background
10- import androidx.compose.foundation.gestures.detectDragGestures
10+ import androidx.compose.foundation.gestures.detectHorizontalDragGestures
1111import androidx.compose.foundation.gestures.detectTapGestures
12+ import androidx.compose.foundation.gestures.detectVerticalDragGestures
1213import androidx.compose.foundation.interaction.MutableInteractionSource
1314import androidx.compose.foundation.layout.padding
1415import androidx.compose.foundation.layout.requiredSize
@@ -42,7 +43,6 @@ import kotlin.math.absoluteValue
4243 * @param modifier The modifier to be applied to the [Switch].
4344 * @param enabled Whether the [Switch] is enabled.
4445 * @param interactionSource The interaction source to be applied to the [Switch].
45- * @param indication The indication to be applied to the [Switch].
4646 */
4747@Composable
4848fun Switch (
@@ -51,7 +51,6 @@ fun Switch(
5151 modifier : Modifier = Modifier ,
5252 enabled : Boolean = true,
5353 interactionSource : MutableInteractionSource ? = null,
54- indication : Indication ? = null
5554) {
5655 @Suppress(" NAME_SHADOWING" )
5756 val interactionSource = interactionSource ? : remember { MutableInteractionSource () }
@@ -102,7 +101,7 @@ fun Switch(
102101 enabled = enabled,
103102 role = Role .Switch ,
104103 interactionSource = interactionSource,
105- indication = indication
104+ indication = null
106105 )
107106 } else {
108107 Modifier
@@ -118,21 +117,7 @@ fun Switch(
118117 .clip(SquircleShape (100 .dp))
119118 .background(if (enabled) backgroundColor else disabledBackgroundColor)
120119 .pointerInput(Unit ) {
121- detectTapGestures(
122- onPress = {
123- isPressed = true
124- },
125- onTap = {
126- isPressed = false
127- if (enabled) {
128- hapticFeedback.performHapticFeedback(HapticFeedbackType .LongPress )
129- onCheckedChange?.invoke(! isChecked)
130- }
131- }
132- )
133- }
134- .pointerInput(Unit ) {
135- detectDragGestures(
120+ detectHorizontalDragGestures(
136121 onDragStart = {
137122 isPressed = true
138123 hasVibrated = false
@@ -149,14 +134,11 @@ fun Switch(
149134 isPressed = false
150135 dragOffset = 0f
151136 },
152- onDrag = { change, dragAmount ->
153- if (! enabled) return @detectDragGestures
154- val newOffset = dragOffset + dragAmount.x / 2
137+ onHorizontalDrag = { change, dragAmount ->
138+ if (! enabled) return @detectHorizontalDragGestures
139+ val newOffset = dragOffset + dragAmount / 2
155140 dragOffset =
156- if (isChecked) newOffset.coerceIn(- 24f , 0f ) else newOffset.coerceIn(
157- 0f ,
158- 24f
159- )
141+ if (isChecked) newOffset.coerceIn(- 24f , 0f ) else newOffset.coerceIn(0f , 24f )
160142 if (isChecked) {
161143 if (dragOffset in - 23f .. - 1f ) {
162144 hasVibrated = false
0 commit comments