FocusDirection


The FocusDirection is used to specify the direction for a FocusManager.moveFocus request.

import androidx.compose.foundation.focusable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusDirection
import androidx.compose.ui.platform.LocalFocusManager

val focusManager = LocalFocusManager.current
Column {
    Row {
        Box(Modifier.focusable())
        Box(Modifier.focusable())
    }
    Row {
        Box(Modifier.focusable())
        Box(Modifier.focusable())
    }
    Button(onClick = { focusManager.moveFocus(FocusDirection.Right) }) { Text("Right") }
    Button(onClick = { focusManager.moveFocus(FocusDirection.Left) }) { Text("Left") }
    Button(onClick = { focusManager.moveFocus(FocusDirection.Up) }) { Text("Up") }
    Button(onClick = { focusManager.moveFocus(FocusDirection.Down) }) { Text("Down") }
}

Summary

Public companion properties

FocusDirection

Direction used in FocusManager.moveFocus to indicate that you are searching for the next focusable item that is below the currently focused item.

Cmn
FocusDirection

Direction used in FocusManager.moveFocus to indicate that you are searching for the next focusable item that is a child of the currently focused item.

Cmn
FocusDirection

Direction used in FocusManager.moveFocus to indicate that you want to move focus to the parent of the currently focused item.

Cmn
FocusDirection

Direction used in FocusManager.moveFocus to indicate that you are searching for the next focusable item to the left of the currently focused item.

Cmn
FocusDirection

Direction used in FocusManager.moveFocus to indicate that you are searching for the next focusable item.

Cmn
FocusDirection

Direction used in FocusManager.moveFocus to indicate that you are searching for the previous focusable item.

Cmn
FocusDirection

Direction used in FocusManager.moveFocus to indicate that you are searching for the next focusable item to the right of the currently focused item.

Cmn
FocusDirection

Direction used in FocusManager.moveFocus to indicate that you are searching for the next focusable item that is above the currently focused item.

Cmn

Public functions

open String
Cmn

Public companion properties

Down

val DownFocusDirection

Direction used in FocusManager.moveFocus to indicate that you are searching for the next focusable item that is below the currently focused item.

import androidx.compose.foundation.focusable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusDirection
import androidx.compose.ui.platform.LocalFocusManager

val focusManager = LocalFocusManager.current
Column {
    Row {
        Box(Modifier.focusable())
        Box(Modifier.focusable())
    }
    Row {
        Box(Modifier.focusable())
        Box(Modifier.focusable())
    }
    Button(onClick = { focusManager.moveFocus(FocusDirection.Right) }) { Text("Right") }
    Button(onClick = { focusManager.moveFocus(FocusDirection.Left) }) { Text("Left") }
    Button(onClick = { focusManager.moveFocus(FocusDirection.Up) }) { Text("Up") }
    Button(onClick = { focusManager.moveFocus(FocusDirection.Down) }) { Text("Down") }
}

Enter

val EnterFocusDirection

Direction used in FocusManager.moveFocus to indicate that you are searching for the next focusable item that is a child of the currently focused item.

Exit

val ExitFocusDirection

Direction used in FocusManager.moveFocus to indicate that you want to move focus to the parent of the currently focused item.

Left

val LeftFocusDirection

Direction used in FocusManager.moveFocus to indicate that you are searching for the next focusable item to the left of the currently focused item.

import androidx.compose.foundation.focusable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusDirection
import androidx.compose.ui.platform.LocalFocusManager

val focusManager = LocalFocusManager.current
Column {
    Row {
        Box(Modifier.focusable())
        Box(Modifier.focusable())
    }
    Row {
        Box(Modifier.focusable())
        Box(Modifier.focusable())
    }
    Button(onClick = { focusManager.moveFocus(FocusDirection.Right) }) { Text("Right") }
    Button(onClick = { focusManager.moveFocus(FocusDirection.Left) }) { Text("Left") }
    Button(onClick = { focusManager.moveFocus(FocusDirection.Up) }) { Text("Up") }
    Button(onClick = { focusManager.moveFocus(FocusDirection.Down) }) { Text("Down") }
}

Next

val NextFocusDirection

Direction used in FocusManager.moveFocus to indicate that you are searching for the next focusable item.

import androidx.compose.foundation.focusable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusDirection
import androidx.compose.ui.platform.LocalFocusManager

val focusManager = LocalFocusManager.current
Column {
    Row {
        Box(Modifier.focusable())
        Box(Modifier.focusable())
    }
    Row {
        Box(Modifier.focusable())
        Box(Modifier.focusable())
    }
    Button(onClick = { focusManager.moveFocus(FocusDirection.Right) }) { Text("Right") }
    Button(onClick = { focusManager.moveFocus(FocusDirection.Left) }) { Text("Left") }
    Button(onClick = { focusManager.moveFocus(FocusDirection.Up) }) { Text("Up") }
    Button(onClick = { focusManager.moveFocus(FocusDirection.Down) }) { Text("Down") }
}

Previous

val PreviousFocusDirection

Direction used in FocusManager.moveFocus to indicate that you are searching for the previous focusable item.

import androidx.compose.foundation.focusable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusDirection
import androidx.compose.ui.platform.LocalFocusManager

val focusManager = LocalFocusManager.current
Column {
    Row {
        Box(Modifier.focusable())
        Box(Modifier.focusable())
    }
    Row {
        Box(Modifier.focusable())
        Box(Modifier.focusable())
    }
    Button(onClick = { focusManager.moveFocus(FocusDirection.Right) }) { Text("Right") }
    Button(onClick = { focusManager.moveFocus(FocusDirection.Left) }) { Text("Left") }
    Button(onClick = { focusManager.moveFocus(FocusDirection.Up) }) { Text("Up") }
    Button(onClick = { focusManager.moveFocus(FocusDirection.Down) }) { Text("Down") }
}

Right

val RightFocusDirection

Direction used in FocusManager.moveFocus to indicate that you are searching for the next focusable item to the right of the currently focused item.

import androidx.compose.foundation.focusable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusDirection
import androidx.compose.ui.platform.LocalFocusManager

val focusManager = LocalFocusManager.current
Column {
    Row {
        Box(Modifier.focusable())
        Box(Modifier.focusable())
    }
    Row {
        Box(Modifier.focusable())
        Box(Modifier.focusable())
    }
    Button(onClick = { focusManager.moveFocus(FocusDirection.Right) }) { Text("Right") }
    Button(onClick = { focusManager.moveFocus(FocusDirection.Left) }) { Text("Left") }
    Button(onClick = { focusManager.moveFocus(FocusDirection.Up) }) { Text("Up") }
    Button(onClick = { focusManager.moveFocus(FocusDirection.Down) }) { Text("Down") }
}

Up

val UpFocusDirection

Direction used in FocusManager.moveFocus to indicate that you are searching for the next focusable item that is above the currently focused item.

import androidx.compose.foundation.focusable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusDirection
import androidx.compose.ui.platform.LocalFocusManager

val focusManager = LocalFocusManager.current
Column {
    Row {
        Box(Modifier.focusable())
        Box(Modifier.focusable())
    }
    Row {
        Box(Modifier.focusable())
        Box(Modifier.focusable())
    }
    Button(onClick = { focusManager.moveFocus(FocusDirection.Right) }) { Text("Right") }
    Button(onClick = { focusManager.moveFocus(FocusDirection.Left) }) { Text("Left") }
    Button(onClick = { focusManager.moveFocus(FocusDirection.Up) }) { Text("Up") }
    Button(onClick = { focusManager.moveFocus(FocusDirection.Down) }) { Text("Down") }
}

Public functions

toString

open fun toString(): String