Native focus
Rive discovers focus nodes asynchronously after loading. The graphic can appear before the view can receive focus.Native focus varies by platform. See Apple’s guidance for iPadOS 15 and later, tvOS, and visionOS and Mac Catalyst. iPhone offers Full Keyboard Access as a separate accessibility feature.
- SwiftUI
- UIKit
- AppKit
RiveUIViewRepresentable and AsyncRiveUIViewRepresentable become focusable automatically when the graphic is ready. Add either view directly to your SwiftUI hierarchy.Requesting keyboard input
Keys go to the element that has focus, and the first element gets focus when the user navigates into the graphic, usually by pressing Tab. To send hardware-keyboard input to a graphic without that first Tab, such as WASD controls that work as soon as the graphic appears, make the view the keyboard responder. A request succeeds when the graphic is loaded, playing, in the key window, and has focus nodes. Rive then tries to focus the first element in the focus order, unless an element already has focus.Requesting keyboard input doesn’t enable text input or show the software keyboard.
- SwiftUI
- UIKit
- AppKit
Call Each change to
keyboardFocused(_:onResult:) on RiveUIViewRepresentable or AsyncRiveUIViewRepresentable, before any SwiftUI modifiers. The view waits until the graphic is ready before it makes the request.true makes one request, and a change to false gives up keyboard input. To request again, such as after you replace the view’s content, set the value to false and then back to true in a later update.To learn whether an attempt succeeded, pass onResult. Rive calls it after each attempt with the action, .become or .resign, and whether it succeeded.A change to true while the view is paused makes no request. Pausing or removing the view, or a loading failure, cancels a pending request. Rive doesn’t call onResult in these cases.Avoid combining keyboardFocused(_:onResult:) with SwiftUI’s focused(_:) on the same view.Moving between elements
- Tab and Shift+Tab follow the focus order set in the editor.
- Arrow keys move focus in the direction you press.
- On tvOS, the Siri Remote also moves focus. Rive treats the remote’s Select button as Enter. See Apple TV focus interactions.