[ad_1]
TLDR: The view modifier .ignoresSafeArea(.keyboard)
doesn’t seem to work when used inside a backside sheet. Is there a workaround?
In a SwiftUI View, tapping a TextField invokes the keyboard and the Textfield then strikes upwards to keep away from the keyboard.
struct ContentView: View {
@State var mytext: String = "Some textual content"
var physique: some View {
VStack {
Spacer()
TextField("abc", textual content: $mytext)
Spacer()
}
}
}
This keyboard avoidance behaviour might be disabled by including the .ignoresSafeArea
modifier
struct ContentView: View {
@State var mytext: String = "Some textual content"
var physique: some View {
VStack {
Spacer()
TextField("abc", textual content: $mytext)
Spacer()
}
.ignoresSafeArea(.keyboard, edges: .backside)
}
}
and the TextField not strikes upwards.
If this method is utilized inside to a view in a backside sheet it not works and your entire sheet is pushed up by the keyboard.
struct ContentView: View {
@State var mytext: String = "Some textual content"
@State var isPresented: Bool = true
var physique: some View {
Coloration.mint
.sheet(isPresented: $isPresented) {
VStack {
Spacer()
TextField("abc", textual content: $mytext)
Spacer()
}
.presentationDetents( [.fraction(0.33)] )
.ignoresSafeArea(.keyboard, edges: .backside)
}
}
}
I’ve tried making use of .ignoresSafeArea(.keyboard, edges: .backside)
to each view thats uncovered within the code with no success.
I believe that the bug is because of the backside sheet implementation utilizing a UIHostingController internally. This could been seen utilizing Xcode’s Debug View Hierarchy instrument.
Others have described how UIHostingController doesn’t respect the .ignoresSafeArea(.keyboard, edges: .backside)
modifier and have developed workarounds however these usually are not relevant right here as a result of the UIHostingController is created internally, not explicitly in my code.
Is there any technique to get the view contained in the sheet to disregard the keyboard and keep put?
I am open to any and all options. Thanks!
[ad_2]