From d664d42f75110e26cf19d9ea77eeb72302f790d0 Mon Sep 17 00:00:00 2001 From: George Garside Date: Sun, 8 Oct 2023 22:01:42 +0100 Subject: [PATCH] Add home background --- ContentView.swift | 11 ++- Domains/Appended2FA.swift | 1 + Domains/ChangePasswordURLs.swift | 1 + Domains/SharedCredentials.swift | 1 + HomeBackground.swift | 78 +++++++++++++++++++ Passwords Inspector.xcodeproj/project.pbxproj | 4 + Rule/PasswordRuleDetail.swift | 1 + Rule/PasswordRules.swift | 1 + 8 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 HomeBackground.swift diff --git a/ContentView.swift b/ContentView.swift index 220f0ea..d9c2bf1 100644 --- a/ContentView.swift +++ b/ContentView.swift @@ -17,6 +17,7 @@ struct ContentView: View { } icon: { Image(systemName: "lock.rectangle") } + .padding(.vertical) } NavigationLink { @@ -32,6 +33,7 @@ struct ContentView: View { } icon: { Image(systemName: "rectangle.on.rectangle.angled") } + .padding(.vertical) } NavigationLink { @@ -47,6 +49,7 @@ struct ContentView: View { } icon: { Image(systemName: "rectangle.and.pencil.and.ellipsis") } + .padding(.vertical) } NavigationLink { @@ -62,8 +65,13 @@ struct ContentView: View { } icon: { Image(systemName: "123.rectangle") } + .padding(.vertical) } } + .scrollContentBackground(.hidden) + .background { + HomeBackground() + } .listStyle(.sidebar) .navigationTitle(Text("Passwords Inspector")) .navigationBarTitleDisplayMode(.inline) @@ -72,7 +80,8 @@ struct ContentView: View { Label { Text("Passwords Inspector") } icon: { - Image(systemName: "key.viewfinder") + Image(systemName: "key.fill") + .rotationEffect(.radians(-0.3)) } .labelStyle(.titleAndIcon) .foregroundStyle(.tint, .tertiary) diff --git a/Domains/Appended2FA.swift b/Domains/Appended2FA.swift index e10795d..31d37a3 100644 --- a/Domains/Appended2FA.swift +++ b/Domains/Appended2FA.swift @@ -88,6 +88,7 @@ struct Appended2FA: View { await reload(cache: .returnCacheDataElseLoad) } .navigationTitle(Text("Appended 2FA")) + .navigationBarTitleDisplayMode(.large) } } diff --git a/Domains/ChangePasswordURLs.swift b/Domains/ChangePasswordURLs.swift index 23a6930..9f8725c 100644 --- a/Domains/ChangePasswordURLs.swift +++ b/Domains/ChangePasswordURLs.swift @@ -82,6 +82,7 @@ struct ChangePasswordURLs: View { await reload(cache: .returnCacheDataElseLoad) } .navigationTitle(Text("Change Password")) + .navigationBarTitleDisplayMode(.large) } } diff --git a/Domains/SharedCredentials.swift b/Domains/SharedCredentials.swift index 2f0ff7e..955b3d9 100644 --- a/Domains/SharedCredentials.swift +++ b/Domains/SharedCredentials.swift @@ -101,6 +101,7 @@ struct SharedCredentials: View { await reload(cache: .returnCacheDataElseLoad) } .navigationTitle(Text("Shared Credentials")) + .navigationBarTitleDisplayMode(.large) } } diff --git a/HomeBackground.swift b/HomeBackground.swift new file mode 100644 index 0000000..e0acd34 --- /dev/null +++ b/HomeBackground.swift @@ -0,0 +1,78 @@ +import SwiftUI + +struct HomeBackground: View { + var body: some View { + GeometryReader { geometry in + Image(systemName: "key.fill", size: .init(width: 64, height: 64), padding: .init(width: 12, height: 24)) + .resizable(resizingMode: .tile) + .modifier(InvertIfDark()) + .opacity(0.05) + .frame(width: geometry.size.width * 1.5, height: geometry.size.height * 1.5) + .rotationEffect(.radians(-0.3)) + .offset(x: -geometry.size.width * 0.25, y: -geometry.size.height * 0.25) + } + } +} + +struct InvertIfDark: ViewModifier { + @Environment(\.colorScheme) private var colorScheme + + func body(content: Content) -> some View { + if colorScheme == .dark { + content.colorInvert() + } else { + content + } + } +} + +extension Image { + init(systemName: String, size: CGSize, padding: CGSize = .zero) { + self.init(uiImage: UIImage(systemName: systemName)!.resizeImage(targetSize: size).addImagePadding(padding: padding)) + } +} + +extension UIImage { + // https://stackoverflow.com/a/31314494/1549818 + func resizeImage(targetSize: CGSize) -> UIImage { + let widthRatio = targetSize.width / size.width + let heightRatio = targetSize.height / size.height + + // Figure out what our orientation is, and use that to form the rectangle + var newSize: CGSize + if widthRatio > heightRatio { + newSize = CGSize(width: size.width * heightRatio, height: size.height * heightRatio) + } else { + newSize = CGSize(width: size.width * widthRatio, height: size.height * widthRatio) + } + + // This is the rect that we've calculated out and this is what is actually used below + let rect = CGRect(x: 0, y: 0, width: newSize.width, height: newSize.height) + + // Actually do the resizing to the rect using the ImageContext stuff + UIGraphicsBeginImageContextWithOptions(newSize, false, 1.0) + draw(in: rect) + let newImage = UIGraphicsGetImageFromCurrentImageContext() + UIGraphicsEndImageContext() + + return newImage! + } + + // https://stackoverflow.com/a/39480016/1549818 + func addImagePadding(padding: CGSize) -> UIImage { + let width = size.width + padding.width + let height = size.height + padding.height + let origin = CGPoint(x: (width - size.width) / 2, y: (height - size.height) / 2) + + UIGraphicsBeginImageContextWithOptions(CGSize(width: width, height: height), false, 0) + draw(at: origin) + let imageWithPadding = UIGraphicsGetImageFromCurrentImageContext() + UIGraphicsEndImageContext() + + return imageWithPadding! + } +} + +#Preview { + HomeBackground() +} diff --git a/Passwords Inspector.xcodeproj/project.pbxproj b/Passwords Inspector.xcodeproj/project.pbxproj index d29a8aa..4203da3 100644 --- a/Passwords Inspector.xcodeproj/project.pbxproj +++ b/Passwords Inspector.xcodeproj/project.pbxproj @@ -13,6 +13,7 @@ 1717C4AD2ABA473F00AD991A /* ChangePasswordURLs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1717C4AC2ABA473F00AD991A /* ChangePasswordURLs.swift */; }; 173245232AC4CE99005C3AC2 /* Rule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 173245222AC4CE99005C3AC2 /* Rule.swift */; }; 173245252AC4D29D005C3AC2 /* PasswordRuleChips.swift in Sources */ = {isa = PBXBuildFile; fileRef = 173245242AC4D29D005C3AC2 /* PasswordRuleChips.swift */; }; + 174820E22AD33DD8006AF2AC /* HomeBackground.swift in Sources */ = {isa = PBXBuildFile; fileRef = 174820E12AD33DD8006AF2AC /* HomeBackground.swift */; }; 17618B7C2AC200C600B31C28 /* PasswordRules.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17618B7B2AC200C600B31C28 /* PasswordRules.swift */; }; 17882AC52AC84AAD0037E3A6 /* PasswordRuleDetail.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17882AC42AC84AAD0037E3A6 /* PasswordRuleDetail.swift */; }; 17BFF7002ABCDDC2004047AD /* SharedCredentials.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17BFF6FF2ABCDDC2004047AD /* SharedCredentials.swift */; }; @@ -29,6 +30,7 @@ 1717C4AC2ABA473F00AD991A /* ChangePasswordURLs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChangePasswordURLs.swift; sourceTree = ""; }; 173245222AC4CE99005C3AC2 /* Rule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Rule.swift; sourceTree = ""; }; 173245242AC4D29D005C3AC2 /* PasswordRuleChips.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PasswordRuleChips.swift; sourceTree = ""; }; + 174820E12AD33DD8006AF2AC /* HomeBackground.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeBackground.swift; sourceTree = ""; }; 17618B7B2AC200C600B31C28 /* PasswordRules.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PasswordRules.swift; sourceTree = ""; }; 17882AC42AC84AAD0037E3A6 /* PasswordRuleDetail.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PasswordRuleDetail.swift; sourceTree = ""; }; 17BFF6FF2ABCDDC2004047AD /* SharedCredentials.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SharedCredentials.swift; sourceTree = ""; }; @@ -52,6 +54,7 @@ children = ( 1717C49D2ABA44EC00AD991A /* PIApp.swift */, 1717C49F2ABA44EC00AD991A /* ContentView.swift */, + 174820E12AD33DD8006AF2AC /* HomeBackground.swift */, 17882AC22AC848380037E3A6 /* Rule */, 17882AC32AC8483E0037E3A6 /* Domains */, 17BFF7012ABF217D004047AD /* Favicon.swift */, @@ -169,6 +172,7 @@ 17BFF7042ABF7D50004047AD /* Appended2FA.swift in Sources */, 17BFF7022ABF217D004047AD /* Favicon.swift in Sources */, 173245252AC4D29D005C3AC2 /* PasswordRuleChips.swift in Sources */, + 174820E22AD33DD8006AF2AC /* HomeBackground.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Rule/PasswordRuleDetail.swift b/Rule/PasswordRuleDetail.swift index ec7488e..10a78f6 100644 --- a/Rule/PasswordRuleDetail.swift +++ b/Rule/PasswordRuleDetail.swift @@ -108,6 +108,7 @@ struct PasswordRuleDetail: View { } } .navigationTitle(rule.id) + .navigationBarTitleDisplayMode(.large) } } diff --git a/Rule/PasswordRules.swift b/Rule/PasswordRules.swift index 15c09d5..324cb80 100644 --- a/Rule/PasswordRules.swift +++ b/Rule/PasswordRules.swift @@ -120,6 +120,7 @@ struct PasswordRules: View { await reload(cache: .returnCacheDataElseLoad) } .navigationTitle(Text("Password Rules")) + .navigationBarTitleDisplayMode(.large) } }