From 0ad8d115bc398f81126ec9d99c48fe34088bb38a Mon Sep 17 00:00:00 2001 From: Kenta Kubo <601636+kkebo@users.noreply.github.com> Date: Thu, 6 Jun 2024 02:23:00 +0900 Subject: [PATCH] refactor: use `#Preview` macros The `#Preview` macro is a simple replacement for the `PreviewProvider` protocol. --- DNSecure/Views/ContentView.swift | 6 ++---- DNSecure/Views/DetailView.swift | 22 +++++++++----------- DNSecure/Views/DoHSections.swift | 28 ++++++++++++-------------- DNSecure/Views/DoTSections.swift | 28 ++++++++++++-------------- DNSecure/Views/HowToActivateView.swift | 6 ++---- DNSecure/Views/LazyTextField.swift | 6 ++---- DNSecure/Views/RuleView.swift | 6 ++---- 7 files changed, 44 insertions(+), 58 deletions(-) diff --git a/DNSecure/Views/ContentView.swift b/DNSecure/Views/ContentView.swift index cb1becd..0db3607 100644 --- a/DNSecure/Views/ContentView.swift +++ b/DNSecure/Views/ContentView.swift @@ -335,8 +335,6 @@ extension ContentView: View { } } -struct ContentView_Previews: PreviewProvider { - static var previews: some View { - ContentView(servers: .constant(Presets.servers), usedID: .constant(nil)) - } +#Preview { + ContentView(servers: .constant(Presets.servers), usedID: .constant(nil)) } diff --git a/DNSecure/Views/DetailView.swift b/DNSecure/Views/DetailView.swift index b3736a1..e8b4085 100644 --- a/DNSecure/Views/DetailView.swift +++ b/DNSecure/Views/DetailView.swift @@ -119,16 +119,14 @@ extension DetailView: View { } } -struct DetailView_Previews: PreviewProvider { - static var previews: some View { - DetailView( - server: .constant( - .init( - name: "My Server", - configuration: .dnsOverTLS(DoTConfiguration()) - ) - ), - isOn: .constant(true) - ) - } +#Preview { + DetailView( + server: .constant( + .init( + name: "My Server", + configuration: .dnsOverTLS(DoTConfiguration()) + ) + ), + isOn: .constant(true) + ) } diff --git a/DNSecure/Views/DoHSections.swift b/DNSecure/Views/DoHSections.swift index df180a1..56d981c 100644 --- a/DNSecure/Views/DoHSections.swift +++ b/DNSecure/Views/DoHSections.swift @@ -55,22 +55,20 @@ extension DoHSections: View { } } -struct DoHSections_Previews: PreviewProvider { - static var previews: some View { - Form { - DoHSections( - configuration: .constant( - .init( - servers: [ - "1.1.1.1", - "1.0.0.1", - "2606:4700:4700::1111", - "2606:4700:4700::1001", - ], - serverURL: URL(string: "https://cloudflare-dns.com/dns-query") - ) +#Preview { + Form { + DoHSections( + configuration: .constant( + .init( + servers: [ + "1.1.1.1", + "1.0.0.1", + "2606:4700:4700::1111", + "2606:4700:4700::1001", + ], + serverURL: URL(string: "https://cloudflare-dns.com/dns-query") ) ) - } + ) } } diff --git a/DNSecure/Views/DoTSections.swift b/DNSecure/Views/DoTSections.swift index c61ef20..04f8dcf 100644 --- a/DNSecure/Views/DoTSections.swift +++ b/DNSecure/Views/DoTSections.swift @@ -55,22 +55,20 @@ extension DoTSections: View { } } -struct DoTSections_Previews: PreviewProvider { - static var previews: some View { - Form { - DoTSections( - configuration: .constant( - .init( - servers: [ - "1.1.1.1", - "1.0.0.1", - "2606:4700:4700::1111", - "2606:4700:4700::1001", - ], - serverName: "cloudflare-dns.com" - ) +#Preview { + Form { + DoTSections( + configuration: .constant( + .init( + servers: [ + "1.1.1.1", + "1.0.0.1", + "2606:4700:4700::1111", + "2606:4700:4700::1001", + ], + serverName: "cloudflare-dns.com" ) ) - } + ) } } diff --git a/DNSecure/Views/HowToActivateView.swift b/DNSecure/Views/HowToActivateView.swift index a149b65..1abd506 100644 --- a/DNSecure/Views/HowToActivateView.swift +++ b/DNSecure/Views/HowToActivateView.swift @@ -175,8 +175,6 @@ extension HowToActivateView: View { } } -struct HowToActivateView_Previews: PreviewProvider { - static var previews: some View { - HowToActivateView(isSheet: true) - } +#Preview { + HowToActivateView(isSheet: true) } diff --git a/DNSecure/Views/LazyTextField.swift b/DNSecure/Views/LazyTextField.swift index 9621fd1..9ffdbe8 100644 --- a/DNSecure/Views/LazyTextField.swift +++ b/DNSecure/Views/LazyTextField.swift @@ -48,8 +48,6 @@ extension LazyTextField: View { } } -struct LazyTextField_Previews: PreviewProvider { - static var previews: some View { - LazyTextField("Name", text: .constant("")) - } +#Preview { + LazyTextField("Name", text: .constant("")) } diff --git a/DNSecure/Views/RuleView.swift b/DNSecure/Views/RuleView.swift index 5d46ebd..c7e3c2b 100644 --- a/DNSecure/Views/RuleView.swift +++ b/DNSecure/Views/RuleView.swift @@ -139,8 +139,6 @@ extension RuleView: View { } } -struct RuleView_Previews: PreviewProvider { - static var previews: some View { - RuleView(rule: .constant(OnDemandRule(name: "Preview Rule"))) - } +#Preview { + RuleView(rule: .constant(OnDemandRule(name: "Preview Rule"))) }