캡처 후 포커스 해제

특수 상호작용 모드 (예: 삽입된 그리기 캔버스, 게임 컨트롤러 표면 또는 모달 입력 대화상자)에서 앱은 포커스를 단일 구성요소로 일시적으로 잠그고 Tab 또는 방향 키가 다른 곳으로 이동하지 못하도록 해야 할 수 있습니다.

포커스 캡처

포커스를 캡처하려면 FocusRequester에서 captureFocus()를 호출합니다.

val focusRequester = remember { FocusRequester() }

Box(
    modifier = Modifier
        .focusRequester(focusRequester)
        .focusable()
        .onFocusChanged { focusState ->
            if (focusState.isFocused) {
                focusRequester.captureFocus()
            }
        }
)

포커스가 캡처된 동안 표준 포커스 탐색 키 (예: Tab)는 포커스를 인접 구성요소로 이동하지 않습니다.

포커스 해제

캡처된 상태를 종료하고 UI에서 일반 포커스 탐색을 복원하려면 freeFocus()를 호출하세요.

IconButton(
    onClick = {
        focusRequester.freeFocus()
    }
) {
    Icon(Icons.Default.Close, contentDescription = "Exit focus lock")
}