I created this simple view to test focus in preview mode and I have no idea why it works absolutely fine on iphone, but not at all on ipad?
import SwiftUI
struct SimpleFocusTestView: View {
@FocusState private var isFocused: Bool
var body: some View {
Text("Test Focus")
.focusable()
.focused($isFocused)
.onTapGesture {
isFocused.toggle()
print("Tapped to toggle focus: \(isFocused)")
}
.onAppear { isFocused = true }
.onChange(of: isFocused) { oldValue, newValue in
print("Focus changed: \(newValue)")
}
.background {
if isFocused {
Capsule()
.fill(.indigo)
.opacity(0.3)
}
}
}
}
#Preview {
SimpleFocusTestView()
}
The printouts I get are:
if I click on ipad I get this:
Tapped to toggle focus: false Tapped to toggle focus: false Tapped to toggle focus: false
why is it impossible to change the value of isFocused on ipad? it all works fine on iphone:
Tapped to toggle focus: true Focus changed: false Tapped to toggle focus: false Focus changed: true