Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.absoluteOffset
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
Expand All @@ -59,13 +59,15 @@
import androidx.compose.ui.layout.layout
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import androidx.compose.ui.zIndex
import androidx.core.view.HapticFeedbackConstantsCompat
Expand Down Expand Up @@ -815,7 +817,7 @@
*/
@Suppress("LongMethod")
@Composable
private fun SwipeToReply(

Check failure on line 820 in stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/messages/list/MessageContainer.kt

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 33 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=GetStream_stream-chat-android&issues=AZ0-24QwQ5zajns2HQd2&open=AZ0-24QwQ5zajns2HQd2&pullRequest=6312
modifier: Modifier = Modifier,
onReply: () -> Unit = {},
isSwipeable: Boolean = true,
Expand All @@ -826,6 +828,7 @@
val offset = remember { Animatable(initialValue = 0f) }
val scope = rememberCoroutineScope()
val view = LocalView.current
val isRtl = LocalLayoutDirection.current == LayoutDirection.Rtl

Box(
modifier = modifier
Expand All @@ -836,11 +839,14 @@
modifier = Modifier
.align(Alignment.CenterStart)
.onSizeChanged { swipeToReplyWidth = it.width.toFloat() }
.offset {
.absoluteOffset {
val roundToInt = swipeToReplyWidth.roundToInt()
IntOffset(
x = (offset.value.roundToInt() - roundToInt)
.coerceIn(-roundToInt, roundToInt),
x = if (isRtl) {
(roundToInt + offset.value.roundToInt()).coerceIn(-roundToInt, roundToInt)
} else {
(offset.value.roundToInt() - roundToInt).coerceIn(-roundToInt, roundToInt)
},
y = 0,
)
},
Expand All @@ -855,16 +861,19 @@
modifier = Modifier
.fillMaxWidth()
.onSizeChanged { rowWidth = it.width.toFloat() }
.offset { IntOffset(x = offset.value.roundToInt(), y = 0) }
.pointerInput(swipeToReplyWidth, isSwipeable) {
.absoluteOffset { IntOffset(x = offset.value.roundToInt(), y = 0) }
.pointerInput(swipeToReplyWidth, isSwipeable, isRtl) {
if (isSwipeable) {
detectHorizontalDragGestures(
onHorizontalDrag = { change, dragAmount ->
// Only consume if horizontal drag dominates vertical
if (change.positionChange().x.absoluteValue > change.positionChange().y.absoluteValue) {
scope.launch {
val newOffset = (offset.value + dragAmount)
.coerceIn(0f, maxOf((rowWidth / 2), swipeToReplyWidth))
val maxSwipe = maxOf((rowWidth / 2), swipeToReplyWidth)
val newOffset = (offset.value + dragAmount).coerceIn(
minimumValue = if (isRtl) -maxSwipe else 0f,
maximumValue = if (isRtl) 0f else maxSwipe,
)
offset.snapTo(newOffset)
}
} else {
Expand All @@ -873,7 +882,7 @@
},
onDragEnd = {
scope.launch {
if (offset.value >= swipeToReplyWidth) {
if (offset.value.absoluteValue >= swipeToReplyWidth) {
view.performHapticFeedback(HapticFeedbackConstantsCompat.CONFIRM)
onReply()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
android:width="20dp"
android:height="20dp"
android:viewportWidth="20"
android:viewportHeight="20">
android:viewportHeight="20"
android:autoMirrored="true">
<path
android:pathData="M1.538,9.542L8.326,3.263C8.726,2.893 9.375,3.177 9.375,3.722V6.667C9.375,6.898 9.565,7.084 9.795,7.087C16.533,7.195 18.333,9.935 18.333,16.876C17.109,14.426 16.484,12.977 9.796,12.919C9.566,12.917 9.375,13.104 9.375,13.334V16.28C9.375,16.825 8.726,17.109 8.326,16.738L1.538,10.46C1.27,10.212 1.27,9.789 1.538,9.542Z"
android:strokeLineJoin="round"
Expand Down
Loading