Refactor code structure for improved readability and maintainability
This commit is contained in:
@@ -919,6 +919,7 @@ private struct ComposeView: View {
|
||||
ComposeFieldCard(title: "Subject") {
|
||||
TextField("What's this about?", text: $model.composeDraft.subject)
|
||||
.textFieldStyle(.plain)
|
||||
.disabled(model.isSending)
|
||||
.accessibilityIdentifier("compose.subject")
|
||||
}
|
||||
|
||||
@@ -926,6 +927,7 @@ private struct ComposeView: View {
|
||||
TextEditor(text: $model.composeDraft.body)
|
||||
.scrollContentBackground(.hidden)
|
||||
.frame(minHeight: 240)
|
||||
.disabled(model.isSending)
|
||||
.accessibilityIdentifier("compose.body")
|
||||
}
|
||||
|
||||
@@ -937,23 +939,23 @@ private struct ComposeView: View {
|
||||
}
|
||||
}
|
||||
.navigationTitle("Compose")
|
||||
.navigationBarTitleDisplayMode(usesCompactComposeLayout ? .inline : .automatic)
|
||||
.composeNavigationTitleDisplayMode(isCompact: usesCompactComposeLayout)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .cancellationAction) {
|
||||
Button("Cancel") {
|
||||
dismiss()
|
||||
}
|
||||
.disabled(model.isSending)
|
||||
.accessibilityIdentifier("compose.cancel")
|
||||
}
|
||||
|
||||
ToolbarItem(placement: .confirmationAction) {
|
||||
Button("Send") {
|
||||
Button(model.isSending ? "Sending…" : "Send") {
|
||||
Task {
|
||||
await model.sendCurrentDraft()
|
||||
dismiss()
|
||||
_ = await model.sendCurrentDraft()
|
||||
}
|
||||
}
|
||||
.disabled(model.composeDraft.to.isEmpty || model.composeDraft.body.isEmpty)
|
||||
.disabled(model.isSending || model.composeDraft.to.isEmpty || model.composeDraft.body.isEmpty)
|
||||
.accessibilityIdentifier("compose.send")
|
||||
}
|
||||
}
|
||||
@@ -968,11 +970,13 @@ private struct ComposeView: View {
|
||||
.textContentType(.emailAddress)
|
||||
.keyboardType(.emailAddress)
|
||||
.textInputAutocapitalization(.never)
|
||||
.disabled(model.isSending)
|
||||
.accessibilityIdentifier("compose.to")
|
||||
#else
|
||||
TextField("name@example.com", text: $model.composeDraft.to)
|
||||
.textFieldStyle(.plain)
|
||||
.textContentType(.emailAddress)
|
||||
.disabled(model.isSending)
|
||||
.accessibilityIdentifier("compose.to")
|
||||
#endif
|
||||
}
|
||||
@@ -986,6 +990,17 @@ private struct ComposeView: View {
|
||||
}
|
||||
}
|
||||
|
||||
private extension View {
|
||||
@ViewBuilder
|
||||
func composeNavigationTitleDisplayMode(isCompact: Bool) -> some View {
|
||||
#if os(iOS)
|
||||
navigationBarTitleDisplayMode(isCompact ? .inline : .automatic)
|
||||
#else
|
||||
self
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
private struct ComposeFieldCard<Content: View>: View {
|
||||
let title: String
|
||||
let content: Content
|
||||
|
||||
Reference in New Issue
Block a user