Skip to content

Commit

Permalink
[AND-295] Allow customisation of vertical arrangement in MessageList (#…
Browse files Browse the repository at this point in the history
…5618)

* [AND-295] Introduce MessagesVerticalArrangement.

* [AND-295] Add customizable MessageList vertical arrangement.

* [AND-295] Add customizable MessageList vertical arrangement.

* [AND-295] Update CHANGELOG.md.

---------

Co-authored-by: PetarVelikov <petar.velikov@getstream.io>
  • Loading branch information
VelikovPetar and PetarVelikov authored Feb 6, 2025
1 parent cc2a80f commit 9195931
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
- Introduce display configurations for user presence. [#5601](https://github.com/GetStream/stream-chat-android/pull/5601)

### ✅ Added
- Add customizable `verticalArrangement` to `MessagesScreen`, `MessageList` and `Messages`. [#5618](https://github.com/GetStream/stream-chat-android/pull/5618)

### ⚠️ Changed
- 🚨 Breaking change: Change `@Composable public fun MessageContainer` function to `@Composable public fun LazyItemScope.MessageContainer`. [#5593](https://github.com/GetStream/stream-chat-android/pull/5593)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ public final class io/getstream/chat/android/ai/assistant/AiMessageTextKt {
}

public final class io/getstream/chat/android/ai/assistant/AiMessagesScreenKt {
public static final fun AiMessagesScreen (Lio/getstream/chat/android/compose/viewmodel/messages/MessagesViewModelFactory;ZLkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function0;ZLio/getstream/chat/android/ai/assistant/TypingState;Lio/getstream/chat/android/models/ReactionSorting;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;ZZLio/getstream/chat/android/compose/ui/messages/list/ThreadMessagesStart;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Landroidx/compose/runtime/Composer;III)V
public static final fun AiMessagesScreen (Lio/getstream/chat/android/compose/viewmodel/messages/MessagesViewModelFactory;ZLkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function0;ZLio/getstream/chat/android/ai/assistant/TypingState;Lio/getstream/chat/android/models/ReactionSorting;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;ZZLandroidx/compose/foundation/layout/Arrangement$Vertical;Lio/getstream/chat/android/compose/ui/messages/list/ThreadMessagesStart;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Landroidx/compose/runtime/Composer;III)V
}

public final class io/getstream/chat/android/ai/assistant/AiRegularMessageContentKt {
Expand Down
1 change: 1 addition & 0 deletions stream-chat-android-ai-assistant/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ rootProject.extra.apply {

apply(from = "$rootDir/scripts/publish-module.gradle")
apply(from = "$rootDir/scripts/android.gradle")
apply(from = "$rootDir/scripts/detekt-compose.gradle")

android {
namespace = "io.getstream.chat.android.ai.assistant"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package io.getstream.chat.android.ai.assistant
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.scrollBy
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -98,11 +99,14 @@ import io.getstream.chat.android.ui.common.state.messages.Reply
* @param skipPushNotification If new messages should skip triggering a push notification when sent. False by default.
* @param skipEnrichUrl If new messages being sent, or existing ones being updated should skip enriching the URL.
* If URL is not enriched, it will not be displayed as a link attachment. False by default.
* @param verticalArrangement Vertical arrangement of the regular message list.
* Default: [Arrangement.Top].
* @param threadMessagesStart Thread messages start at the bottom or top of the screen.
* Default: [ThreadMessagesStart.BOTTOM].
* @param topBarContent custom top bar content to be displayed on top of the messages list.
* @param bottomBarContent custom bottom bar content to be displayed at the bottom of the messages list.
* Default: [ThreadMessagesStart.BOTTOM].
*/
@Suppress("LongMethod")
@Composable
public fun AiMessagesScreen(
viewModelFactory: MessagesViewModelFactory,
Expand All @@ -120,6 +124,7 @@ public fun AiMessagesScreen(
onUserAvatarClick: (User) -> Unit = {},
skipPushNotification: Boolean = false,
skipEnrichUrl: Boolean = false,
verticalArrangement: Arrangement.Vertical = Arrangement.Top,
threadMessagesStart: ThreadMessagesStart = ThreadMessagesStart.BOTTOM,
aiStartButton: @Composable BoxScope.() -> Unit = {
DefaultAiStartButton(
Expand Down Expand Up @@ -234,6 +239,7 @@ public fun AiMessagesScreen(
viewModel = listViewModel,
reactionSorting = reactionSorting,
messagesLazyListState = state,
verticalArrangement = verticalArrangement,
threadMessagesStart = threadMessagesStart,
onThreadClick = remember(composerViewModel, listViewModel) {
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1535,7 +1535,7 @@ public final class io/getstream/chat/android/compose/ui/messages/MessagesScreenK
public static final fun MessageDialogs (Lio/getstream/chat/android/compose/viewmodel/messages/MessageListViewModel;Landroidx/compose/runtime/Composer;I)V
public static final fun MessageMenus (Landroidx/compose/foundation/layout/BoxScope;Lio/getstream/chat/android/compose/viewmodel/messages/MessageListViewModel;Lio/getstream/chat/android/compose/viewmodel/messages/MessageComposerViewModel;ZZLandroidx/compose/runtime/Composer;I)V
public static final fun MessageModerationDialog (Lio/getstream/chat/android/compose/viewmodel/messages/MessageListViewModel;Lio/getstream/chat/android/compose/viewmodel/messages/MessageComposerViewModel;ZZLandroidx/compose/runtime/Composer;I)V
public static final fun MessagesScreen (Lio/getstream/chat/android/compose/viewmodel/messages/MessagesViewModelFactory;ZLio/getstream/chat/android/compose/ui/components/messages/factory/MessageContentFactory;Lio/getstream/chat/android/models/ReactionSorting;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ZZZLio/getstream/chat/android/compose/ui/messages/list/ThreadMessagesStart;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;III)V
public static final fun MessagesScreen (Lio/getstream/chat/android/compose/viewmodel/messages/MessagesViewModelFactory;ZLio/getstream/chat/android/compose/ui/components/messages/factory/MessageContentFactory;Lio/getstream/chat/android/models/ReactionSorting;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ZZZLandroidx/compose/foundation/layout/Arrangement$Vertical;Lio/getstream/chat/android/compose/ui/messages/list/ThreadMessagesStart;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;III)V
public static final fun PollDialogs (Lio/getstream/chat/android/compose/viewmodel/messages/MessageListViewModel;ZLandroidx/compose/runtime/Composer;I)V
}

Expand Down Expand Up @@ -1955,12 +1955,12 @@ public final class io/getstream/chat/android/compose/ui/messages/list/MessageIte
}

public final class io/getstream/chat/android/compose/ui/messages/list/MessageListKt {
public static final fun MessageList (Lio/getstream/chat/android/compose/viewmodel/messages/MessageListViewModel;Lio/getstream/chat/android/models/ReactionSorting;Landroidx/compose/ui/Modifier;Landroidx/compose/foundation/layout/PaddingValues;Lio/getstream/chat/android/compose/ui/components/messages/factory/MessageContentFactory;Lio/getstream/chat/android/compose/ui/messages/list/MessagesLazyListState;Lio/getstream/chat/android/compose/ui/messages/list/ThreadMessagesStart;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function4;Landroidx/compose/runtime/Composer;IIIIII)V
public static final fun MessageList (Lio/getstream/chat/android/ui/common/state/messages/list/MessageListState;Lio/getstream/chat/android/compose/ui/messages/list/ThreadMessagesStart;Lio/getstream/chat/android/models/ReactionSorting;Landroidx/compose/ui/Modifier;Landroidx/compose/foundation/layout/PaddingValues;Lio/getstream/chat/android/compose/ui/components/messages/factory/MessageContentFactory;Lio/getstream/chat/android/compose/ui/messages/list/MessagesLazyListState;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function4;Landroidx/compose/runtime/Composer;IIIIII)V
public static final fun MessageList (Lio/getstream/chat/android/compose/viewmodel/messages/MessageListViewModel;Lio/getstream/chat/android/models/ReactionSorting;Landroidx/compose/ui/Modifier;Landroidx/compose/foundation/layout/PaddingValues;Lio/getstream/chat/android/compose/ui/components/messages/factory/MessageContentFactory;Lio/getstream/chat/android/compose/ui/messages/list/MessagesLazyListState;Landroidx/compose/foundation/layout/Arrangement$Vertical;Lio/getstream/chat/android/compose/ui/messages/list/ThreadMessagesStart;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function4;Landroidx/compose/runtime/Composer;IIIIII)V
public static final fun MessageList (Lio/getstream/chat/android/ui/common/state/messages/list/MessageListState;Landroidx/compose/foundation/layout/Arrangement$Vertical;Lio/getstream/chat/android/compose/ui/messages/list/ThreadMessagesStart;Lio/getstream/chat/android/models/ReactionSorting;Landroidx/compose/ui/Modifier;Landroidx/compose/foundation/layout/PaddingValues;Lio/getstream/chat/android/compose/ui/components/messages/factory/MessageContentFactory;Lio/getstream/chat/android/compose/ui/messages/list/MessagesLazyListState;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function4;Landroidx/compose/runtime/Composer;IIIIII)V
}

public final class io/getstream/chat/android/compose/ui/messages/list/MessagesKt {
public static final fun Messages (Lio/getstream/chat/android/ui/common/state/messages/list/MessageListState;Lio/getstream/chat/android/compose/ui/messages/list/MessagesLazyListState;Lio/getstream/chat/android/compose/ui/messages/list/ThreadMessagesStart;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Landroidx/compose/ui/Modifier;Landroidx/compose/foundation/layout/PaddingValues;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function4;Landroidx/compose/runtime/Composer;III)V
public static final fun Messages (Lio/getstream/chat/android/ui/common/state/messages/list/MessageListState;Lio/getstream/chat/android/compose/ui/messages/list/MessagesLazyListState;Landroidx/compose/foundation/layout/Arrangement$Vertical;Lio/getstream/chat/android/compose/ui/messages/list/ThreadMessagesStart;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Landroidx/compose/ui/Modifier;Landroidx/compose/foundation/layout/PaddingValues;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function4;Landroidx/compose/runtime/Composer;III)V
}

public final class io/getstream/chat/android/compose/ui/messages/list/MessagesLazyListState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.compose.animation.fadeOut
import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutVertically
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.WindowInsets
Expand Down Expand Up @@ -125,10 +126,12 @@ import io.getstream.chat.android.ui.common.state.messages.updateMessage
* @param skipEnrichUrl If new messages being sent, or existing ones being updated should skip enriching the URL.
* If URL is not enriched, it will not be displayed as a link attachment. False by default.
* @param showAnonymousAvatar If the user avatar should be shown on comments for polls with anonymous voting visibility.
* @param verticalArrangement Vertical arrangement of the regular message list.
* Default: [Arrangement.Top].
* @param threadMessagesStart Thread messages start at the bottom or top of the screen.
* Default: [ThreadMessagesStart.BOTTOM].
* @param topBarContent custom top bar content to be displayed on top of the messages list.
* @param bottomBarContent custom bottom bar content to be displayed at the bottom of the messages list.
* Default: [ThreadMessagesStart.BOTTOM].
*/
@Suppress("LongMethod")
@Composable
Expand All @@ -147,6 +150,7 @@ public fun MessagesScreen(
skipPushNotification: Boolean = false,
skipEnrichUrl: Boolean = false,
showAnonymousAvatar: Boolean = false,
verticalArrangement: Arrangement.Vertical = Arrangement.Top,
threadMessagesStart: ThreadMessagesStart = ThreadMessagesStart.BOTTOM,
topBarContent: @Composable (BackAction) -> Unit = {
DefaultTopBarContent(
Expand Down Expand Up @@ -234,6 +238,7 @@ public fun MessagesScreen(
messageContentFactory = messageContentFactory,
reactionSorting = reactionSorting,
messagesLazyListState = rememberMessageListState(parentMessageId = currentState.parentMessageId),
verticalArrangement = verticalArrangement,
threadMessagesStart = threadMessagesStart,
onThreadClick = remember(composerViewModel, listViewModel) {
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.getstream.chat.android.compose.ui.messages.list

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.PaddingValues
Expand Down Expand Up @@ -62,6 +63,8 @@ import io.getstream.chat.android.ui.common.state.messages.poll.SelectedPoll
* @param contentPadding Padding values to be applied to the message list surrounding the content inside.
* @param messagesLazyListState State of the lazy list that represents the list of messages. Useful for controlling the
* scroll state and focused message offset.
* @param verticalArrangement Vertical arrangement of the regular message list.
* Default: [Arrangement.Top].
* @param threadMessagesStart Thread messages start at the bottom or top of the screen.
* Default: [ThreadMessagesStart.BOTTOM].
* @param onThreadClick Handler when the user taps on the message, while there's a thread going.
Expand Down Expand Up @@ -96,6 +99,7 @@ public fun MessageList(
messageContentFactory: MessageContentFactory = ChatTheme.messageContentFactory,
messagesLazyListState: MessagesLazyListState =
rememberMessageListState(parentMessageId = viewModel.currentMessagesState.parentMessageId),
verticalArrangement: Arrangement.Vertical = Arrangement.Top,
threadMessagesStart: ThreadMessagesStart = ThreadMessagesStart.BOTTOM,
onThreadClick: (Message) -> Unit = { viewModel.openMessageThread(it) },
onLongItemClick: (Message) -> Unit = { viewModel.selectMessage(it) },
Expand Down Expand Up @@ -210,6 +214,7 @@ public fun MessageList(
currentState = viewModel.currentMessagesState,
messagesLazyListState = messagesLazyListState,
onMessagesPageStartReached = onMessagesPageStartReached,
verticalArrangement = verticalArrangement,
threadMessagesStart = threadMessagesStart,
onLastVisibleMessageChanged = onLastVisibleMessageChanged,
onLongItemClick = onLongItemClick,
Expand Down Expand Up @@ -330,6 +335,8 @@ internal fun DefaultMessageListEmptyContent(modifier: Modifier) {
* users to connect the UI to their own data providers, as it relies on pure state.
*
* @param currentState The state of the component, represented by [MessageListState].
* @param verticalArrangement Vertical arrangement of the regular message list.
* Default: [Arrangement.Top].
* @param threadMessagesStart Thread messages start at the bottom or top of the screen.
* Default: [ThreadMessagesStart.BOTTOM].
* @param reactionSorting The sorting of the reactions.
Expand Down Expand Up @@ -362,6 +369,7 @@ internal fun DefaultMessageListEmptyContent(modifier: Modifier) {
@Composable
public fun MessageList(
currentState: MessageListState,
verticalArrangement: Arrangement.Vertical = Arrangement.Top,
threadMessagesStart: ThreadMessagesStart = ThreadMessagesStart.BOTTOM,
reactionSorting: ReactionSorting,
modifier: Modifier = Modifier,
Expand Down Expand Up @@ -473,6 +481,7 @@ public fun MessageList(
messagesState = currentState,
messagesLazyListState = messagesLazyListState,
onMessagesStartReached = onMessagesPageStartReached,
verticalArrangement = verticalArrangement,
threadMessagesStart = threadMessagesStart,
onLastVisibleMessageChanged = onLastVisibleMessageChanged,
onScrolledToBottom = onScrolledToBottom,
Expand Down
Loading

0 comments on commit 9195931

Please sign in to comment.