Skip to content

Commit 84ada32

Browse files
authored
Fix various poll UI issues (#6346)
* Update poll section background color * Remove avatar border from poll vote item * Set text caret at the end in poll comment dialog * Update duplicate option error appearance * Update snapshots * Extract PollOptionErrorRow * Update string * Improve poll option row accessibility
1 parent a264e34 commit 84ada32

15 files changed

Lines changed: 74 additions & 62 deletions

stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/components/composer/InputField.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public fun InputField(
8585
),
8686
decorationBox: @Composable (innerTextField: @Composable () -> Unit) -> Unit,
8787
) {
88-
var textState by remember { mutableStateOf(TextFieldValue(text = value)) }
88+
var textState by remember { mutableStateOf(TextFieldValue(text = value, selection = TextRange(value.length))) }
8989

9090
if (textState.text != value) {
9191
// Workaround to move cursor to the end after selecting a suggestion

stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/components/poll/PollViewResultDialog.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ internal fun PollSection(
346346
modifier = modifier
347347
.fillMaxWidth()
348348
.clip(shape = RoundedCornerShape(StreamTokens.radiusXl))
349-
.background(ChatTheme.colors.backgroundCoreSurfaceSubtle)
349+
.background(ChatTheme.colors.backgroundCoreSurfaceCard)
350350
.padding(contentPadding),
351351
verticalArrangement = verticalArrangement,
352352
content = content,

stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/components/poll/PollVoteItem.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ internal fun PollVoteItem(
5555
.padding(borderSize),
5656
user = user,
5757
showIndicator = false,
58-
showBorder = true,
58+
showBorder = false,
5959
),
6060
)
6161

stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/messages/attachments/poll/PollOptionList.kt

Lines changed: 63 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import androidx.compose.material3.Icon
3131
import androidx.compose.material3.IconButton
3232
import androidx.compose.material3.LocalMinimumInteractiveComponentSize
3333
import androidx.compose.material3.Text
34+
import androidx.compose.material3.minimumInteractiveComponentSize
3435
import androidx.compose.runtime.Composable
3536
import androidx.compose.runtime.getValue
3637
import androidx.compose.runtime.key
@@ -45,7 +46,6 @@ import androidx.compose.ui.res.painterResource
4546
import androidx.compose.ui.res.stringResource
4647
import androidx.compose.ui.tooling.preview.Preview
4748
import androidx.compose.ui.unit.dp
48-
import androidx.compose.ui.unit.sp
4949
import io.getstream.chat.android.compose.R
5050
import io.getstream.chat.android.compose.ui.components.poll.PollOptionInput
5151
import io.getstream.chat.android.compose.ui.theme.ChatTheme
@@ -131,61 +131,80 @@ private fun ReorderableScope.PollOptionRow(
131131
onRemove: () -> Unit,
132132
) {
133133
val colors = ChatTheme.colors
134-
val borderColor = if (item.pollOptionError == null) colors.borderCoreDefault else colors.accentError
135-
Row(
134+
Column(
136135
modifier = Modifier
137136
.fillMaxWidth()
138-
.border(width = 1.dp, color = borderColor, shape = PollInputShape)
137+
.border(width = 1.dp, color = colors.borderCoreDefault, shape = PollInputShape)
139138
.clip(shape = PollInputShape),
140-
verticalAlignment = Alignment.CenterVertically,
141139
) {
142-
IconButton(
143-
modifier = Modifier.draggableHandle(),
144-
onClick = {},
140+
Row(
141+
modifier = Modifier.fillMaxWidth(),
142+
verticalAlignment = Alignment.CenterVertically,
145143
) {
146-
Icon(
147-
painter = painterResource(id = R.drawable.stream_design_ic_reorder),
148-
contentDescription = null,
149-
tint = colors.inputTextIcon,
150-
modifier = Modifier.size(20.dp),
144+
Box(
145+
modifier = Modifier
146+
.draggableHandle()
147+
.minimumInteractiveComponentSize(),
148+
) {
149+
Icon(
150+
painter = painterResource(id = R.drawable.stream_design_ic_reorder),
151+
contentDescription = stringResource(R.string.stream_compose_poll_option_reorder),
152+
tint = colors.inputTextIcon,
153+
modifier = Modifier.size(20.dp),
154+
)
155+
}
156+
157+
PollOptionInput(
158+
modifier = Modifier.weight(1f),
159+
value = item.title,
160+
description = stringResource(id = R.string.stream_compose_poll_option_hint),
161+
onValueChange = onTitleChange,
151162
)
152-
}
153163

154-
PollOptionInput(
155-
modifier = Modifier.weight(1f),
156-
value = item.title,
157-
description = stringResource(id = R.string.stream_compose_poll_option_hint),
158-
onValueChange = onTitleChange,
159-
decorationBox = { innerTextField ->
160-
if (item.pollOptionError == null || item.title.isBlank()) {
161-
innerTextField()
162-
} else {
163-
Column {
164-
Text(
165-
modifier = Modifier
166-
.fillMaxWidth()
167-
.padding(bottom = StreamTokens.spacing2xs),
168-
text = item.pollOptionError.message,
169-
color = colors.accentError,
170-
fontSize = 12.sp,
171-
)
172-
innerTextField()
173-
}
174-
}
175-
},
176-
)
164+
IconButton(onClick = onRemove) {
165+
Icon(
166+
painter = painterResource(R.drawable.stream_design_ic_minus_circle),
167+
contentDescription = stringResource(R.string.stream_compose_poll_option_remove),
168+
tint = colors.inputTextIcon,
169+
modifier = Modifier.size(20.dp),
170+
)
171+
}
172+
}
177173

178-
IconButton(onClick = onRemove) {
179-
Icon(
180-
painter = painterResource(R.drawable.stream_design_ic_minus_circle),
181-
contentDescription = null,
182-
tint = colors.inputTextIcon,
183-
modifier = Modifier.size(20.dp),
184-
)
174+
if (item.pollOptionError != null && item.title.isNotBlank()) {
175+
PollOptionErrorRow(item.pollOptionError)
185176
}
186177
}
187178
}
188179

180+
@Composable
181+
private fun PollOptionErrorRow(pollOptionError: PollOptionError) {
182+
val colors = ChatTheme.colors
183+
Row(
184+
modifier = Modifier
185+
.fillMaxWidth()
186+
.padding(
187+
start = StreamTokens.spacingMd,
188+
end = StreamTokens.spacingMd,
189+
bottom = StreamTokens.spacingSm,
190+
),
191+
horizontalArrangement = Arrangement.spacedBy(StreamTokens.spacingXs),
192+
verticalAlignment = Alignment.CenterVertically,
193+
) {
194+
Icon(
195+
painter = painterResource(R.drawable.stream_design_ic_exclamation_circle),
196+
contentDescription = null,
197+
tint = colors.accentError,
198+
modifier = Modifier.size(20.dp),
199+
)
200+
Text(
201+
text = pollOptionError.message,
202+
color = colors.accentError,
203+
style = ChatTheme.typography.captionDefault,
204+
)
205+
}
206+
}
207+
189208
@Composable
190209
private fun AddPollOptionButton(onClick: () -> Unit) {
191210
val colors = ChatTheme.colors

stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/messages/attachments/poll/PollSwitchList.kt

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,18 @@
1717
package io.getstream.chat.android.compose.ui.messages.attachments.poll
1818

1919
import androidx.compose.animation.animateContentSize
20-
import androidx.compose.foundation.background
2120
import androidx.compose.foundation.border
2221
import androidx.compose.foundation.layout.Arrangement
2322
import androidx.compose.foundation.layout.Box
2423
import androidx.compose.foundation.layout.Column
24+
import androidx.compose.foundation.layout.PaddingValues
2525
import androidx.compose.foundation.layout.Row
2626
import androidx.compose.foundation.layout.fillMaxWidth
2727
import androidx.compose.foundation.layout.padding
2828
import androidx.compose.foundation.layout.size
2929
import androidx.compose.foundation.layout.width
3030
import androidx.compose.foundation.rememberScrollState
3131
import androidx.compose.foundation.shape.CircleShape
32-
import androidx.compose.foundation.shape.RoundedCornerShape
3332
import androidx.compose.foundation.text.BasicTextField
3433
import androidx.compose.foundation.text.KeyboardOptions
3534
import androidx.compose.foundation.verticalScroll
@@ -52,6 +51,7 @@ import androidx.compose.ui.tooling.preview.Preview
5251
import androidx.compose.ui.unit.dp
5352
import io.getstream.chat.android.compose.R
5453
import io.getstream.chat.android.compose.ui.components.StreamSwitch
54+
import io.getstream.chat.android.compose.ui.components.poll.PollSection
5555
import io.getstream.chat.android.compose.ui.theme.ChatTheme
5656
import io.getstream.chat.android.compose.ui.theme.StreamTokens
5757
import io.getstream.chat.android.compose.ui.util.applyIf
@@ -142,18 +142,9 @@ private fun PollSwitchListItem(
142142
onCheckedChange: (Boolean) -> Unit,
143143
childContent: (@Composable () -> Unit)? = null,
144144
) {
145-
Column(
146-
modifier = Modifier
147-
.fillMaxWidth()
148-
.animateContentSize()
149-
.border(
150-
width = 1.dp,
151-
color = ChatTheme.colors.backgroundCoreSurfaceDefault,
152-
shape = RoundedCornerShape(StreamTokens.radiusXl),
153-
)
154-
.clip(shape = RoundedCornerShape(StreamTokens.radiusXl))
155-
.background(ChatTheme.colors.backgroundCoreSurfaceDefault)
156-
.padding(StreamTokens.spacingMd),
145+
PollSection(
146+
modifier = Modifier.animateContentSize(),
147+
contentPadding = PaddingValues(StreamTokens.spacingMd),
157148
) {
158149
PollSwitchHeader(
159150
title = title,

stream-chat-android-compose/src/main/res/values/strings.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@
269269
<string name="stream_compose_poll_option_title">Options</string>
270270
<string name="stream_compose_poll_option_description">Add an option</string>
271271
<string name="stream_compose_poll_option_hint">Add an option</string>
272-
<string name="stream_compose_poll_option_error_duplicated">This is already an option</string>
272+
<string name="stream_compose_poll_option_error_duplicated">Option already exists</string>
273273
<string name="stream_compose_poll_option_discard_dialog_title">Discard poll</string>
274274
<string name="stream_compose_poll_option_discard_dialog_description">Are you sure you want to discard your poll?</string>
275275
<string name="stream_compose_poll_option_discard_dialog_cancel">Keep Editing</string>
@@ -317,6 +317,8 @@
317317

318318
<string name="stream_compose_poll_created_preview">Poll created: %s</string>
319319
<string name="stream_compose_poll_closed_preview">Poll closed: %s</string>
320+
<string name="stream_compose_poll_option_reorder">Reorder poll option</string>
321+
<string name="stream_compose_poll_option_remove">Remove poll option</string>
320322

321323
<!-- Pinned message list -->
322324
<string name="stream_compose_pinned_message_list_empty_title">No pinned messages</string>
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)