On iOS 15, I am encountering problems with the focus of the keyboard, navigation views and popovers. I have tried to reproduce it in the following code, but it behaves slightly different to the app.
Here, it loses focus with each character. In the app, focus is never gained because the keyboard avoidance scrolling never happens or it fails to keep the focus. They may be two separate issues, but I think they are related.
This works as expected on iOS 14.8 and fails on a iPadPro with iOS 15 beta and in the Simulator. On devices with physical keyboards and on Mac Catalyst, it works fine as one would expect.
import SwiftUI
struct EditScreen: View {
@Binding var shownBinding: Bool
@State private var userName = ""
@State private var newKeyword = ""
@State private var addKeywordScreenShown = false
@State private var criteriaScreenShown = false
private var userSpecificElements: some View {
Section(header: Text("Criteria")) {
NavigationLink(isActive: $criteriaScreenShown, destination: {
GeometryReader { gp in
Group() {
NavigationLink(destination:
TextField("New Keyword", text: $newKeyword),
isActive: $addKeywordScreenShown)
{
Text("Add Keyword")
.padding(10)
.border(Color.primary)
.foregroundColor(.primary)
}
}
.background(Color.gray)
.frame(width: gp.size.width, height: gp.size.height)
}
})
{
HStack() {
Image(systemName: "plus.circle.fill")
Text("Add Criteria")
}
}
}
}
var body: some View {
NavigationView() {
Form() {
HStack() {
Text("Name")
Spacer()
TextField("Enter Name", text: $userName)
.keyboardType(.alphabet)
}
HStack() {
Text("Avatar")
Spacer()
Button(action: {}) {
Image(systemName: "person")
}
}
userSpecificElements
}
.navigationTitle("Edit User")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .primaryAction) {
Button("Save") {
shownBinding = false
userName = ""
}
}
ToolbarItem(placement: .cancellationAction) {
Button("Cancel") { shownBinding = false }
}
}
}
}
}