Contents

focusable(_:interactions:)

Specifies if the view is focusable, and if so, what focus-driven interactions it supports.

Declaration

nonisolated func focusable(_ isFocusable: Bool = true, interactions: FocusInteractions) -> some View

Parameters

  • isFocusable:

    true if the view should participate in focus; false otherwise. The default value is true.

  • interactions:

    The types of focus interactions supported by the view. The default value is .automatic.

Return Value

A view that sets whether its child is focusable.

Discussion

By default, SwiftUI enables all possible focus interactions. However, on macOS and iOS it is conventional for button-like views to only accept focus when the user has enabled keyboard navigation system-wide in the Settings app. Clients can reproduce this behavior with custom views by only supporting .activate interactions.

MyTapGestureView(...)
    .focusable(interactions: .activate)

See Also

Indicating that a view can receive focus