Skip to content

Commit

Permalink
Add home background
Browse files Browse the repository at this point in the history
  • Loading branch information
grgar committed Oct 8, 2023
1 parent e44e61e commit d664d42
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 1 deletion.
11 changes: 10 additions & 1 deletion ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct ContentView: View {
} icon: {
Image(systemName: "lock.rectangle")
}
.padding(.vertical)
}

NavigationLink {
Expand All @@ -32,6 +33,7 @@ struct ContentView: View {
} icon: {
Image(systemName: "rectangle.on.rectangle.angled")
}
.padding(.vertical)
}

NavigationLink {
Expand All @@ -47,6 +49,7 @@ struct ContentView: View {
} icon: {
Image(systemName: "rectangle.and.pencil.and.ellipsis")
}
.padding(.vertical)
}

NavigationLink {
Expand All @@ -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)
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions Domains/Appended2FA.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ struct Appended2FA: View {
await reload(cache: .returnCacheDataElseLoad)
}
.navigationTitle(Text("Appended 2FA"))
.navigationBarTitleDisplayMode(.large)
}
}

Expand Down
1 change: 1 addition & 0 deletions Domains/ChangePasswordURLs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ struct ChangePasswordURLs: View {
await reload(cache: .returnCacheDataElseLoad)
}
.navigationTitle(Text("Change Password"))
.navigationBarTitleDisplayMode(.large)
}
}

Expand Down
1 change: 1 addition & 0 deletions Domains/SharedCredentials.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ struct SharedCredentials: View {
await reload(cache: .returnCacheDataElseLoad)
}
.navigationTitle(Text("Shared Credentials"))
.navigationBarTitleDisplayMode(.large)
}
}

Expand Down
78 changes: 78 additions & 0 deletions HomeBackground.swift
Original file line number Diff line number Diff line change
@@ -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()
}
4 changes: 4 additions & 0 deletions Passwords Inspector.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand All @@ -29,6 +30,7 @@
1717C4AC2ABA473F00AD991A /* ChangePasswordURLs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChangePasswordURLs.swift; sourceTree = "<group>"; };
173245222AC4CE99005C3AC2 /* Rule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Rule.swift; sourceTree = "<group>"; };
173245242AC4D29D005C3AC2 /* PasswordRuleChips.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PasswordRuleChips.swift; sourceTree = "<group>"; };
174820E12AD33DD8006AF2AC /* HomeBackground.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeBackground.swift; sourceTree = "<group>"; };
17618B7B2AC200C600B31C28 /* PasswordRules.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PasswordRules.swift; sourceTree = "<group>"; };
17882AC42AC84AAD0037E3A6 /* PasswordRuleDetail.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PasswordRuleDetail.swift; sourceTree = "<group>"; };
17BFF6FF2ABCDDC2004047AD /* SharedCredentials.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SharedCredentials.swift; sourceTree = "<group>"; };
Expand All @@ -52,6 +54,7 @@
children = (
1717C49D2ABA44EC00AD991A /* PIApp.swift */,
1717C49F2ABA44EC00AD991A /* ContentView.swift */,
174820E12AD33DD8006AF2AC /* HomeBackground.swift */,
17882AC22AC848380037E3A6 /* Rule */,
17882AC32AC8483E0037E3A6 /* Domains */,
17BFF7012ABF217D004047AD /* Favicon.swift */,
Expand Down Expand Up @@ -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;
};
Expand Down
1 change: 1 addition & 0 deletions Rule/PasswordRuleDetail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ struct PasswordRuleDetail: View {
}
}
.navigationTitle(rule.id)
.navigationBarTitleDisplayMode(.large)
}
}

Expand Down
1 change: 1 addition & 0 deletions Rule/PasswordRules.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ struct PasswordRules: View {
await reload(cache: .returnCacheDataElseLoad)
}
.navigationTitle(Text("Password Rules"))
.navigationBarTitleDisplayMode(.large)
}
}

Expand Down

0 comments on commit d664d42

Please sign in to comment.