Make poll options in Compose reorderable with drag/drop

This commit is contained in:
Shadowfacts 2022-11-20 14:06:45 -05:00
parent 001a73af3c
commit 810ae71832
1 changed files with 13 additions and 2 deletions

View File

@ -51,9 +51,20 @@ struct ComposePollView: View {
.hoverEffect()
}
ForEach(Array(poll.options.enumerated()), id: \.element.id) { (e) in
ComposePollOption(poll: poll, option: e.element, optionIndex: e.offset)
List {
ForEach(Array(poll.options.enumerated()), id: \.element.id) { (e) in
ComposePollOption(poll: poll, option: e.element, optionIndex: e.offset)
.frame(height: 36)
.listRowInsets(EdgeInsets(top: 4, leading: 0, bottom: 4, trailing: 0))
.listRowSeparator(.hidden)
.listRowBackground(Color.clear)
}
.onMove { indices, newIndex in
poll.options.move(fromOffsets: indices, toOffset: newIndex)
}
}
.listStyle(.plain)
.frame(height: 44 * CGFloat(poll.options.count))
Button(action: self.addOption) {
Label("Add Option", systemImage: "plus")