In iOS 15 SDK you added the new FocusState API in SwiftUI. However there is no discussion or explanation anywhere that I could find, which explains:
What exactly is "focus"?
What isn't focus?
What is the relationship between FocusState and accessibility focus?
What is the relationship between whether a SecureField is being edited, and whether it's "focused"?
Example:
Lets say my tvOS app has an on-screen keyboard, where the user uses the remote's directional controls to move focus around to the letter buttons. To enter their password, they focus the password field, then click the center button to activate it. Now that it's active, they move focus to each letter of their password and click on each one: P... A... S... S... W... R... D... !... then they move focus to the "Submit" button and click.
In this case, while the SecureField is being edited, focus moves around to a bunch of different buttons.
The point of this example is that, if SecureField had a public "isBeingEdited" property, then it would be TRUE even while the field is not focused.
However most Workday's designers interpret "focused" as being totally equivalent to "isBeingEdited" because in a web browser, tabbing out of a field makes it stop being edited.
What is Apple's intent here? When not using a remote or physical keyboard or screen-reader, how is focus supposed to relate to whether a field is being edited? Does this relationship change when a user now has a bluetooth keyboard connected and Full Keyboard Access is turned ON? How does this correlate with accessibility focus?
I cannot find any documentation from Apple that explains what focus is, or how this is supposed to work in SwiftUI in the various different scenarios where the concept of "focus" is relevant. Do you have a link to something current that explains how it's supposed to work so that we will know if there's a bug?
Last question: how can we make the iOS simulator treat the physical keyboard as if it was a bluetooth keyboard to be used for focus-based keyboard navigation?
Direct and reflect focus in SwiftUI
RSS for tagDiscuss the WWDC21 session Direct and reflect focus in SwiftUI.
Posts under wwdc21-10023 tag
2 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
In a SwiftUI lab, I was asking about setting the focus state down a view hierarchy. The answer I got was to pass the focus state down the views as a binding. Conceptually, that made sense, so I moved on to other questions. But now that I am trying to implement it, I am having problems.
In the parent view, I have something like this:
@FocusState private var focusElement: UUID?
Then I am setting a property like this in the child view:
@Binding var focusedId: UUID?
When I try to create the detail view, I'm trying this:
DetailView(focusedId: $focusElement)
But this doesn't work. The error I get is:
Cannot convert value of type 'FocusState<UUID?>.Binding' to expected argument type 'Binding<UUID?>'
What is the right way to pass down the focus state to a child view so that it can update back up to the parent view?
I am trying to update from one child view, and have a TextField in a sibling view get focus.