@@ -190,51 +190,53 @@ struct PollOptionView: View {
190
190
var maxVotes : Int ?
191
191
/// If true, only option name and vote count is shown, otherwise votes indicator and avatars appear as well.
192
192
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
+
194
197
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 " )
210
211
}
211
212
}
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
+ }
225
229
}
226
230
}
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
+ )
227
239
}
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 )
238
240
}
239
241
}
240
242
}
0 commit comments