Skip to content

Commit

Permalink
Minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
eonist committed Nov 29, 2024
1 parent 482e8d9 commit e54d93b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
18 changes: 9 additions & 9 deletions Sources/BlurView/blur/Blur.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ import UIKit
* - Fixme: ⚠️️ Make all this as a view modifier? or?
* - Fixme: ⚠️️ Move into multiple files?
*/
struct BlurView: UIViewRepresentable {
fileprivate struct BlurView: UIViewRepresentable {
/**
* The tinting color for the blur effect.
* - Description: The color used to tint the blur effect, allowing customization of the blur appearance to match the app's design theme.
*/
var tintingColor: Color
fileprivate var tintingColor: Color
/**
* Creates and configures a UIVisualEffectView for the BlurView.
* - Description: This function creates and configures a UIVisualEffectView instance for the BlurView. It uses the provided context to access necessary information and applies the tinting color to the UIVisualEffectView to achieve the desired blur effect.
* - Parameter context: The context containing the coordinator and other necessary information for creating the UIVisualEffectView.
* - Returns: The configured UIVisualEffectView instance.
*/
func makeUIView(context: Context) -> UIVisualEffectView {
fileprivate func makeUIView(context: Context) -> UIVisualEffectView {
// Initializes an EffectView with the tintingColor converted to a UIColor
EffectView(tintingColor: .init(tintingColor))
}
Expand All @@ -33,7 +33,7 @@ struct BlurView: UIViewRepresentable {
* - uiView: The UIVisualEffectView to be updated.
* - context: The context containing the latest state.
*/
func updateUIView(_ uiView: UIVisualEffectView, context: Context) {
fileprivate func updateUIView(_ uiView: UIVisualEffectView, context: Context) {
uiView.effect = UIBlurEffect(style: .regular) // Sets the blur effect style to regular
}
}
Expand All @@ -42,19 +42,19 @@ struct BlurView: UIViewRepresentable {
* - Description: The `BlurModifier` is a custom view modifier that applies a `BlurView` as a background to any SwiftUI view. The blur effect uses the specified `tintingColor` to create a frosted glass look, adding visual depth and focus to the content layered on top of it.
* - Fixme: ⚠️️ Rename to something else later, like?
*/
struct BlurModifier: ViewModifier {
fileprivate struct BlurModifier: ViewModifier {
/**
* The tinting color for the blur effect.
* - Description: The color used to tint the blur effect, allowing customization of the blur appearance to match the app's design theme.
*/
var tintingColor: Color
fileprivate var tintingColor: Color
/**
* Applies the BlurView to the content view.
* - Description: This modifier wraps the content view with a BlurView, which overlays a UIVisualEffectView configured with a UIBlurEffect. The tintingColor is applied to the blur effect, creating a visually appealing backdrop that enhances the focus on the content.
* - Parameter content: The content view to apply the BlurView to.
* - Returns: The modified content view with the BlurView applied.
*/
func body(content: Content) -> some View {
fileprivate func body(content: Content) -> some View {
content
.background(BlurView(tintingColor: tintingColor)) // This is primary with 0.8 for light mode
}
Expand All @@ -75,7 +75,7 @@ extension View {
* - Parameter tintingColor: The color to tint the blur effect with.
* - Returns: A view with the blur effect applied to its background.
*/
func blurBG(_ tintingColor: Color) -> some View {
public func blurBG(_ tintingColor: Color) -> some View {
// - Fixme: ⚠️️ We can do .subTitle here with a view-modifer for Text
let modifier = BlurModifier(tintingColor: tintingColor)
return self.modifier(modifier)
Expand All @@ -92,7 +92,7 @@ extension View {
Text("Hello, World!")
.blurBG(.black.opacity(0.6))
}
.previewLayout(.sizeThatFits)
// .previewLayout(.sizeThatFits)
.padding()
}
#endif
2 changes: 1 addition & 1 deletion Sources/BlurView/blur/EffectView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ struct EffectViewRepresentable: UIViewRepresentable {
*/
#Preview {
EffectViewRepresentable(tintingColor: .gray)
.previewLayout(.sizeThatFits)
// .previewLayout(.sizeThatFits)
.padding()
}
#endif
12 changes: 8 additions & 4 deletions Sources/BlurView/blur/HeaderOverlay.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import SwiftUI
* - saturation: The color saturation for the header overlay.
* - Returns: A view representing the header overlay with the specified height and saturation.
*/
public func headerOverlay(height: CGFloat, saturation: Color/* = Color.blackOrWhite.opacity(0.12)*/) -> some View {
Rectangle() // Create header background (adds the frosted background to header)
@ViewBuilder public func headerOverlay(height: CGFloat, saturation: Color/* = Color.blackOrWhite.opacity(0.12)*//*, shouldIgnoresSafeArea: Bool = false*/) -> some View {
let view = Rectangle() // Create header background (adds the frosted background to header)
// .background(.green.opacity(0.2)) // debug
.foregroundColor(.clear)
// - Fixme: ⚠️️ make this .maxWidth? make sure tests keep running for all platforms etc
Expand All @@ -27,7 +27,11 @@ public func headerOverlay(height: CGFloat, saturation: Color/* = Color.blackOrWh
)
// .background(.green) // ⚠️️ debug
.blurBG(saturation) // 4 and 6 also looks cool we add Blur as a modifier?
.ignoresSafeArea() // ⚠️️ key to moving bg over safe-area
// if shouldIgnoresSafeArea {
view.ignoresSafeArea() // ⚠️️ key to moving bg over safe-area
// } else {
// view
// }
// Can probably also do: .edgesIgnoringSafeArea(.all)
}
/**
Expand All @@ -39,7 +43,7 @@ public func headerOverlay(height: CGFloat, saturation: Color/* = Color.blackOrWh
*/
#Preview {
headerOverlay(height: 100, saturation: Color.black.opacity(0.12))
.previewLayout(.sizeThatFits) // - Fixme: ⚠️️ Why do we need this?
// .previewLayout(.sizeThatFits) // - Fixme: ⚠️️ Why do we need this?
.padding()
}
#endif
1 change: 1 addition & 0 deletions Sources/BlurView/effect/DebugHeaderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import SwiftUI
* - Note: Best practice I think would be to use Material in a background() as both mac and ios has the same api. it requires the background color to be the native OS background color. But thats a limitation for the other solutions as well. unless we digg into legacy and figure out how to make custom background colors work
* - Fixme: ⚠️️ add the workaround in the example bello to the debugview
* ## Examplea:
* // ⚠️️ Seems we can also just do: padding(.top) here
* Rectangle() // the current workaround for seemless translucent views for macOS
* .inset(by: spacerHeight)
* .fill(Material.ultraThinMaterial)
Expand Down

0 comments on commit e54d93b

Please sign in to comment.