Skip to content

Commit 4883a85

Browse files
committed
Fix the vote progress view not having full width when the Poll is closed
1 parent 4dd1264 commit 4883a85

File tree

4 files changed

+43
-40
lines changed

4 files changed

+43
-40
lines changed

Sources/StreamChatSwiftUI/ChatChannel/MessageList/Polls/PollAllOptionsView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ struct PollAllOptionsView: View {
3131
viewModel: viewModel,
3232
option: option,
3333
optionFont: fonts.headline,
34-
alternativeStyle: true
34+
alternativeStyle: true,
35+
checkboxButtonSpacing: 8
3536
)
3637
}
3738
}

Sources/StreamChatSwiftUI/ChatChannel/MessageList/Polls/PollAttachmentView.swift

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -190,51 +190,53 @@ struct PollOptionView: View {
190190
var maxVotes: Int?
191191
/// If true, only option name and vote count is shown, otherwise votes indicator and avatars appear as well.
192192
var alternativeStyle: Bool = false
193-
193+
/// The spacing between the checkbox and the option name.
194+
/// By default it is 4. For All Options View is 8.
195+
var checkboxButtonSpacing: CGFloat = 4
196+
194197
var body: some View {
195-
VStack(spacing: 4) {
196-
HStack(alignment: .top) {
197-
if !viewModel.poll.isClosed {
198-
Button {
199-
if viewModel.optionVotedByCurrentUser(option) {
200-
viewModel.removePollVote(for: option)
201-
} else {
202-
viewModel.castPollVote(for: option)
203-
}
204-
} label: {
205-
if viewModel.optionVotedByCurrentUser(option) {
206-
Image(systemName: "checkmark.circle.fill")
207-
} else {
208-
Image(systemName: "circle")
209-
}
198+
HStack(alignment: .top, spacing: checkboxButtonSpacing) {
199+
if !viewModel.poll.isClosed {
200+
Button {
201+
if viewModel.optionVotedByCurrentUser(option) {
202+
viewModel.removePollVote(for: option)
203+
} else {
204+
viewModel.castPollVote(for: option)
205+
}
206+
} label: {
207+
if viewModel.optionVotedByCurrentUser(option) {
208+
Image(systemName: "checkmark.circle.fill")
209+
} else {
210+
Image(systemName: "circle")
210211
}
211212
}
212-
213-
Text(option.text)
214-
.font(optionFont)
215-
Spacer()
216-
if !alternativeStyle, viewModel.showVoterAvatars {
217-
HStack(spacing: -4) {
218-
ForEach(
219-
option.latestVotes.sorted(by: { $0.createdAt > $1.createdAt }).suffix(2)
220-
) { vote in
221-
MessageAvatarView(
222-
avatarURL: vote.user?.imageURL,
223-
size: .init(width: 20, height: 20)
224-
)
213+
}
214+
VStack(spacing: 4) {
215+
HStack(alignment: .top) {
216+
Text(option.text)
217+
.font(optionFont)
218+
Spacer()
219+
if !alternativeStyle, viewModel.showVoterAvatars {
220+
HStack(spacing: -4) {
221+
ForEach(
222+
option.latestVotes.sorted(by: { $0.createdAt > $1.createdAt }).suffix(2)
223+
) { vote in
224+
MessageAvatarView(
225+
avatarURL: vote.user?.imageURL,
226+
size: .init(width: 20, height: 20)
227+
)
228+
}
225229
}
226230
}
231+
Text("\(viewModel.poll.voteCountsByOption?[option.id] ?? 0)")
232+
}
233+
if !alternativeStyle {
234+
PollVotesIndicatorView(
235+
alternativeStyle: viewModel.poll.isClosed && viewModel.hasMostVotes(for: option),
236+
optionVotes: optionVotes ?? 0,
237+
maxVotes: maxVotes ?? 0
238+
)
227239
}
228-
Text("\(viewModel.poll.voteCountsByOption?[option.id] ?? 0)")
229-
}
230-
231-
if !alternativeStyle {
232-
PollVotesIndicatorView(
233-
alternativeStyle: viewModel.poll.isClosed && viewModel.hasMostVotes(for: option),
234-
optionVotes: optionVotes ?? 0,
235-
maxVotes: maxVotes ?? 0
236-
)
237-
.padding(.leading, 24)
238240
}
239241
}
240242
}
Loading
Loading

0 commit comments

Comments
 (0)