Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AND-302] menu item stateless components #5608

Merged
merged 22 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c87715c
Introduce factory for menu items channel menu, message menu and react…
aleksandar-apostolov Feb 3, 2025
b6b3095
Api Dump and default values changes
aleksandar-apostolov Feb 3, 2025
93f7d38
Spotless
aleksandar-apostolov Feb 3, 2025
b26ba75
Merge branch 'develop' into AND-302-menu-item-statless-components
aleksandar-apostolov Feb 3, 2025
1e29dd5
Merge conflict and api & spotless
aleksandar-apostolov Feb 3, 2025
cea16f9
Fix lint
aleksandar-apostolov Feb 4, 2025
e0539e7
Merge branch 'develop' into AND-302-menu-item-statless-components
aleksandar-apostolov Feb 4, 2025
b9eaf4b
Fix default height of message menu item
aleksandar-apostolov Feb 4, 2025
8bc983c
Merge branch 'develop' into AND-302-menu-item-statless-components
aleksandar-apostolov Feb 4, 2025
0aa3c43
Do not break the old composables by not exposing the parameters
aleksandar-apostolov Feb 4, 2025
1222c85
Merge branch 'develop' into AND-302-menu-item-statless-components
aleksandar-apostolov Feb 4, 2025
db18a56
Spotless & Api Dump
aleksandar-apostolov Feb 4, 2025
f86f40d
Make MessageOptionItemDeprecated
aleksandar-apostolov Feb 4, 2025
d104e89
Fix merge issues
aleksandar-apostolov Feb 4, 2025
4d36311
Merge branch 'develop' into AND-302-menu-item-statless-components
aleksandar-apostolov Feb 4, 2025
c5c4482
Remove padding declaration in the factory.
aleksandar-apostolov Feb 4, 2025
3acafa1
Merge remote-tracking branch 'origin/AND-302-menu-item-statless-compo…
aleksandar-apostolov Feb 4, 2025
ec7e6bd
Rename the public function WITHOUT `Generic`
aleksandar-apostolov Feb 4, 2025
7c42654
ApiDump
aleksandar-apostolov Feb 4, 2025
65744c2
Merge branch 'develop' into AND-302-menu-item-statless-components
aleksandar-apostolov Feb 5, 2025
87c9bb3
spotless
aleksandar-apostolov Feb 5, 2025
84dc55b
Fix padding
aleksandar-apostolov Feb 5, 2025
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
77 changes: 60 additions & 17 deletions stream-chat-android-compose/api/stream-chat-android-compose.api

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import io.getstream.chat.android.compose.R
import io.getstream.chat.android.compose.state.channels.list.SearchQuery
import io.getstream.chat.android.compose.ui.channels.info.SelectedChannelMenu
import io.getstream.chat.android.compose.ui.channels.list.ChannelList
import io.getstream.chat.android.compose.ui.components.SearchInput
import io.getstream.chat.android.compose.ui.components.SimpleDialog
Expand Down Expand Up @@ -189,7 +188,7 @@ public fun ChannelsScreen(
enter = fadeIn(),
exit = fadeOut(animationSpec = tween(durationMillis = AnimationConstants.DefaultDurationMillis / 2)),
) {
SelectedChannelMenu(
ChatTheme.componentFactory.ChannelMenu(
modifier = Modifier
.align(Alignment.BottomCenter)
.animateEnterExit(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import androidx.compose.ui.unit.dp
import io.getstream.chat.android.compose.state.channels.list.ChannelOptionState
import io.getstream.chat.android.compose.ui.components.SimpleMenu
import io.getstream.chat.android.compose.ui.components.channels.ChannelMembers
import io.getstream.chat.android.compose.ui.components.channels.ChannelOptions
import io.getstream.chat.android.compose.ui.components.channels.buildDefaultChannelOptionsState
import io.getstream.chat.android.compose.ui.theme.ChatTheme
import io.getstream.chat.android.compose.ui.util.getMembersStatusText
Expand Down Expand Up @@ -79,16 +78,22 @@ public fun SelectedChannelMenu(
shape: Shape = ChatTheme.shapes.bottomSheet,
overlayColor: Color = ChatTheme.colors.overlay,
headerContent: @Composable ColumnScope.() -> Unit = {
DefaultSelectedChannelMenuHeaderContent(
selectedChannel = selectedChannel,
currentUser = currentUser,
)
with(ChatTheme.componentFactory) {
ChannelMenuHeaderContent(
modifier = Modifier,
aleksandar-apostolov marked this conversation as resolved.
Show resolved Hide resolved
selectedChannel = selectedChannel,
currentUser = currentUser,
)
}
},
centerContent: @Composable ColumnScope.() -> Unit = {
DefaultSelectedChannelMenuCenterContent(
onChannelOptionClick = onChannelOptionClick,
channelOptions = channelOptions,
)
with(ChatTheme.componentFactory) {
ChannelMenuCenterContent(
modifier = Modifier,
aleksandar-apostolov marked this conversation as resolved.
Show resolved Hide resolved
onChannelOptionClick = onChannelOptionClick,
channelOptions = channelOptions,
)
}
},
) {
SimpleMenu(
Expand Down Expand Up @@ -141,20 +146,6 @@ internal fun DefaultSelectedChannelMenuHeaderContent(
ChannelMembers(membersToDisplay)
}

/**
* Represents the default content shown at the center of [SelectedChannelMenu] dialog.
*
* @param onChannelOptionClick Handler for when the user selects a channel option.
* @param channelOptions The list of options to show in the UI, according to user permissions.
*/
@Composable
internal fun DefaultSelectedChannelMenuCenterContent(
onChannelOptionClick: (ChannelAction) -> Unit,
channelOptions: List<ChannelOptionState>,
) {
ChannelOptions(channelOptions, onChannelOptionClick)
}

/**
* Preview of [SelectedChannelMenu] styled as a centered modal dialog.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
Expand Down Expand Up @@ -81,21 +78,13 @@ public fun ChannelOptions(
.background(color = ChatTheme.colors.borders),
)

ChannelOptionsItem(
title = option.title,
titleColor = option.titleColor,
leadingIcon = {
Icon(
modifier = Modifier
.size(56.dp)
.padding(16.dp),
painter = option.iconPainter,
tint = option.iconColor,
contentDescription = null,
)
},
onClick = { onChannelOptionClick(option.action) },
)
with(ChatTheme.componentFactory) {
aleksandar-apostolov marked this conversation as resolved.
Show resolved Hide resolved
ChannelOptionsItem(
modifier = Modifier,
option = option,
onClick = { onChannelOptionClick(option.action) },
)
}
}
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright (c) 2014-2025 Stream.io Inc. All rights reserved.
*
* Licensed under the Stream License;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://github.com/GetStream/stream-chat-android/blob/main/LICENSE
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.getstream.chat.android.compose.ui.components.common

import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.material3.Text
import androidx.compose.material3.ripple
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import io.getstream.chat.android.compose.ui.theme.ChatTheme

/**
* Represents a generic menu option item that can be used in a list of options.
*
* @param modifier Modifier for styling.
* @param onClick Handler called when the item is clicked.
* @param leadingIcon The icon to show on the left side of the item.
* @param title The title of the item.
* @param titleColor The color of the title.
* @param style The style of the title.
* @param itemHeight The height of the item.
* @param verticalAlignment Used to apply vertical alignment.
* @param horizontalArrangement Used to apply horizontal arrangement.
*/
@Composable
public fun GenericMenuOptionItem(
aleksandar-apostolov marked this conversation as resolved.
Show resolved Hide resolved
modifier: Modifier = Modifier,
onClick: () -> Unit,
leadingIcon: @Composable RowScope.() -> Unit,
title: String,
titleColor: Color,
style: TextStyle = ChatTheme.typography.bodyBold,
itemHeight: Dp = 56.dp,
verticalAlignment: Alignment.Vertical = Alignment.CenterVertically,
horizontalArrangement: Arrangement.Horizontal = Arrangement.Start,
) {
Row(
modifier
.fillMaxWidth()
.height(itemHeight)
.clickable(
onClick = onClick,
indication = ripple(),
interactionSource = remember { MutableInteractionSource() },
),
verticalAlignment = verticalAlignment,
horizontalArrangement = horizontalArrangement,
) {
leadingIcon()
Text(
modifier = Modifier.testTag("Stream_ContextMenu_$title"),
text = title,
style = style,
color = titleColor,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,19 @@
package io.getstream.chat.android.compose.ui.components.messageoptions

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import io.getstream.chat.android.compose.R
import io.getstream.chat.android.compose.state.messageoptions.MessageOptionItemState
import io.getstream.chat.android.compose.ui.components.common.GenericMenuOptionItem
import io.getstream.chat.android.compose.ui.theme.ChatTheme
import io.getstream.chat.android.previewdata.PreviewMessageData
import io.getstream.chat.android.ui.common.state.messages.Reply
Expand All @@ -45,33 +43,37 @@ import io.getstream.chat.android.ui.common.state.messages.Reply
* @param horizontalArrangement Used to apply horizontal arrangement.
*/
@Composable
@Deprecated(
message = "This class is deprecated and will be removed in the next version.",
replaceWith = ReplaceWith("GenericMenuOptionItem"),
level = DeprecationLevel.WARNING,
)
public fun MessageOptionItem(
option: MessageOptionItemState,
modifier: Modifier = Modifier,
verticalAlignment: Alignment.Vertical = Alignment.CenterVertically,
horizontalArrangement: Arrangement.Horizontal = Arrangement.Start,
onMessageOptionItemSelected: (MessageOptionItemState) -> Unit = {},
aleksandar-apostolov marked this conversation as resolved.
Show resolved Hide resolved
) {
val title = stringResource(id = option.title)

Row(
GenericMenuOptionItem(
modifier = modifier,
title = title,
titleColor = option.titleColor,
leadingIcon = {
Icon(
modifier = Modifier.padding(horizontal = 16.dp),
painter = option.iconPainter,
tint = option.iconColor,
contentDescription = title,
)
},
onClick = { onMessageOptionItemSelected(option) },
style = ChatTheme.typography.body,
itemHeight = 56.dp,
verticalAlignment = verticalAlignment,
horizontalArrangement = horizontalArrangement,
) {
Icon(
modifier = Modifier.padding(horizontal = 16.dp),
painter = option.iconPainter,
tint = option.iconColor,
contentDescription = title,
)

Text(
modifier = Modifier.testTag("Stream_ContextMenu_$title"),
text = title,
style = ChatTheme.typography.body,
color = option.titleColor,
)
}
)
}

/**
Expand Down
Loading
Loading