Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace WKWebView with SafariView #17

Merged
merged 2 commits into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 8 additions & 21 deletions PasswordBox.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
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 /* 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 */; };
Expand Down Expand Up @@ -62,11 +62,12 @@
3F026F282C39A2E400ED696C /* EditViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditViewModel.swift; sourceTree = "<group>"; };
3F026F2A2C39A3F100ED696C /* AddViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddViewModel.swift; sourceTree = "<group>"; };
3F026F372C3A622500ED696C /* LicenseList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LicenseList.swift; sourceTree = "<group>"; };
3F026F412C3A77A600ED696C /* Contact.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Contact.swift; sourceTree = "<group>"; };
3F026F412C3A77A600ED696C /* OpenURLInSafariViewModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenURLInSafariViewModifier.swift; sourceTree = "<group>"; };
3F026F432C3A789500ED696C /* URLs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLs.swift; sourceTree = "<group>"; };
3F13F9C52C1DECF30068908E /* InfomationViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfomationViewModel.swift; sourceTree = "<group>"; };
3F13F9C72C1DED720068908E /* EditView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditView.swift; sourceTree = "<group>"; };
3F13F9CA2C1DEE020068908E /* PasswordFormView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PasswordFormView.swift; sourceTree = "<group>"; };
3F1DFECE2C4B552E00BAA193 /* SafariView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SafariView.swift; sourceTree = "<group>"; };
3F3DE2F72C1DE2500089CB5A /* InfomationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfomationView.swift; sourceTree = "<group>"; };
3F3DE2F92C1DE2710089CB5A /* AddView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddView.swift; sourceTree = "<group>"; };
3F6AA4B72C2FDF22008EC918 /* PasswordField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PasswordField.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -97,7 +98,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
3F026F402C3A779900ED696C /* WebUI in Frameworks */,
3F026F362C3A618400ED696C /* LicenseList in Frameworks */,
3F026F252C3996D000ED696C /* KeychainAccess in Frameworks */,
);
Expand Down Expand Up @@ -164,7 +164,8 @@
3F3DE2F72C1DE2500089CB5A /* InfomationView.swift */,
3F13F9C52C1DECF30068908E /* InfomationViewModel.swift */,
3F026F372C3A622500ED696C /* LicenseList.swift */,
3F026F412C3A77A600ED696C /* Contact.swift */,
3F026F412C3A77A600ED696C /* OpenURLInSafariViewModifier.swift */,
3F1DFECE2C4B552E00BAA193 /* SafariView.swift */,
);
path = Info;
sourceTree = "<group>";
Expand Down Expand Up @@ -313,7 +314,6 @@
packageProductDependencies = (
3F026F242C3996D000ED696C /* KeychainAccess */,
3F026F352C3A618400ED696C /* LicenseList */,
3F026F3F2C3A779900ED696C /* WebUI */,
);
productName = PasswordBox;
productReference = 3F8C85972C189D4A0032277E /* PasswordBox.app */;
Expand Down Expand Up @@ -391,7 +391,6 @@
packageReferences = (
3F3972422C3995D600B5FD6F /* XCRemoteSwiftPackageReference "KeychainAccess" */,
3F026F342C3A618400ED696C /* XCRemoteSwiftPackageReference "LicenseList" */,
3F026F3E2C3A779900ED696C /* XCRemoteSwiftPackageReference "WebUI" */,
);
productRefGroup = 3F8C85982C189D4A0032277E /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -439,11 +438,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 */,
Expand Down Expand Up @@ -811,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";
Expand All @@ -840,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 */;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "6d9693d0d2ebed2cce70d1e7c0cf6be2d1dcbd91244366a4a87fba11ed359b12",
"originHash" : "46542c2fcfadddac75e8477df6fe867ef001d3e27b778582482db7dd9f45229e",
"pins" : [
{
"identity" : "keychainaccess",
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions PasswordBox/Resources/URLs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")!
}
Expand Down
18 changes: 0 additions & 18 deletions PasswordBox/UI/Info/Contact.swift

This file was deleted.

18 changes: 8 additions & 10 deletions PasswordBox/UI/Info/InfomationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
47 changes: 47 additions & 0 deletions PasswordBox/UI/Info/OpenURLInSafariViewModifier.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import SwiftUI

struct OpenURLInSafariViewModifier: ViewModifier {
@State private var url: URL? = nil
private var isPresented: Binding<Bool> {
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))
}
}

29 changes: 29 additions & 0 deletions PasswordBox/UI/Info/SafariView.swift
Original file line number Diff line number Diff line change
@@ -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) {
}
}