From 5e7f2ba36f2709bacb9fab4ce0521765b792ab1f Mon Sep 17 00:00:00 2001 From: KaitoMuraoka Date: Sat, 20 Jul 2024 11:23:24 +0900 Subject: [PATCH 1/2] Change from WKWebView to SafariView --- PasswordBox.xcodeproj/project.pbxproj | 12 +++-- PasswordBox/Resources/URLs.swift | 1 + PasswordBox/UI/Info/Contact.swift | 18 ------- PasswordBox/UI/Info/InfomationView.swift | 18 ++++--- .../UI/Info/OpenURLInSafariViewModifier.swift | 47 +++++++++++++++++++ PasswordBox/UI/Info/SafariView.swift | 29 ++++++++++++ 6 files changed, 93 insertions(+), 32 deletions(-) delete mode 100644 PasswordBox/UI/Info/Contact.swift create mode 100644 PasswordBox/UI/Info/OpenURLInSafariViewModifier.swift create mode 100644 PasswordBox/UI/Info/SafariView.swift diff --git a/PasswordBox.xcodeproj/project.pbxproj b/PasswordBox.xcodeproj/project.pbxproj index 8cd96ab..cb74284 100644 --- a/PasswordBox.xcodeproj/project.pbxproj +++ b/PasswordBox.xcodeproj/project.pbxproj @@ -14,11 +14,12 @@ 3F026F362C3A618400ED696C /* LicenseList in Frameworks */ = {isa = PBXBuildFile; productRef = 3F026F352C3A618400ED696C /* LicenseList */; }; 3F026F382C3A622500ED696C /* LicenseList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F026F372C3A622500ED696C /* LicenseList.swift */; }; 3F026F402C3A779900ED696C /* WebUI in Frameworks */ = {isa = PBXBuildFile; productRef = 3F026F3F2C3A779900ED696C /* WebUI */; }; - 3F026F422C3A77A600ED696C /* Contact.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F026F412C3A77A600ED696C /* Contact.swift */; }; + 3F026F422C3A77A600ED696C /* OpenURLInSafariViewModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F026F412C3A77A600ED696C /* OpenURLInSafariViewModifier.swift */; }; 3F026F442C3A789500ED696C /* URLs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F026F432C3A789500ED696C /* URLs.swift */; }; 3F13F9C62C1DECF30068908E /* InfomationViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F13F9C52C1DECF30068908E /* InfomationViewModel.swift */; }; 3F13F9C82C1DED720068908E /* EditView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F13F9C72C1DED720068908E /* EditView.swift */; }; 3F13F9CB2C1DEE020068908E /* PasswordFormView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F13F9CA2C1DEE020068908E /* PasswordFormView.swift */; }; + 3F1DFECF2C4B552E00BAA193 /* SafariView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F1DFECE2C4B552E00BAA193 /* SafariView.swift */; }; 3F3DE2F82C1DE2500089CB5A /* InfomationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F3DE2F72C1DE2500089CB5A /* InfomationView.swift */; }; 3F3DE2FA2C1DE2710089CB5A /* AddView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F3DE2F92C1DE2710089CB5A /* AddView.swift */; }; 3F6AA4B82C2FDF22008EC918 /* PasswordField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F6AA4B72C2FDF22008EC918 /* PasswordField.swift */; }; @@ -62,11 +63,12 @@ 3F026F282C39A2E400ED696C /* EditViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditViewModel.swift; sourceTree = ""; }; 3F026F2A2C39A3F100ED696C /* AddViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddViewModel.swift; sourceTree = ""; }; 3F026F372C3A622500ED696C /* LicenseList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LicenseList.swift; sourceTree = ""; }; - 3F026F412C3A77A600ED696C /* Contact.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Contact.swift; sourceTree = ""; }; + 3F026F412C3A77A600ED696C /* OpenURLInSafariViewModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenURLInSafariViewModifier.swift; sourceTree = ""; }; 3F026F432C3A789500ED696C /* URLs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLs.swift; sourceTree = ""; }; 3F13F9C52C1DECF30068908E /* InfomationViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfomationViewModel.swift; sourceTree = ""; }; 3F13F9C72C1DED720068908E /* EditView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditView.swift; sourceTree = ""; }; 3F13F9CA2C1DEE020068908E /* PasswordFormView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PasswordFormView.swift; sourceTree = ""; }; + 3F1DFECE2C4B552E00BAA193 /* SafariView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SafariView.swift; sourceTree = ""; }; 3F3DE2F72C1DE2500089CB5A /* InfomationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfomationView.swift; sourceTree = ""; }; 3F3DE2F92C1DE2710089CB5A /* AddView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddView.swift; sourceTree = ""; }; 3F6AA4B72C2FDF22008EC918 /* PasswordField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PasswordField.swift; sourceTree = ""; }; @@ -164,7 +166,8 @@ 3F3DE2F72C1DE2500089CB5A /* InfomationView.swift */, 3F13F9C52C1DECF30068908E /* InfomationViewModel.swift */, 3F026F372C3A622500ED696C /* LicenseList.swift */, - 3F026F412C3A77A600ED696C /* Contact.swift */, + 3F026F412C3A77A600ED696C /* OpenURLInSafariViewModifier.swift */, + 3F1DFECE2C4B552E00BAA193 /* SafariView.swift */, ); path = Info; sourceTree = ""; @@ -439,11 +442,12 @@ 3F13F9C62C1DECF30068908E /* InfomationViewModel.swift in Sources */, 3F13F9CB2C1DEE020068908E /* PasswordFormView.swift in Sources */, 3FEE0F162C3C2EDE0057EE2F /* AppTips.swift in Sources */, + 3F1DFECF2C4B552E00BAA193 /* SafariView.swift in Sources */, 3F026F442C3A789500ED696C /* URLs.swift in Sources */, 3F99FC512C390D65001ED4B2 /* IconStyles.swift in Sources */, 3F8C85C72C189F230032277E /* CellView.swift in Sources */, 3F026F2B2C39A3F100ED696C /* AddViewModel.swift in Sources */, - 3F026F422C3A77A600ED696C /* Contact.swift in Sources */, + 3F026F422C3A77A600ED696C /* OpenURLInSafariViewModifier.swift in Sources */, 3FC77A612C313C4500B56E75 /* IconView.swift in Sources */, 3F026F292C39A2E400ED696C /* EditViewModel.swift in Sources */, 3F6AA4BE2C3130FC008EC918 /* CreatePassword.swift in Sources */, diff --git a/PasswordBox/Resources/URLs.swift b/PasswordBox/Resources/URLs.swift index a1dceb7..2c7dfc4 100644 --- a/PasswordBox/Resources/URLs.swift +++ b/PasswordBox/Resources/URLs.swift @@ -2,6 +2,7 @@ import Foundation extension URL { struct InfomationView { + static let privacyPolicy = URL(string: "https://qiita.com/KaitoMuraoka/private/21637988ff296880f635")! static let contactURL = URL(string: "https://docs.google.com/forms/d/e/1FAIpQLSepth9cvpo71tNVjStRtxS0LFBqXkA6V21nXXb6NcQIem6FlA/viewform?usp=sf_link")! static let websiteURL = URL(string: "https://github.com/KaitoMuraoka/PasswordBox")! } diff --git a/PasswordBox/UI/Info/Contact.swift b/PasswordBox/UI/Info/Contact.swift deleted file mode 100644 index f3699aa..0000000 --- a/PasswordBox/UI/Info/Contact.swift +++ /dev/null @@ -1,18 +0,0 @@ -import SwiftUI -import WebUI - -struct Contact: View { - let url: URL - var body: some View { - WebViewReader { proxy in - WebView() - .onAppear { - proxy.load(request: URLRequest(url: url)) - } - } - } -} - -#Preview { - Contact(url: URL(string: "https://github.com/")!) -} diff --git a/PasswordBox/UI/Info/InfomationView.swift b/PasswordBox/UI/Info/InfomationView.swift index c0b13e0..28fceab 100644 --- a/PasswordBox/UI/Info/InfomationView.swift +++ b/PasswordBox/UI/Info/InfomationView.swift @@ -3,23 +3,21 @@ import SwiftUI struct InfomationView: View { private let viewModel = InfomationViewModel() private let contactUsTitle = "お問い合わせ" + private let privacyPolicy = "プライバシーポリシー" private let releaseNote = "リリースノート" private let WebSite = "Webサイト" private let licenceTitle = "LICENCE" var body: some View { List { Section("情報") { - Text("プライバシー") - - NavigationLink(contactUsTitle) { - Contact(url: URL.InfomationView.contactURL) - .navigationTitle(contactUsTitle) - } + Link(privacyPolicy, destination: URL.InfomationView.privacyPolicy) + .openURLInSafariView() + + Link(contactUsTitle, destination: URL.InfomationView.contactURL) + .openURLInSafariView() - NavigationLink(WebSite) { - Contact(url: URL.InfomationView.websiteURL) - .navigationTitle(WebSite) - } + Link(WebSite, destination: URL.InfomationView.websiteURL) + .openURLInSafariView() NavigationLink(licenceTitle) { LicenseList() diff --git a/PasswordBox/UI/Info/OpenURLInSafariViewModifier.swift b/PasswordBox/UI/Info/OpenURLInSafariViewModifier.swift new file mode 100644 index 0000000..22d77d8 --- /dev/null +++ b/PasswordBox/UI/Info/OpenURLInSafariViewModifier.swift @@ -0,0 +1,47 @@ +import SwiftUI + +struct OpenURLInSafariViewModifier: ViewModifier { + @State private var url: URL? = nil + private var isPresented: Binding { + Binding { + url != nil + } set: { newValue in + if newValue == false { + url = nil + } + } + } + + private let configuration: SafariView.Configuration? + + init(configuration: SafariView.Configuration?) { + self.configuration = configuration + } + + func body(content: Content) -> some View { + content + .environment(\.openURL, OpenURLAction { url in + switch url.scheme { + case "https"?, "http"?: + self.url = url + return .handled + default: + return .systemAction(url) + } + }) + .fullScreenCover(isPresented: isPresented) { + if let url { + SafariView(url: url, configuration: configuration) + .edgesIgnoringSafeArea(.all) + } + } + + } +} + +extension View { + func openURLInSafariView(configuration: SafariView.Configuration? = nil) -> some View { + return modifier(OpenURLInSafariViewModifier(configuration: configuration)) + } +} + diff --git a/PasswordBox/UI/Info/SafariView.swift b/PasswordBox/UI/Info/SafariView.swift new file mode 100644 index 0000000..2d255c1 --- /dev/null +++ b/PasswordBox/UI/Info/SafariView.swift @@ -0,0 +1,29 @@ +import SwiftUI +import SafariServices + +struct SafariView: UIViewControllerRepresentable { + typealias UIViewControllerType = SFSafariViewController + + typealias Configuration = SFSafariViewController.Configuration + + private let url: URL + private let configuration: Configuration? + + init(url: URL, configuration: Configuration? = nil) { + self.url = url + self.configuration = configuration + } + + func makeUIViewController(context: Context) -> SFSafariViewController { + let safariViewController: SFSafariViewController + if let configuration { + safariViewController = SFSafariViewController(url: url, configuration: configuration) + } else { + safariViewController = SFSafariViewController(url: url) + } + return safariViewController + } + + func updateUIViewController(_ uiViewController: SFSafariViewController, context: Context) { + } +} From 871d31977db95b7a209fe03aa2dbbe8a2dff03b9 Mon Sep 17 00:00:00 2001 From: KaitoMuraoka Date: Sat, 20 Jul 2024 11:24:56 +0900 Subject: [PATCH 2/2] delete WebUI --- PasswordBox.xcodeproj/project.pbxproj | 17 ----------------- .../xcshareddata/swiftpm/Package.resolved | 11 +---------- 2 files changed, 1 insertion(+), 27 deletions(-) diff --git a/PasswordBox.xcodeproj/project.pbxproj b/PasswordBox.xcodeproj/project.pbxproj index cb74284..ed0e0a9 100644 --- a/PasswordBox.xcodeproj/project.pbxproj +++ b/PasswordBox.xcodeproj/project.pbxproj @@ -13,7 +13,6 @@ 3F026F2B2C39A3F100ED696C /* AddViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F026F2A2C39A3F100ED696C /* AddViewModel.swift */; }; 3F026F362C3A618400ED696C /* LicenseList in Frameworks */ = {isa = PBXBuildFile; productRef = 3F026F352C3A618400ED696C /* LicenseList */; }; 3F026F382C3A622500ED696C /* LicenseList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F026F372C3A622500ED696C /* LicenseList.swift */; }; - 3F026F402C3A779900ED696C /* WebUI in Frameworks */ = {isa = PBXBuildFile; productRef = 3F026F3F2C3A779900ED696C /* WebUI */; }; 3F026F422C3A77A600ED696C /* OpenURLInSafariViewModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F026F412C3A77A600ED696C /* OpenURLInSafariViewModifier.swift */; }; 3F026F442C3A789500ED696C /* URLs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F026F432C3A789500ED696C /* URLs.swift */; }; 3F13F9C62C1DECF30068908E /* InfomationViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F13F9C52C1DECF30068908E /* InfomationViewModel.swift */; }; @@ -99,7 +98,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 3F026F402C3A779900ED696C /* WebUI in Frameworks */, 3F026F362C3A618400ED696C /* LicenseList in Frameworks */, 3F026F252C3996D000ED696C /* KeychainAccess in Frameworks */, ); @@ -316,7 +314,6 @@ packageProductDependencies = ( 3F026F242C3996D000ED696C /* KeychainAccess */, 3F026F352C3A618400ED696C /* LicenseList */, - 3F026F3F2C3A779900ED696C /* WebUI */, ); productName = PasswordBox; productReference = 3F8C85972C189D4A0032277E /* PasswordBox.app */; @@ -394,7 +391,6 @@ packageReferences = ( 3F3972422C3995D600B5FD6F /* XCRemoteSwiftPackageReference "KeychainAccess" */, 3F026F342C3A618400ED696C /* XCRemoteSwiftPackageReference "LicenseList" */, - 3F026F3E2C3A779900ED696C /* XCRemoteSwiftPackageReference "WebUI" */, ); productRefGroup = 3F8C85982C189D4A0032277E /* Products */; projectDirPath = ""; @@ -815,14 +811,6 @@ minimumVersion = 0.7.0; }; }; - 3F026F3E2C3A779900ED696C /* XCRemoteSwiftPackageReference "WebUI" */ = { - isa = XCRemoteSwiftPackageReference; - repositoryURL = "https://github.com/cybozu/WebUI.git"; - requirement = { - kind = upToNextMajorVersion; - minimumVersion = 2.1.0; - }; - }; 3F3972422C3995D600B5FD6F /* XCRemoteSwiftPackageReference "KeychainAccess" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/kishikawakatsumi/KeychainAccess"; @@ -844,11 +832,6 @@ package = 3F026F342C3A618400ED696C /* XCRemoteSwiftPackageReference "LicenseList" */; productName = LicenseList; }; - 3F026F3F2C3A779900ED696C /* WebUI */ = { - isa = XCSwiftPackageProductDependency; - package = 3F026F3E2C3A779900ED696C /* XCRemoteSwiftPackageReference "WebUI" */; - productName = WebUI; - }; /* End XCSwiftPackageProductDependency section */ }; rootObject = 3F8C858F2C189D4A0032277E /* Project object */; diff --git a/PasswordBox.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/PasswordBox.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index e8d7be9..bc40649 100644 --- a/PasswordBox.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/PasswordBox.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "6d9693d0d2ebed2cce70d1e7c0cf6be2d1dcbd91244366a4a87fba11ed359b12", + "originHash" : "46542c2fcfadddac75e8477df6fe867ef001d3e27b778582482db7dd9f45229e", "pins" : [ { "identity" : "keychainaccess", @@ -18,15 +18,6 @@ "revision" : "0828b88c1a6130d56ede2cc6c41ec50068a7ebd6", "version" : "0.7.0" } - }, - { - "identity" : "webui", - "kind" : "remoteSourceControl", - "location" : "https://github.com/cybozu/WebUI.git", - "state" : { - "revision" : "4708709d7c33c84b102eea73d91bd8baea49640b", - "version" : "2.1.0" - } } ], "version" : 3