Создание проблем с фокусом доступности в HorizontalPagerAndroid

Форум для тех, кто программирует под Android
Ответить
Гость
 Создание проблем с фокусом доступности в HorizontalPager

Сообщение Гость »


Compose has FocusRequester() with the function requestFoucs() which seems to behave in unexpected and inconstant ways. The following is a great example of a focus issue which should be addressed.

Issue Overview:
We've implemented a HorizontalPager to showcase Cards. Users can swipe through these Card, and we've made efforts to ensure this feature is accessible to all users. However the focus mechanism behaves inconsistently during navigation.

Specific Behavior:
Initial Focus: Initially, when navigating to the HorizontalPager, the focus lands correctly on the current active Card, as expected.

First Swipe: UIpon swiping to the next Card (to the right) the focus correctly moves to the new active Card.
Second Swipe: Here the focus unexpectedly clears instead of landing on the next Card.

Attempted Solutions:
We've tried implementing the LaunchedEffect(Unit) with a delay, followed by focusRequester.requestFocus() intending to manually request focus for the next Card in the sequence. Unfortunately, this approach hasn't triggered the expected behavior, and the focus still fails to land on the third Card as anticipated.

Impact:
This issue poses a significant barrier to accessibility, making it challenging for users relying on screen readers to fully engage with our content. Ensuring proper focusing while navigation through our HorizonalPager is very important to provide an inclusive user experience in our app.

Request for Assistance:
Given the technical nature of this issue, we are reaching out here for insights or suggestions on how to address this focus inconsistency. We have provided issue on StackOverflow to raise greater awareness and are open to exploring alternative solutions if they may be available.

Attached is the mock code that demonstrates the issue:
// 1. Turn Talkback on for Accessibility // 2. Launch app // 3. Swipe through Horizontal carousel // 4. Notice how the accessibility focus clears upon the 2nd swipe // Actual behavior: Accessibility focus is cleared after 2nd swipe. // Expected behavior: Accessibility focus should always lock on the card after each swipe (left or right). class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { val requester = remember { FocusRequester() } TalkBackHorizontalPagerExperimentsTheme { // A surface container using the 'background' color from the theme Surface( modifier = Modifier .fillMaxSize() .focusRequester(requester) .focusable(), color = MaterialTheme.colorScheme.background, ) { LaunchedEffect(Unit) { delay(500) requester.requestFocus() Log.d("TAG", "onCreate: Trigger request") } val listOfCards = mutableListOf() listOfCards.add(Color.Green) listOfCards.add(Color.Black) listOfCards.add(Color.Red) listOfCards.add(Color.Yellow) listOfCards.add(Color.Blue) BasicPager(listOfCards = listOfCards) { index -> SomeCard(color = listOfCards[index], requester) } } } } } } @Composable fun SomeCard(color: Color, requester: FocusRequester) { Card( shape = RoundedCornerShape(10.dp), elevation = CardDefaults.cardElevation(defaultElevation = 10.dp), modifier = Modifier .fillMaxWidth() .height(200.dp) .border(width = 4.dp, color = Color.Black) .clipToBounds() .focusRequester(requester) .focusable() ) { Row( Modifier .fillMaxSize() .background(color = color) ) { } } } @OptIn(ExperimentalFoundationApi::class) @Composable fun BasicPager( listOfCards: MutableList, itemContent: @Composable (index: Int) -> Unit, ) { val state = rememberPagerState { listOfCards.size } HorizontalPager(state = state) { itemContent(it) } }

Источник: https://stackoverflow.com/questions/781 ... ontalpager
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»