From ff3ad7487cda90500779eacec9f1ba9f0fd81377 Mon Sep 17 00:00:00 2001 From: Jesse Horne Date: Tue, 28 Nov 2023 13:57:46 -0500 Subject: [PATCH] reverted swipe modifier to original --- .../common/views/helpers/Modifiers.android.kt | 44 ------------------- .../simplex/common/views/helpers/Modifiers.kt | 19 ++++++-- .../common/views/helpers/Modifiers.desktop.kt | 14 ------ 3 files changed, 16 insertions(+), 61 deletions(-) delete mode 100644 apps/multiplatform/common/src/androidMain/kotlin/chat/simplex/common/views/helpers/Modifiers.android.kt delete mode 100644 apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/views/helpers/Modifiers.desktop.kt diff --git a/apps/multiplatform/common/src/androidMain/kotlin/chat/simplex/common/views/helpers/Modifiers.android.kt b/apps/multiplatform/common/src/androidMain/kotlin/chat/simplex/common/views/helpers/Modifiers.android.kt deleted file mode 100644 index bc7767a9ef..0000000000 --- a/apps/multiplatform/common/src/androidMain/kotlin/chat/simplex/common/views/helpers/Modifiers.android.kt +++ /dev/null @@ -1,44 +0,0 @@ -package chat.simplex.common.views.helpers - -import androidx.compose.foundation.gestures.Orientation -import androidx.compose.foundation.layout.offset -import androidx.compose.material.* -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.layout.layout -import androidx.compose.ui.platform.LocalLayoutDirection -import androidx.compose.ui.unit.IntOffset -import androidx.compose.ui.unit.LayoutDirection -import kotlin.math.roundToInt - -fun Modifier.badgeLayout() = - layout { measurable, constraints -> - val placeable = measurable.measure(constraints) - - // based on the expectation of only one line of text - val minPadding = placeable.height / 4 - - val width = maxOf(placeable.width + minPadding, placeable.height) - layout(width, placeable.height) { - placeable.place((width - placeable.width) / 2, 0) - } - } - -@Composable -actual fun SwipeToDismissModifier( - state: DismissState, - directions: Set, - swipeDistance: Float, -): Modifier { - val isRtl = LocalLayoutDirection.current == LayoutDirection.Rtl - val anchors = mutableMapOf(0f to DismissValue.Default) - if (DismissDirection.StartToEnd in directions) anchors += swipeDistance to DismissValue.DismissedToEnd - if (DismissDirection.EndToStart in directions) anchors += -swipeDistance to DismissValue.DismissedToStart - return Modifier.swipeable( - state = state, - anchors = anchors, - thresholds = { _, _ -> FractionalThreshold(0.5f) }, - orientation = Orientation.Horizontal, - reverseDirection = isRtl, - ).offset { IntOffset(state.offset.value.roundToInt(), 0) } -} diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/helpers/Modifiers.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/helpers/Modifiers.kt index d907c1394f..6aec9a6aa7 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/helpers/Modifiers.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/helpers/Modifiers.kt @@ -25,8 +25,21 @@ fun Modifier.badgeLayout() = } @Composable -expect fun SwipeToDismissModifier( +fun SwipeToDismissModifier( state: DismissState, - directions: Set = setOf(DismissDirection.EndToStart, DismissDirection.StartToEnd), + directions: Set, swipeDistance: Float, -): Modifier +): Modifier { + val isRtl = LocalLayoutDirection.current == LayoutDirection.Rtl + val anchors = mutableMapOf(0f to DismissValue.Default) + if (DismissDirection.StartToEnd in directions) anchors += swipeDistance to DismissValue.DismissedToEnd + if (DismissDirection.EndToStart in directions) anchors += -swipeDistance to DismissValue.DismissedToStart + return Modifier.swipeable( + state = state, + anchors = anchors, + thresholds = { _, _ -> FractionalThreshold(0.5f) }, + orientation = Orientation.Horizontal, + reverseDirection = isRtl, + ).offset { IntOffset(state.offset.value.roundToInt(), 0) } +} + diff --git a/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/views/helpers/Modifiers.desktop.kt b/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/views/helpers/Modifiers.desktop.kt deleted file mode 100644 index 40e28b5be0..0000000000 --- a/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/views/helpers/Modifiers.desktop.kt +++ /dev/null @@ -1,14 +0,0 @@ -package chat.simplex.common.views.helpers - -import androidx.compose.material.* -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier - -@Composable -actual fun SwipeToDismissModifier( - state: DismissState, - directions: Set, - swipeDistance: Float, -): Modifier { - return Modifier -}