Upgrade to Pro — share decks privately, control downloads, hide ads and more …

2024年のナビゲーション・フォーカス対応:Composeでキーボード・ナビゲーションをサポー...

Tiphaine
September 12, 2024

 2024年のナビゲーション・フォーカス対応:Composeでキーボード・ナビゲーションをサポートしよう

Tiphaine

September 12, 2024
Tweet

More Decks by Tiphaine

Other Decks in Technology

Transcript

  1. 6

  2. 7

  3. Focus 11 • Accessibility Focus ≠ Navigation Focus • Nav

    Focus(ུ)͸ʮΩʔϘʔυɾφϏήʔγϣϯʯ ͱ΋ݺ͹ΕΔ • ͲͪΒ΋Focus NavigationͷҰछ 😵💫 Focusͷछྨ
  4. myView.setOnKeyListener { view, keyCode, event -> 36 } // αϙʔτ͍ͨ͠ΠϕϯτΛఆٛ͢Δ

    KeyEvent.KEYCODE_ENTER, ... -> { // Կ͔ॲཧ͢Δ true } else -> false when (keyCode) { ࢀߟɿAndroid Developers }
  5. myView.setOnKeyListener { view, keyCode, event -> } when (keyCode) {

    } 37 ΠϕϯτͷॏෳഉআΛ๨Εͳ͍ ⚠ when (keyCode) { ... } // ACTION_UP·Ͱ͸ಉ͡Πϕϯτ͕਺ճདྷͯ͠·͏ if (event.action != KeyEvent.ACTION_UP) { return@setOnKeyListener false }
  6. override fun onKeyUp(keyCode: Int, event: KeyEvent?)
 : Boolean { }

    return when (keyCode) { KeyEvent.KEYCODE_ENTER -> performClick() else -> ... } 38 ΧελϜɾϏϡʔͷ৔߹͸ɺ onKeyUp()ΛΦʔόʔϥΠυ͢Δ🚀
  7. 43 • ࿦ཧతͰҰ؏ͨ͠ॱংΛอͭ // Tab navigation
 android:nextFocusForward=“@id/...” // Directional navigation

    // ্ɺԼɺࠨ΋ผͷଐੑͰઃఆͰ͖Δ android:nextFocusRight=“@id/...” ༧૝͞ΕͨྲྀΕΛҡ࣋͢Δ
  8. ΧελϜΠϯδέʔλɿશΞϓϦϨϕϧ 49 <!-- themes.xml --> <style name=“AppTheme" ...> ... <item

    name="colorControlHighlight">...</item> </style> ΧελϜΠϯδέʔλ
  9. ΧελϜΠϯδέʔλɿཁૉϨϕϧ ᶃ ΧελϜΠϯδέʔλɿཁૉϨϕϧ 50 <!-- outline.xml --> <shape ... android:shape="rectangle">

    ... <stroke android:width="4dp" android:color=“@color/black” /> </shape> ΧελϜΠϯδέʔλ
  10. <!-- focus_selector.xml --> <selector ...> </selector> 51 <item android:drawable=“@drawable/outline” 


    android:state_focused="true" /> <item android:drawable="@color/transparent"/> ΧελϜΠϯδέʔλɿཁૉϨϕϧ ᶄ ΧελϜΠϯδέʔλɿཁૉϨϕϧ ΧελϜΠϯδέʔλ
  11. 01 54 Introduction to Focus Common Problems Focus in Compose

    02 03 Introduction to Focus Common Problems
  12. 59 Row { Column { } Column { } }

    CustomButton("1") CustomButton("2") CustomButton("3") CustomButton("4")
  13. 63 Modifier var color by remember { .focusable() mutableStateOf(transparent) }

    // FocusՄೳʹ͍ͨ͠ComposableͷModifier focusableͷModifier͸Ұ൪࠷ޙʹઃఆ͢΂͖ ⚠
  14. 64 Modifier .border(5.dp, indicatorColor) .onFocusChanged { focusState -> } color

    = if (focusState.isFocused) { black } else { transparent } var color by remember { ...} .focusable() 🎉
  15. 69 Modifier.onKeyEvent { keyEvent -> } when (keyEvent.key) { Modifier.onKeyEvent

    Key.Enter -> { // Կ͔ॲཧΛ͢Δ true } else -> false }
  16. 70 // ॏෳഉআ if (keyEvent.type != KeyEventType.KeyUp) { return@onPreviewKeyEvent false

    } when (keyEvent.key) { } when (keyEvent.key) { ... } Modifier.onKeyEvent { keyEvent -> } Modifier.onKeyEvent
  17. 73 ॱংΛม͑Δ - Tab Navigation Modifier.focusProperties { } next =

    } previous = ... ... • FocusPropertiesͱFocusRequesterΛ࢖͏ ॱংΛม͑Δ
  18. Modifier 75 val (first, second) = remember { FocusRequester.createRefs() }

    first // ̍൪໨ͷComposable // ̎൪໨ͷComposableʢߦ͖ઌʣ Modifier.focusRequester( ) ) second .focusRequester(
  19. 76 val (first, second) = remember { FocusRequester.createRefs() } Modifier

    .focusProperties { } second next = first) .focusRequester(
  20. 78 Modifier.focusProperties { left = ... right = ... up

    = ... down = ... } ॱংΛม͑Δ - Directional Nav ॱংΛม͑Δ
  21. Button( onClick = { ) { ... } TextField(... //

    ΫϦοΫͨ͠ΒɺTextFieldʹҠಈ͢Δ 81 ) }
  22. 82 Button( onClick = { ) { ... } TextField(...

    } ) val requester = remember { FocusRequester() } Modifier.focusRequester(requester) // ΫϦοΫͨ͠ΒɺTextFieldʹҠಈ͢Δ
  23. 83 Button( onClick = { ) { ... } TextField(...

    } ) val requester = remember { FocusRequester() } Modifier.focusRequester(requester) requester.requestFocus() // ΫϦοΫͨ͠ΒɺTextFieldʹҠಈ͢Δ
  24. 88

  25. 89

  26. 90

  27. 93

  28. 95 • Focus in Compose ɹ- Android DevelopersެࣜυΩϡϝϯτ • Android

    App Development: Accessibility ɹ(LinkedIn Learning) - Renato Iwashima ࢀߟ