ScrollView hicjacking focus in swiftui

Greetings!

I'm facing a problem handleling full keyboard access in my app. This is a simpler version of the code: struct PrimerTest: View { @FocusState private var focusedImage: Int?

var body: some View {
    VStack(alignment: .leading, spacing: 20) {
        Link("Go to google or smth", destination: URL(string: "https://google.com")!)
            .font(.headline)
        Text("First text")
        Text("Second text")
        HStack {
            Text("Label")
                .accessibilityHidden(true)
            
            Spacer()
            Button("Play") {
                print("Im a button")
            }
        }
        
        Text("Selecciona un perfil con el teclado (Tab):")
            .font(.caption)
            .foregroundColor(.secondary)
        
        HStack {
            ForEach(0..<5, id: \.self) { index in
                Image(systemName: "person.circle.fill")
                    .resizable()
                    .frame(width: 30, height: 30)
                    .focusable(true)
                    .focused($focusedImage, equals: index)
                    .foregroundStyle(focusedImage == index ? Color.blue : Color.gray)
                    .scaleEffect(focusedImage == index ? 1.2 : 1.0)
                    .animation(.easeInOut, value: focusedImage)
                    .accessibilityHidden(true)
            }
        }
    }
    .navigationTitle("Title n stuff")
    .padding()
}

}

And the focus behaves as expected and the important thing, we can access que button on the right side of the screen

But as soon as we introduce the scrollview, the right side button is unaccessible, since when we hit tab we go back to the back button in the nav stack header.

struct PrimerTest: View { @FocusState private var focusedImage: Int?

var body: some View {
    ScrollView {
        VStack(alignment: .leading, spacing: 20) {
            Link("Go to google or smth", destination: URL(string: "https://google.com")!)
                .font(.headline)
            Text("First text")
            Text("Second text")
            HStack {
                Text("Label")
                    .accessibilityHidden(true)
                
                Spacer()
                Button("Play") {
                    print("Im a button")
                }
            }
            
            Text("Selecciona un perfil con el teclado (Tab):")
                .font(.caption)
                .foregroundColor(.secondary)
            
            HStack {
                ForEach(0..<5, id: \.self) { index in
                    Image(systemName: "person.circle.fill")
                        .resizable()
                        .frame(width: 30, height: 30)
                        .focusable(true)
                        .focused($focusedImage, equals: index)
                        .foregroundStyle(focusedImage == index ? Color.blue : Color.gray)
                        .scaleEffect(focusedImage == index ? 1.2 : 1.0)
                        .animation(.easeInOut, value: focusedImage)
                        .accessibilityHidden(true)
                }
            }
        }
    }
    .navigationTitle("Title n stuff")
    .padding()
}

}

I've tried all the things I found online and none achieves an acceptable behavoir, I've seen ppl saying this issue has been fixed in ipados with the focusSection modifier, but I have not seen any fix fot this issue in ios.

Hi! Thanks for the detailed writeup. This doesn't look right, and is probably a bug.

Can you please file a bug report and include all this info you posted here (and feel free to link the post as well)

  • these code sample
  • these video recording

to the following link? https://developer.apple.com/bug-reporting/

We may also need logs. I think simulator logs get logged to the Mac's system so the steps on the site might help you capture logs from your Mac when you file. Otherwise, if you have a physical device that is running this code, those logs may be even better.

You can reply what the Feedback ID is for this issue and I'll make sure it gets to the right team to investigate.

ScrollView hicjacking focus in swiftui
 
 
Q