Skip to content

Commit

Permalink
fix: disable swiping in some extra cases [WPB-9044] 🍒 (#2984)
Browse files Browse the repository at this point in the history
Co-authored-by: Vitor Hugo Schwaab <[email protected]>
  • Loading branch information
github-actions[bot] and vitorhugods authored May 7, 2024
1 parent 377f600 commit 69e378d
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1074,6 +1075,11 @@ fun MessageList(
}
}
}
val swipableConfiguration = remember(message) {
SwipableMessageConfiguration.SwipableToReply {
onSwipedToReply(it)
}
}

MessageContainerItem(
message = message,
Expand All @@ -1085,7 +1091,7 @@ fun MessageList(
onAudioClick = onAudioItemClicked,
onChangeAudioPosition = onChangeAudioPosition,
onLongClicked = onShowEditingOption,
onSwipedToReply = onSwipedToReply,
swipableMessageConfiguration = swipableConfiguration,
onAssetMessageClicked = onAssetItemClicked,
onImageMessageClicked = onImageFullScreenMode,
onOpenProfile = onOpenProfile,
Expand Down Expand Up @@ -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(
Expand All @@ -1135,6 +1142,7 @@ private fun MessageGroupDateTime(
DateUtils.DAY_IN_MILLIS,
0
).toString()

MessageDateTimeGroup.Daily.Type.Yesterday ->
DateUtils.getRelativeDateTimeString(
context,
Expand All @@ -1143,23 +1151,27 @@ 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,
DateUtils.FORMAT_SHOW_DATE or DateUtils.FORMAT_SHOW_YEAR or DateUtils.FORMAT_SHOW_TIME
)
}
}

null -> ""
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -135,7 +136,7 @@ private fun AssetMessagesListContent(
shouldDisplayMessageStatus = false,
shouldDisplayFooter = false,
onReplyClickable = null,
onSwipedToReply = { }
swipableMessageConfiguration = SwipableMessageConfiguration.NotSwipable
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fun MessageContainerItem(
audioMessagesState: PersistentMap<String, AudioState>,
assetStatus: AssetTransferStatus? = null,
onLongClicked: (UIMessage.Regular) -> Unit,
onSwipedToReply: (UIMessage.Regular) -> Unit,
swipableMessageConfiguration: SwipableMessageConfiguration,
onAssetMessageClicked: (String) -> Unit,
onAudioClick: (String) -> Unit,
onChangeAudioPosition: (String, Int) -> Unit,
Expand Down Expand Up @@ -140,7 +140,7 @@ fun MessageContainerItem(
onAudioClick = onAudioClick,
onChangeAudioPosition = onChangeAudioPosition,
onLongClicked = onLongClicked,
onSwipedToReply = onSwipedToReply,
swipableMessageConfiguration = swipableMessageConfiguration,
onAssetMessageClicked = onAssetMessageClicked,
onImageMessageClicked = onImageMessageClicked,
onOpenProfile = onOpenProfile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -114,7 +115,7 @@ fun RegularMessageItem(
audioMessagesState: PersistentMap<String, AudioState>,
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,
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -71,7 +72,7 @@ fun SearchConversationMessagesResultsScreen(
shouldDisplayMessageStatus = false,
shouldDisplayFooter = false,
onReplyClickable = null,
onSwipedToReply = {}
swipableMessageConfiguration = SwipableMessageConfiguration.NotSwipable
)
}

Expand Down

0 comments on commit 69e378d

Please sign in to comment.