Skip to content

Instantly share code, notes, and snippets.

@xenodium
Last active September 16, 2023 19:40
Show Gist options
  • Save xenodium/220005cdc1b0012868f9bdf8eebc1af0 to your computer and use it in GitHub Desktop.
Save xenodium/220005cdc1b0012868f9bdf8eebc1af0 to your computer and use it in GitHub Desktop.
blurred keyboard background
struct ContentView: View {
var body: some View {
ZStack(alignment: .bottom) {
// ...
VisualEffectView(effect: UIBlurEffect(style: .systemUltraThinMaterial))
.animation(.easeInOut)
.edgesIgnoringSafeArea(.all)
.onTapGesture {
UIApplication.shared.sendAction(
#selector(UIResponder.resignFirstResponder),
to: nil,
from: nil,
for: nil)
}
EditHabitView()
}
}
}
struct EditHabitView: View {
var body: some View {
VStack {
// ...
TextField(
"habit",
text: $title
) { _ in
// ...
}
// https://github.com/siteline/SwiftUI-Introspect.git
.introspectTextField { textField in
textField.returnKeyType = .done
textField.becomeFirstResponder()
}
}
}
}
struct VisualEffectView: UIViewRepresentable {
var effect: UIVisualEffect?
func makeUIView(context: UIViewRepresentableContext<Self>) -> UIVisualEffectView {
UIVisualEffectView()
}
func updateUIView(_ uiView: UIVisualEffectView, context: UIViewRepresentableContext<Self>) {
uiView.effect = effect
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment