While working with SwiftUI I noticed a very unusual behavior. On iOS 14 when showing the keyboard on a modal screen the parent view also gets squeezed. To show what I mean I made a short demonstrator view and a short gif which shows the issue. You can find that here.
struct SqueezTestView: View {
@State var isModalPresented = false
@State var text = ""
@State var colors: [Color] = [.red, .green, .blue, .orange, .pink, .purple, .yellow]
var body: some View {
NavigationView {
VStack {
ForEach(0..<colors.count) { index in
colors[index]
.animation(.linear(duration: 1))
}
}
.navigationBarTitle("Squeez")
.navigationBarItems(leading: Button("Shuffel") { colors.shuffle() }, trailing: Button("Modal") { isModalPresented = true })
.sheet(isPresented: $isModalPresented) {
NavigationView {
VStack {
TextField("Test", text: $text, onCommit: {isModalPresented = false})
.padding()
Spacer()
}
.navigationBarTitle("Modal", displayMode: .inline)
.navigationBarItems(trailing: Button("Done") { isModalPresented = false })
}
}
}
}
}
I expected that only the modal view gets squeezed and parent view stays the same. In this case the parent view gets animated every time I dismiss the modal while the keyboard is visible. Is there anything I missed or are there any known fixes to this issue?