Instance Method

focusable(_:onFocusChange:)

Specifies if the view is focusable and, if so, adds an action to perform when the view comes into focus.

Declaration

func focusable(_ isFocusable: Bool = true, onFocusChange: @escaping (Bool) -> Void = { _ in }) -> some View

Parameters

isFocusable

A Boolean value that indicates whether this view is focusable.

onFocusChange

A closure that’s called whenever this view either gains or loses focus. The Boolean parameter to onFocusChange is true when the view is in focus; otherwise, it’s false.

Return Value

A view that sets whether a view is focusable, and triggers onFocusChange when the view gains or loses focus.

See Also

Handling View Hover and Focus

func onHover(perform: (Bool) -> Void) -> View

Adds an action to perform when the user moves the pointer over or away from the view’s frame.