Skip to content

Instantly share code, notes, and snippets.

@victorbrndls
Created October 19, 2021 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victorbrndls/9c9753e86f6fc226c37c8c94cc1e40f3 to your computer and use it in GitHub Desktop.
Save victorbrndls/9c9753e86f6fc226c37c8c94cc1e40f3 to your computer and use it in GitHub Desktop.
val focusRequester = remember { FocusRequester() }
var color by remember { mutableStateOf(Black) }
Box(
Modifier
.clickable { focusRequester.requestFocus() }
.border(2.dp, color)
// The focusRequester should be added BEFORE the focusable.
.focusRequester(focusRequester)
// The onFocusChanged should be added BEFORE the focusable that is being observed.
.onFocusChanged { color = if (it.isFocused) Green else Black }
.focusable()
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment