I'm trying to make a View that will put a Blur() at the bottom of an iPhone layout, respecting safeareas and that I can easily reuse.
Something like this:
import SwiftUI
struct SafeBottomBlurContainer: View {
@Environment(\.colorScheme) var colorScheme
var body: some View {
GeometryReader { geometry in
VStack {
Spacer()
ZStack {
Blur(style: self.colorScheme == .dark ? .systemThinMaterialDark : .systemThinMaterialLight)
.frame(
width: geometry.size.width,
height: geometry.safeAreaInsets.bottom + 50
)
Holder()
.padding(.bottom, geometry.safeAreaInsets.bottom)
}
}
.edgesIgnoringSafeArea(.bottom)
}
}
}
struct Holder: View {
var body: some View {
Rectangle().opacity(0.5)
.frame(height: 50)
}
}
struct SafeBottomBlurContainer_Previews: PreviewProvider {
static var previews: some View {
SafeBottomBlurContainer()
}
}
Here is the ~~blue~~ blur extension, by the way:
import SwiftUI
struct Blur: UIViewRepresentable {
var style: UIBlurEffect.Style = .systemMaterial
func makeUIView(context: Context) -> UIVisualEffectView {
return UIVisualEffectView(effect: UIBlurEffect(style: style))
}
func updateUIView(_ uiView: UIVisualEffectView, context: Context) {
uiView.effect = UIBlurEffect(style: style)
}
}
Now, what I'd like to do is somehow pass in Holder()
so that I can adjust the height of the Blur (which here is + 50). I feel like I should be using AnyView in some manner, but can't figure it out. That might be me on the wrong track.
Here is how I'd like to use it in a ContentView() example:
import SwiftUI
struct ContentView: View {
var body: some View {
ZStack {
Color.pink.edgesIgnoringSafeArea(.all)
SafeBottomBlurContainer(containedView: MyCustomViewWithWhateverHeight)
}
}
}