a native ios client for gitbay

client ios swift

https://gitbay.org

gitbay/Views/Shared/ComposeSheet.swift

59 lines · 2086 bytes

 1import SwiftUI
 2
 3/// Title-and-body editor shared by issue/MR create and edit sheets.
 4struct ComposeSheet: View {
 5
 6    let heading: String
 7    let submitLabel: String
 8    let working: Bool
 9    let errorMessage: String?
10    @Binding var title: String
11    @Binding var bodyText: String
12    let onSubmit: () -> Void
13
14    @Environment(\.dismiss) private var dismiss
15
16    var body: some View {
17        NavigationStack {
18            Form {
19                Section("Title") {
20                    TextField("Title", text: $title, axis: .vertical)
21                        .lineLimit(1...3)
22                        // Titles name code: paths, commands, branch names.
23                        // Autocorrection rewrites them.
24                        .autocorrectionDisabled()
25                        .accessibilityIdentifier("compose-title")
26                }
27                Section("Body") {
28                    TextEditor(text: $bodyText)
29                        .frame(minHeight: 160)
30                        .font(.gbSans(.body))
31                        .autocorrectionDisabled()
32                        .accessibilityIdentifier("compose-body")
33                }
34                if let errorMessage {
35                    Section {
36                        GBNotice(errorMessage)
37                    }
38                }
39            }
40            .navigationTitle(heading)
41            .navigationBarTitleDisplayMode(.inline)
42            .toolbar {
43                ToolbarItem(placement: .cancellationAction) {
44                    Button("Cancel") { dismiss() }
45                }
46                ToolbarItem(placement: .confirmationAction) {
47                    if working {
48                        ProgressView()
49                    } else {
50                        Button(submitLabel, action: onSubmit)
51                            .disabled(title.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty)
52                            .accessibilityIdentifier("compose-submit")
53                    }
54                }
55            }
56            .interactiveDismissDisabled(working)
57        }
58    }
59}