From 69e378d6635da2aca02891cbfaf847b97396c0c7 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 7 May 2024 18:10:13 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20disable=20swiping=20in=20some=20extra=20?= =?UTF-8?q?cases=20[WPB-9044]=20=F0=9F=8D=92=20(#2984)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Vitor Hugo Schwaab --- .../home/conversations/ConversationScreen.kt | 16 ++++++++-- .../conversations/media/FileAssetsContent.kt | 3 +- .../messages/item/MessageContainerItem.kt | 4 +-- .../messages/item/RegularMessageItem.kt | 31 +++++++++++++------ .../ui/home/conversations/model/UIMessage.kt | 1 + ...SearchConversationMessagesResultsScreen.kt | 3 +- 6 files changed, 42 insertions(+), 16 deletions(-) diff --git a/app/src/main/kotlin/com/wire/android/ui/home/conversations/ConversationScreen.kt b/app/src/main/kotlin/com/wire/android/ui/home/conversations/ConversationScreen.kt index 3bf56a5319a..92924b93233 100644 --- a/app/src/main/kotlin/com/wire/android/ui/home/conversations/ConversationScreen.kt +++ b/app/src/main/kotlin/com/wire/android/ui/home/conversations/ConversationScreen.kt @@ -86,8 +86,8 @@ import com.wire.android.navigation.BackStackMode import com.wire.android.navigation.NavigationCommand import com.wire.android.navigation.Navigator import com.wire.android.ui.LocalActivity -import com.wire.android.ui.calling.getOutgoingCallIntent import com.wire.android.ui.calling.getOngoingCallIntent +import com.wire.android.ui.calling.getOutgoingCallIntent import com.wire.android.ui.common.bottomsheet.MenuModalSheetHeader import com.wire.android.ui.common.bottomsheet.MenuModalSheetLayout import com.wire.android.ui.common.colorsScheme @@ -131,6 +131,7 @@ import com.wire.android.ui.home.conversations.messages.ConversationMessagesViewM import com.wire.android.ui.home.conversations.messages.ConversationMessagesViewState import com.wire.android.ui.home.conversations.messages.draft.MessageDraftViewModel import com.wire.android.ui.home.conversations.messages.item.MessageContainerItem +import com.wire.android.ui.home.conversations.messages.item.SwipableMessageConfiguration import com.wire.android.ui.home.conversations.migration.ConversationMigrationViewModel import com.wire.android.ui.home.conversations.model.ExpirationStatus import com.wire.android.ui.home.conversations.model.UIMessage @@ -1074,6 +1075,11 @@ fun MessageList( } } } + val swipableConfiguration = remember(message) { + SwipableMessageConfiguration.SwipableToReply { + onSwipedToReply(it) + } + } MessageContainerItem( message = message, @@ -1085,7 +1091,7 @@ fun MessageList( onAudioClick = onAudioItemClicked, onChangeAudioPosition = onChangeAudioPosition, onLongClicked = onShowEditingOption, - onSwipedToReply = onSwipedToReply, + swipableMessageConfiguration = swipableConfiguration, onAssetMessageClicked = onAssetItemClicked, onImageMessageClicked = onImageFullScreenMode, onOpenProfile = onOpenProfile, @@ -1126,6 +1132,7 @@ private fun MessageGroupDateTime( now, DateUtils.MINUTE_IN_MILLIS ).toString() + is MessageDateTimeGroup.Daily -> { when (messageDateTimeGroup.type) { MessageDateTimeGroup.Daily.Type.Today -> DateUtils.getRelativeDateTimeString( @@ -1135,6 +1142,7 @@ private fun MessageGroupDateTime( DateUtils.DAY_IN_MILLIS, 0 ).toString() + MessageDateTimeGroup.Daily.Type.Yesterday -> DateUtils.getRelativeDateTimeString( context, @@ -1143,16 +1151,19 @@ private fun MessageGroupDateTime( DateUtils.DAY_IN_MILLIS * 2, 0 ).toString() + MessageDateTimeGroup.Daily.Type.WithinWeek -> DateUtils.formatDateTime( context, messageDateTime.time, DateUtils.FORMAT_SHOW_WEEKDAY or DateUtils.FORMAT_SHOW_DATE or DateUtils.FORMAT_SHOW_TIME ) + MessageDateTimeGroup.Daily.Type.NotWithinWeekButSameYear -> DateUtils.formatDateTime( context, messageDateTime.time, DateUtils.FORMAT_SHOW_DATE or DateUtils.FORMAT_SHOW_TIME ) + MessageDateTimeGroup.Daily.Type.Other -> DateUtils.formatDateTime( context, messageDateTime.time, @@ -1160,6 +1171,7 @@ private fun MessageGroupDateTime( ) } } + null -> "" } diff --git a/app/src/main/kotlin/com/wire/android/ui/home/conversations/media/FileAssetsContent.kt b/app/src/main/kotlin/com/wire/android/ui/home/conversations/media/FileAssetsContent.kt index 17be9d60ed9..a1bcaa24f5c 100644 --- a/app/src/main/kotlin/com/wire/android/ui/home/conversations/media/FileAssetsContent.kt +++ b/app/src/main/kotlin/com/wire/android/ui/home/conversations/media/FileAssetsContent.kt @@ -40,6 +40,7 @@ import com.wire.android.ui.common.dimensions import com.wire.android.ui.common.progress.WireCircularProgressIndicator import com.wire.android.ui.home.conversations.info.ConversationDetailsData import com.wire.android.ui.home.conversations.messages.item.MessageContainerItem +import com.wire.android.ui.home.conversations.messages.item.SwipableMessageConfiguration import com.wire.android.ui.home.conversations.model.UIMessage import com.wire.android.ui.home.conversations.usecase.UIPagingItem import com.wire.android.ui.home.conversationslist.common.FolderHeader @@ -135,7 +136,7 @@ private fun AssetMessagesListContent( shouldDisplayMessageStatus = false, shouldDisplayFooter = false, onReplyClickable = null, - onSwipedToReply = { } + swipableMessageConfiguration = SwipableMessageConfiguration.NotSwipable ) } diff --git a/app/src/main/kotlin/com/wire/android/ui/home/conversations/messages/item/MessageContainerItem.kt b/app/src/main/kotlin/com/wire/android/ui/home/conversations/messages/item/MessageContainerItem.kt index c3c0f4e67d5..7283b881f01 100644 --- a/app/src/main/kotlin/com/wire/android/ui/home/conversations/messages/item/MessageContainerItem.kt +++ b/app/src/main/kotlin/com/wire/android/ui/home/conversations/messages/item/MessageContainerItem.kt @@ -58,7 +58,7 @@ fun MessageContainerItem( audioMessagesState: PersistentMap, assetStatus: AssetTransferStatus? = null, onLongClicked: (UIMessage.Regular) -> Unit, - onSwipedToReply: (UIMessage.Regular) -> Unit, + swipableMessageConfiguration: SwipableMessageConfiguration, onAssetMessageClicked: (String) -> Unit, onAudioClick: (String) -> Unit, onChangeAudioPosition: (String, Int) -> Unit, @@ -140,7 +140,7 @@ fun MessageContainerItem( onAudioClick = onAudioClick, onChangeAudioPosition = onChangeAudioPosition, onLongClicked = onLongClicked, - onSwipedToReply = onSwipedToReply, + swipableMessageConfiguration = swipableMessageConfiguration, onAssetMessageClicked = onAssetMessageClicked, onImageMessageClicked = onImageMessageClicked, onOpenProfile = onOpenProfile, diff --git a/app/src/main/kotlin/com/wire/android/ui/home/conversations/messages/item/RegularMessageItem.kt b/app/src/main/kotlin/com/wire/android/ui/home/conversations/messages/item/RegularMessageItem.kt index af0831e5bd6..c587826c69d 100644 --- a/app/src/main/kotlin/com/wire/android/ui/home/conversations/messages/item/RegularMessageItem.kt +++ b/app/src/main/kotlin/com/wire/android/ui/home/conversations/messages/item/RegularMessageItem.kt @@ -40,6 +40,7 @@ import androidx.compose.material3.SwipeToDismissBoxState import androidx.compose.material3.SwipeToDismissBoxValue import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.Stable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember @@ -114,7 +115,7 @@ fun RegularMessageItem( audioMessagesState: PersistentMap, assetStatus: AssetTransferStatus? = null, onLongClicked: (UIMessage.Regular) -> Unit, - onSwipedToReply: (UIMessage.Regular) -> Unit = {}, + swipableMessageConfiguration: SwipableMessageConfiguration = SwipableMessageConfiguration.NotSwipable, onAssetMessageClicked: (String) -> Unit, onAudioClick: (String) -> Unit, onChangeAudioPosition: (String, Int) -> Unit, @@ -133,11 +134,8 @@ fun RegularMessageItem( useSmallBottomPadding: Boolean = false, selfDeletionTimerState: SelfDeletionTimerHelper.SelfDeletionTimerState = SelfDeletionTimerHelper.SelfDeletionTimerState.NotExpirable ): Unit = with(message) { - val onSwipe = remember(message) { { onSwipedToReply(message) } } - SwipableToReplyBox( - isSwipable = isReplyable, - onSwipedToReply = onSwipe - ) { + @Composable + fun messageContent() { MessageItemTemplate( showAuthor, useSmallBottomPadding = useSmallBottomPadding, @@ -260,12 +258,25 @@ fun RegularMessageItem( } ) } + if (swipableMessageConfiguration is SwipableMessageConfiguration.SwipableToReply && isReplyable) { + val onSwipe = remember(message) { { swipableMessageConfiguration.onSwipedToReply(message) } } + SwipableToReplyBox(onSwipedToReply = onSwipe) { + messageContent() + } + } else { + messageContent() + } +} + +@Stable +sealed interface SwipableMessageConfiguration { + data object NotSwipable : SwipableMessageConfiguration + class SwipableToReply(val onSwipedToReply: (uiMessage: UIMessage.Regular) -> Unit) : SwipableMessageConfiguration } @OptIn(ExperimentalMaterial3Api::class) @Composable private fun SwipableToReplyBox( - isSwipable: Boolean, modifier: Modifier = Modifier, onSwipedToReply: () -> Unit = {}, content: @Composable RowScope.() -> Unit @@ -275,7 +286,7 @@ private fun SwipableToReplyBox( var didVibrateOnCurrentDrag by remember { mutableStateOf(false) } // Finish the animation in the first 25% of the drag - val progressUntilAnimationCompletion = 0.25f + val progressUntilAnimationCompletion = 0.33f val dismissState = remember { SwipeToDismissBoxState( SwipeToDismissBoxValue.Settled, @@ -301,12 +312,12 @@ private fun SwipableToReplyBox( SwipeToDismissBox( state = dismissState, modifier = modifier, - enableDismissFromStartToEnd = isSwipable, content = content, enableDismissFromEndToStart = false, backgroundContent = { Row( - modifier = Modifier.fillMaxSize() + modifier = Modifier + .fillMaxSize() .drawBehind { // TODO(RTL): Might need adjusting once RTL is supported (also lacking in SwipeToDismissBox) drawRect( diff --git a/app/src/main/kotlin/com/wire/android/ui/home/conversations/model/UIMessage.kt b/app/src/main/kotlin/com/wire/android/ui/home/conversations/model/UIMessage.kt index 9c2643824f3..d568387f0f9 100644 --- a/app/src/main/kotlin/com/wire/android/ui/home/conversations/model/UIMessage.kt +++ b/app/src/main/kotlin/com/wire/android/ui/home/conversations/model/UIMessage.kt @@ -99,6 +99,7 @@ sealed interface UIMessage { val isReplyable: Boolean get() = isReplyableContent && isTheMessageAvailableToOtherUsers && + !isDeleted && header.messageStatus.expirationStatus is ExpirationStatus.NotExpirable val isTextContentWithoutQuote = messageContent is UIMessageContent.TextMessage && messageContent.messageBody.quotedMessage == null diff --git a/app/src/main/kotlin/com/wire/android/ui/home/conversations/search/messages/SearchConversationMessagesResultsScreen.kt b/app/src/main/kotlin/com/wire/android/ui/home/conversations/search/messages/SearchConversationMessagesResultsScreen.kt index 4851ef9db54..a6a6f6db68e 100644 --- a/app/src/main/kotlin/com/wire/android/ui/home/conversations/search/messages/SearchConversationMessagesResultsScreen.kt +++ b/app/src/main/kotlin/com/wire/android/ui/home/conversations/search/messages/SearchConversationMessagesResultsScreen.kt @@ -27,6 +27,7 @@ import androidx.paging.compose.itemKey import com.wire.android.ui.common.colorsScheme import com.wire.android.ui.home.conversations.info.ConversationDetailsData import com.wire.android.ui.home.conversations.messages.item.MessageContainerItem +import com.wire.android.ui.home.conversations.messages.item.SwipableMessageConfiguration import com.wire.android.ui.home.conversations.mock.mockMessageWithText import com.wire.android.ui.home.conversations.model.UIMessage import com.wire.android.ui.theme.WireTheme @@ -71,7 +72,7 @@ fun SearchConversationMessagesResultsScreen( shouldDisplayMessageStatus = false, shouldDisplayFooter = false, onReplyClickable = null, - onSwipedToReply = {} + swipableMessageConfiguration = SwipableMessageConfiguration.NotSwipable ) }