Skip to content

Commit 51386f9

Browse files
committed
Fix pill preview height and re-target the click testTag
Two related fixes on the pill composable: - Bound the inner Row to Modifier.height(IntrinsicSize.Min). VerticalDivider uses fillMaxHeight() internally, which was unbounded inside the Surface preview and stretched the pill across the rendered surface. With IntrinsicSize.Min, the divider's height resolves to the tallest non-flexible child (the label row or the close icon). - Move the Stream_ScrollToFirstUnreadButton testTag from the Surface to the inner clickable Row. The Surface is not interactive, so a UI test that finds the node by tag and performs a click would land on a non-clickable node. With the tag on the click target, finding by tag and clicking now invokes the scroll handler, mirroring the dismiss tag on the X icon.
1 parent cce0de2 commit 51386f9

4 files changed

Lines changed: 27 additions & 28 deletions

File tree

stream-chat-android-compose/api/stream-chat-android-compose.api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1519,7 +1519,7 @@ public final class io/getstream/chat/android/compose/ui/components/messages/Comp
15191519
public final class io/getstream/chat/android/compose/ui/components/messages/ComposableSingletons$ScrollToFirstUnreadButtonKt {
15201520
public static final field INSTANCE Lio/getstream/chat/android/compose/ui/components/messages/ComposableSingletons$ScrollToFirstUnreadButtonKt;
15211521
public fun <init> ()V
1522-
public final fun getLambda$-1749808746$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function2;
1522+
public final fun getLambda$-1405339857$stream_chat_android_compose_release ()Lkotlin/jvm/functions/Function2;
15231523
}
15241524

15251525
public final class io/getstream/chat/android/compose/ui/components/messages/ComposableSingletons$SwipeToReplyIconKt {

stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/components/messages/ScrollToFirstUnreadButton.kt

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ package io.getstream.chat.android.compose.ui.components.messages
1818

1919
import androidx.compose.foundation.BorderStroke
2020
import androidx.compose.foundation.layout.Arrangement
21+
import androidx.compose.foundation.layout.IntrinsicSize
2122
import androidx.compose.foundation.layout.Row
23+
import androidx.compose.foundation.layout.fillMaxHeight
24+
import androidx.compose.foundation.layout.height
25+
import androidx.compose.foundation.layout.heightIn
2226
import androidx.compose.foundation.layout.padding
2327
import androidx.compose.foundation.layout.size
2428
import androidx.compose.foundation.shape.CircleShape
@@ -65,20 +69,23 @@ internal fun ScrollToFirstUnreadButton(
6569
) {
6670
Surface(
6771
modifier = modifier
68-
.shadow(StreamTokens.spacing2xs, shape = CircleShape)
69-
.testTag("Stream_ScrollToFirstUnreadButton"),
72+
.shadow(StreamTokens.spacing2xs, shape = CircleShape),
7073
shape = CircleShape,
7174
color = ChatTheme.colors.backgroundCoreElevation1,
7275
contentColor = ChatTheme.colors.textPrimary,
73-
border = BorderStroke(StreamTokens.borderStrokeSubtle, ChatTheme.colors.borderCoreSubtle),
76+
border = BorderStroke(1.dp, ChatTheme.colors.borderCoreSubtle),
7477
) {
7578
Row(
79+
modifier = Modifier
80+
.height(IntrinsicSize.Min)
81+
.heightIn(min = 40.dp),
7682
verticalAlignment = Alignment.CenterVertically,
7783
) {
7884
Row(
7985
modifier = Modifier
86+
.testTag("Stream_ScrollToFirstUnreadButton")
8087
.clickable(role = Role.Button, onClick = onClick)
81-
.padding(vertical = StreamTokens.spacingXs)
88+
.fillMaxHeight()
8289
.padding(start = StreamTokens.spacingSm, end = StreamTokens.spacingXs),
8390
horizontalArrangement = Arrangement.spacedBy(StreamTokens.spacing2xs),
8491
verticalAlignment = Alignment.CenterVertically,
@@ -98,14 +105,15 @@ internal fun ScrollToFirstUnreadButton(
98105
)
99106
}
100107
VerticalDivider(
108+
modifier = Modifier.padding(vertical = StreamTokens.spacing2xs),
101109
thickness = StreamTokens.borderStrokeSubtle,
102110
color = ChatTheme.colors.borderCoreSubtle,
103111
)
104112
Icon(
105113
modifier = Modifier
106-
.clickable(role = Role.Button, onClick = onDismiss)
107114
.testTag("Stream_ScrollToFirstUnreadButton_Dismiss")
108-
.padding(vertical = StreamTokens.spacingXs)
115+
.clickable(role = Role.Button, onClick = onDismiss)
116+
.fillMaxHeight()
109117
.padding(start = StreamTokens.spacingXs, end = StreamTokens.spacingSm)
110118
.size(IconSize),
111119
painter = painterResource(R.drawable.stream_design_ic_xmark),
@@ -117,10 +125,15 @@ internal fun ScrollToFirstUnreadButton(
117125

118126
@Composable
119127
@Preview(showBackground = true)
120-
private fun Preview() {
128+
private fun ScrollToFirstUnreadButtonPreview() {
121129
ChatTheme {
122-
ScrollToFirstUnreadButton(
123-
unreadCount = 9,
124-
)
130+
ScrollToFirstUnreadButton()
125131
}
126132
}
133+
134+
@Composable
135+
internal fun ScrollToFirstUnreadButton() {
136+
ScrollToFirstUnreadButton(
137+
unreadCount = 9,
138+
)
139+
}

stream-chat-android-compose/src/test/kotlin/io/getstream/chat/android/compose/ui/components/messages/ScrollToFirstUnreadButtonTest.kt

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,9 @@ internal class ScrollToFirstUnreadButtonTest : PaparazziComposeTest {
3232
)
3333

3434
@Test
35-
fun `pill with single unread`() {
36-
snapshotWithDarkMode {
37-
ScrollToFirstUnreadButton(unreadCount = 1)
38-
}
39-
}
40-
41-
@Test
42-
fun `pill with default unread count`() {
43-
snapshotWithDarkMode {
44-
ScrollToFirstUnreadButton(unreadCount = 9)
45-
}
46-
}
47-
48-
@Test
49-
fun `pill with large unread count`() {
50-
snapshotWithDarkMode {
51-
ScrollToFirstUnreadButton(unreadCount = 999)
35+
fun `pill with unread count`() {
36+
snapshotWithDarkModeRow {
37+
ScrollToFirstUnreadButton()
5238
}
5339
}
5440
}
Loading

0 commit comments

Comments
 (0)