1

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 }
                }
            }
        }
    }
}
cire1776
  • 113
  • 1
  • 8
  • I am also facing the same issue after updating to iOS 15 & Xcode 13, iOS 14.4 & Xcode 12 working the same code without any issue. – Parth Dabhi Sep 30 '21 at 07:06
  • It's nice to not be the only one with the problem. A workaround or fix would be nice. I've had to stop UI testing under iOS 15 completely. – cire1776 Sep 30 '21 at 14:52

0 Answers0