refactor: Split ExcludedDomainsView into a separate file

This commit is contained in:
Kenta Kubo 2025-09-03 03:01:28 +09:00
parent 031f9408a0
commit 3d5397fa7e
2 changed files with 45 additions and 36 deletions

View file

@ -0,0 +1,45 @@
import SwiftUI
struct ExcludedDomainsView {
@Binding var domains: [String]
}
extension ExcludedDomainsView: View {
var body: some View {
Form {
Section {
ForEach(0..<self.domains.count, id: \.self) { i in
LazyTextField(
"Domain",
// self.$rule.excludedDomains[i] causes crash on deletion
text: .init(
get: { self.domains[i] },
set: { self.domains[i] = $0 }
)
)
}
.onDelete { self.domains.remove(atOffsets: $0) }
.onMove { self.domains.move(fromOffsets: $0, toOffset: $1) }
Button("Add Domain") {
self.domains.append("")
}
} footer: {
Text(
"Each domain is matched against the destination hostname using suffix matching, and each label in the domain must match an entire label in the hostname. For example, the domain `example.com` will match the hostname `www.example.com` but not `www.anotherexample.com`."
)
}
}
.navigationTitle("Excluded Domains")
.toolbar {
EditButton()
}
}
}
@available(iOS 17, *)
#Preview {
@Previewable @State var domains = ["example.com"]
NavigationStack {
ExcludedDomainsView(domains: $domains)
}
}

View file

@ -8,42 +8,6 @@
import NetworkExtension
import SwiftUI
struct ExcludedDomainsView {
@Binding var domains: [String]
}
extension ExcludedDomainsView: View {
var body: some View {
Form {
Section {
ForEach(0..<self.domains.count, id: \.self) { i in
LazyTextField(
"Domain",
// self.$rule.excludedDomains[i] causes crash on deletion
text: .init(
get: { self.domains[i] },
set: { self.domains[i] = $0 }
)
)
}
.onDelete { self.domains.remove(atOffsets: $0) }
.onMove { self.domains.move(fromOffsets: $0, toOffset: $1) }
Button("Add Domain") {
self.domains.append("")
}
} footer: {
Text(
"Each domain is matched against the destination hostname using suffix matching, and each label in the domain must match an entire label in the hostname. For example, the domain `example.com` will match the hostname `www.example.com` but not `www.anotherexample.com`."
)
}
}
.navigationTitle("Excluded Domains")
.toolbar {
EditButton()
}
}
}
struct RuleView {
@Binding var rule: OnDemandRule
}