diff --git a/richeditor-compose/api/android/richeditor-compose.api b/richeditor-compose/api/android/richeditor-compose.api index 145bae9d..c0802abd 100644 --- a/richeditor-compose/api/android/richeditor-compose.api +++ b/richeditor-compose/api/android/richeditor-compose.api @@ -239,7 +239,6 @@ public final class com/mohamedrejeb/richeditor/ui/ComposableSingletons$BasicRich public final class com/mohamedrejeb/richeditor/ui/InteractionType : java/lang/Enum { public static final field DoubleTap Lcom/mohamedrejeb/richeditor/ui/InteractionType; public static final field PrimaryClick Lcom/mohamedrejeb/richeditor/ui/InteractionType; - public static final field PrimaryDoubleClick Lcom/mohamedrejeb/richeditor/ui/InteractionType; public static final field SecondaryClick Lcom/mohamedrejeb/richeditor/ui/InteractionType; public static final field Tap Lcom/mohamedrejeb/richeditor/ui/InteractionType; public static fun getEntries ()Lkotlin/enums/EnumEntries; diff --git a/richeditor-compose/api/desktop/richeditor-compose.api b/richeditor-compose/api/desktop/richeditor-compose.api index c2f00bff..f8ffaeb8 100644 --- a/richeditor-compose/api/desktop/richeditor-compose.api +++ b/richeditor-compose/api/desktop/richeditor-compose.api @@ -239,7 +239,6 @@ public final class com/mohamedrejeb/richeditor/ui/ComposableSingletons$BasicRich public final class com/mohamedrejeb/richeditor/ui/InteractionType : java/lang/Enum { public static final field DoubleTap Lcom/mohamedrejeb/richeditor/ui/InteractionType; public static final field PrimaryClick Lcom/mohamedrejeb/richeditor/ui/InteractionType; - public static final field PrimaryDoubleClick Lcom/mohamedrejeb/richeditor/ui/InteractionType; public static final field SecondaryClick Lcom/mohamedrejeb/richeditor/ui/InteractionType; public static final field Tap Lcom/mohamedrejeb/richeditor/ui/InteractionType; public static fun getEntries ()Lkotlin/enums/EnumEntries; diff --git a/richeditor-compose/api/richeditor-compose.klib.api b/richeditor-compose/api/richeditor-compose.klib.api index c473794e..b9bd15cf 100644 --- a/richeditor-compose/api/richeditor-compose.klib.api +++ b/richeditor-compose/api/richeditor-compose.klib.api @@ -17,7 +17,6 @@ open annotation class com.mohamedrejeb.richeditor.annotation/InternalRichTextApi final enum class com.mohamedrejeb.richeditor.ui/InteractionType : kotlin/Enum { // com.mohamedrejeb.richeditor.ui/InteractionType|null[0] enum entry DoubleTap // com.mohamedrejeb.richeditor.ui/InteractionType.DoubleTap|null[0] enum entry PrimaryClick // com.mohamedrejeb.richeditor.ui/InteractionType.PrimaryClick|null[0] - enum entry PrimaryDoubleClick // com.mohamedrejeb.richeditor.ui/InteractionType.PrimaryDoubleClick|null[0] enum entry SecondaryClick // com.mohamedrejeb.richeditor.ui/InteractionType.SecondaryClick|null[0] enum entry Tap // com.mohamedrejeb.richeditor.ui/InteractionType.Tap|null[0] diff --git a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/BasicRichTextEditor.kt b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/BasicRichTextEditor.kt index 3da120ea..2e71a487 100644 --- a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/BasicRichTextEditor.kt +++ b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/BasicRichTextEditor.kt @@ -1,6 +1,5 @@ package com.mohamedrejeb.richeditor.ui -import androidx.compose.foundation.gestures.detectTapGestures import androidx.compose.foundation.interaction.Interaction import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.interaction.PressInteraction @@ -20,7 +19,7 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.SolidColor import androidx.compose.ui.input.pointer.PointerEventPass import androidx.compose.ui.input.pointer.PointerEventType -import androidx.compose.ui.input.pointer.isPressed +import androidx.compose.ui.input.pointer.PointerType import androidx.compose.ui.input.pointer.isPrimaryPressed import androidx.compose.ui.input.pointer.isSecondaryPressed import androidx.compose.ui.input.pointer.pointerInput @@ -35,9 +34,6 @@ import androidx.compose.ui.unit.LayoutDirection import com.mohamedrejeb.richeditor.model.RichSpanStyle import com.mohamedrejeb.richeditor.model.RichTextState import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.launch -import kotlinx.datetime.Clock -import kotlin.time.Duration.Companion.milliseconds /** @@ -359,43 +355,48 @@ private fun Modifier.handleInteractions( ): Modifier = composed { this .pointerInput(enabled) { - awaitPointerEventScope { - while (true) { - val event = awaitPointerEvent(PointerEventPass.Main) - if (!enabled) continue + awaitPointerEventScope { + while (true) { + val event = awaitPointerEvent(PointerEventPass.Main) + if (!enabled) continue - if (event.type == PointerEventType.Press) { - val position = event.changes.first().position + if (event.type == PointerEventType.Press) { + val position = event.changes.first().position - if (event.buttons.isPrimaryPressed) { - val consumed = onInteraction?.invoke(InteractionType.PrimaryClick, position) ?: false - if (consumed) { - event.changes.forEach { it.consume() } - } - } - else if (event.buttons.isSecondaryPressed) { - val consumed = onInteraction?.invoke(InteractionType.SecondaryClick, position) ?: false - if (consumed) { - event.changes.forEach { it.consume() } + when (event.changes.first().type) { + PointerType.Touch -> { + onInteraction?.invoke( + InteractionType.Tap, + event.changes.first().position + ) + } + + PointerType.Mouse -> { + if (event.buttons.isPrimaryPressed) { + val consumed = + onInteraction?.invoke( + InteractionType.PrimaryClick, + position + ) + ?: false + if (consumed) { + event.changes.forEach { it.consume() } + } + } else if (event.buttons.isSecondaryPressed) { + val consumed = + onInteraction?.invoke( + InteractionType.SecondaryClick, + position + ) + ?: false + if (consumed) { + event.changes.forEach { it.consume() } + } + } + } } } } } } - } - // Handle touch interactions - .pointerInput(enabled) { - detectTapGestures( - onTap = { offset -> - if (enabled) { - onInteraction?.invoke(InteractionType.Tap, offset) - } - }, - onDoubleTap = { offset -> - if (enabled) { - onInteraction?.invoke(InteractionType.DoubleTap, offset) - } - } - ) - } -} +} \ No newline at end of file