-
public final class FocusNodeKt
-
-
Method Summary
Modifier and Type Method Description final static UnitFocusControl(Function0<Boolean> requiresFocus, Function0<Unit> content)Coordinates focus for any composables in content and determines which composable will get focus. final static UnitOnFocusChange(Function2<CoroutineScope, Boolean, Unit> onFocusChanged)Use as part of a focus-requiring component to register a callback to be notified when the focus state changes. final static UnitRequestFocusWhenActive(FocusRequester focusRequester)Use as part of a focus-requiring component to register a callback to automatically request focus when this component is active. final static FocusRequesterrememberActiveFocusRequester()Creates, remembers and returns a new FocusRequester, that will have . -
-
Method Detail
-
FocusControl
@Composable()@Deprecated(message = Replaced with Wear Compose, replaceWith = @ReplaceWith(imports = {androidx.wear.compose.foundation.HierarchicalFocusCoordinator}, expression = HierarchicalFocusCoordinator(requiresFocus, content))) final static Unit FocusControl(Function0<Boolean> requiresFocus, Function0<Unit> content)
Coordinates focus for any composables in content and determines which composable will get focus. FocusControls can be nested, and form a tree, with an implicit root. Focus-requiring components (i.e. components using OnFocusChange or RequestFocusWhenActive) should only be in the leaf FocusControls, and there should be at most one per FocusControl. For FocusControl elements sharing a parent (or at the top level, sharing the implicit root parent), only one should have focus enabled. The selected FocusControl is the one that has focus enabled for itself and all ancestors, it will pass focus to its focus-requiring component if it has one, or call FocusManager#clearFocus() otherwise. If no FocusControl is selected, there will be no change on the focus state.
From https://android.googlesource.com/platform/frameworks/support/+/refs/changes/24/2171324/6/wear/compose/compose-foundation/src/commonMain/kotlin/androidx/wear/compose/foundation/Focus.kt
Example usage:
- Parameters:
requiresFocus- a function that returns true when the content is active in the composition and requires the focus
-
OnFocusChange
@Composable()@Deprecated(message = Replaced with Wear Compose, replaceWith = @ReplaceWith(imports = {androidx.wear.compose.foundation.OnFocusChange}, expression = OnFocusChange(onFocusChanged))) final static Unit OnFocusChange(Function2<CoroutineScope, Boolean, Unit> onFocusChanged)
Use as part of a focus-requiring component to register a callback to be notified when the focus state changes.
- Parameters:
onFocusChanged- callback to be invoked when the focus state changes, the parameter is the new state (if true, we are becoming active and should request focus).
-
RequestFocusWhenActive
@Composable()@Deprecated(message = Replaced with Wear Compose, replaceWith = @ReplaceWith(imports = {androidx.wear.compose.foundation.RequestFocusWhenActive}, expression = RequestFocusWhenActive(focusRequester))) final static Unit RequestFocusWhenActive(FocusRequester focusRequester)
Use as part of a focus-requiring component to register a callback to automatically request focus when this component is active. Note that this will may call requestFocus in the provided FocusRequester, so that focusRequester should be used in a .focusRequester modifier.
- Parameters:
focusRequester- The associated FocusRequester to request focus on.
-
rememberActiveFocusRequester
@Composable()@Deprecated(message = Replaced with Wear Compose, replaceWith = @ReplaceWith(imports = {androidx.wear.compose.foundation.rememberActiveFocusRequester}, expression = rememberActiveFocusRequester())) final static FocusRequester rememberActiveFocusRequester()
Creates, remembers and returns a new FocusRequester, that will have .requestFocus called when the enclosing HierarchicalFocusCoordinator becomes active. Note that the location you call this is important, in particular, which HierarchicalFocusCoordinator is enclosing it. Also, this may call requestFocus in the returned FocusRequester, so that focusRequester should be used in a .focusRequester modifier on a Composable that is part of the composition.
-
-
-
-