The Developer Preview for Android 11 is now available; test it out and share your feedback.

FocusNode

class FocusNode : ComponentNode
kotlin.Any
   ↳ androidx.ui.core.ComponentNode
   ↳ androidx.ui.core.FocusNode

Backing node that implements focus.

Summary

Public constructors

Backing node that implements focus.

Public methods

Unit
attach(owner: Owner)

Add this focusable child to the parent's focusable children list.

Boolean

Deny requests to clear focus.

Unit

Remove this focusable child from the parent's focusable children list.

Boolean

When the node is in the Captured state, it rejects all requests to clear focus.

Unit
requestFocus(propagateFocus: Boolean = true)

Request focus for this node.

Inherited functions

Extension functions

From androidx.ui.core.focus
Unit

Checks the focus state of the Owner and Initializes the focus state of the node.

Inherited extension functions

From androidx.ui.core
Unit

Inserts a child ComponentNode at a last index.

ComponentNode?

Executes selector on every parent of this ComponentNode and returns the closest ComponentNode to return true from selector or null if selector returns false for all ancestors.

LayoutNode?

Executes block on first level of LayoutNode descendants of this ComponentNode and returns the last LayoutNode to return true from block.

Boolean

Returns true if this ComponentNode has no descendant LayoutNodes.

Boolean

Returns true if this ComponentNode currently has an ComponentNode.owner.

Owner

Returns ComponentNode.owner or throws if it is null.

Unit

Executes block on first level of LayoutNode descendants of this ComponentNode.

From androidx.compose
operator T

IMPORTANT: This global operator is TEMPORARY, and should be removed whenever an answer for contextual composers is reached.

Properties

FocusDetailedState

The focus state for the current component.

LayoutCoordinates?

The LayoutCoordinates of the OnChildPositioned component that hosts the child components of this FocusNode.

() -> Unit

Ref<FocusNode>?

Implementation oddity around composition; used to capture a reference to this FocusNode when composed.

Inherited properties

Public constructors

<init>

FocusNode()

Backing node that implements focus.

Public methods

attach

fun attach(owner: Owner): Unit

Add this focusable child to the parent's focusable children list.

captureFocus

fun captureFocus(): Boolean

Deny requests to clear focus.

This is used when a component wants to hold onto focus (eg. A phone number field with an invalid number.

Return
true if the focus was successfully captured. False otherwise.

detach

fun detach(): Unit

Remove this focusable child from the parent's focusable children list.

freeFocus

fun freeFocus(): Boolean

When the node is in the Captured state, it rejects all requests to clear focus. Calling freeFocus puts the node in the Active state, where it is no longer preventing other nodes from requesting focus.

Return
true if the captured focus was released. If the node is not in the Captured state. this function returns false to indicate that this operation was a no-op.

requestFocus

fun requestFocus(propagateFocus: Boolean = true): Unit

Request focus for this node.

Parameters
propagateFocus: Boolean = true

Whether the focus should be propagated to the node's children.

In Compose, the parent FocusNode controls focus for its focusable children.Calling this function will send a focus request to this FocusNode's parent FocusNode.

Properties

focusState

var focusState: FocusDetailedState

The focus state for the current component. When the component is in the Active state, it receives key events and other actions. We use FocusDetailedStates internally and developers have the option to build their components using FocusDetailedState, or a subset of states defined in FocusState.

layoutCoordinates

var layoutCoordinates: LayoutCoordinates?

The LayoutCoordinates of the OnChildPositioned component that hosts the child components of this FocusNode.

recompose

var recompose: () -> Unit

ref

var ref: Ref<FocusNode>?

Implementation oddity around composition; used to capture a reference to this FocusNode when composed. This is a reverse property that mutates its right-hand side.

TODO: Once we finalize the API consider removing this and replace this with an interface that sets the value as a property on the object that needs it.