Replace Draw Something context menu item with dedicated button

Fixes add attachment button not working on iOS 13. Adding a context menu
to a Button inside a List on iOS 13 prevents the button from ever
recognizing taps.
This commit is contained in:
Shadowfacts 2020-09-07 14:41:31 -04:00
parent ec2d510be2
commit fe95cb9e1a
Signed by untrusted user: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 31 additions and 26 deletions

View File

@ -44,45 +44,50 @@ struct ComposeAttachmentsList: View {
} }
Button(action: self.addAttachment) { Button(action: self.addAttachment) {
HStack { if #available(iOS 14.0, *) {
addButtonImage Label("Add photo or video", systemImage: addButtonImageName)
Text("Add image or video") } else {
} HStack {
} Image(systemName: addButtonImageName)
.foregroundColor(.blue) Text("Add photo or video")
.disabled(!canAddAttachment)
.frame(height: cellHeight)
.popover(isPresented: $isShowingAssetPickerPopover, content: self.assetPickerPopover)
.contextMenu {
Button(action: self.createDrawing) {
if #available(iOS 14.0, *) {
Label("Draw Something", systemImage: "hand.draw")
} else {
HStack {
Text("Draw Something")
Image(systemName: "hand.draw")
}
} }
} }
.disabled(!canAddAttachment)
} }
.disabled(!canAddAttachment)
.foregroundColor(.blue)
.frame(height: cellHeight / 2)
.popover(isPresented: $isShowingAssetPickerPopover, content: self.assetPickerPopover)
.listRowInsets(EdgeInsets(top: cellPadding / 2, leading: cellPadding / 2, bottom: cellPadding / 2, trailing: cellPadding / 2))
Button(action: self.createDrawing) {
if #available(iOS 14.0, *) {
Label("Draw something", systemImage: "hand.draw")
} else {
HStack(alignment: .lastTextBaseline) {
Image(systemName: "hand.draw")
Text("Draw something")
}
}
}
.disabled(!canAddAttachment)
.foregroundColor(.blue)
.frame(height: cellHeight / 2)
.listRowInsets(EdgeInsets(top: cellPadding / 2, leading: cellPadding / 2, bottom: cellPadding / 2, trailing: cellPadding / 2))
} }
.frame(height: totalListHeight) .frame(height: totalListHeight)
.onAppear(perform: self.didAppear) .onAppear(perform: self.didAppear)
.onReceive(draft.$attachments, perform: self.attachmentsChanged) .onReceive(draft.$attachments, perform: self.attachmentsChanged)
} }
private var addButtonImage: Image { private var addButtonImageName: String {
let name: String
switch colorScheme { switch colorScheme {
case .dark: case .dark:
name = "photo.fill" return "photo.fill"
case .light: case .light:
name = "photo" return "photo"
@unknown default: @unknown default:
name = "photo" return "photo"
} }
return Image(systemName: name)
} }
private var canAddAttachment: Bool { private var canAddAttachment: Bool {
@ -98,7 +103,7 @@ struct ComposeAttachmentsList: View {
private var totalListHeight: CGFloat { private var totalListHeight: CGFloat {
let totalRowHeights = rowHeights.values.reduce(0, +) let totalRowHeights = rowHeights.values.reduce(0, +)
let totalPadding = CGFloat(draft.attachments.count) * cellPadding let totalPadding = CGFloat(draft.attachments.count) * cellPadding
let addButtonHeight = cellHeight + cellPadding let addButtonHeight = cellHeight + cellPadding * 2
return totalRowHeights + totalPadding + addButtonHeight return totalRowHeights + totalPadding + addButtonHeight
} }