TalkbackTutorial / Application

An Android App as Talkback Tutorial.
6 stars 2 forks source link

Lesson 8 Module 2 Enhancement #53

Closed Andre-Pham closed 2 years ago

Andre-Pham commented 2 years ago

When returning from the external app the first time the last item (the button) was focused, instead of the first text element.

mcrossman commented 2 years ago

I've had a discussion with @Chokss54 about this as the same issue occurs in JumpText on certain fragment transitions. We couldn't find any other cases of this behaviour occurring but we were able to use sendAccessibilityEvent to force it to work. However, this solution doesn't work in this module.

The bug in detail

To reproduce, you need two fragments with the same layout structure, in this case being

The second fragment can have the same or more number of Views at the bottom. This bug doesn't happen if the second view has fewer Views than the first.

When you replace the first fragment with the second, TalkBack's focus will remain in the exact same place in the layout hierarchy as it was in the first fragment.

What should be happening

Fragment 1 Fragment 2
View View
View $\nearrow$ View
View View
View

When replacing Fragment 1 with Fragment 2, TalkBack should focus on the first View.

What is happening

Fragment 1 Fragment 2
View View
View View
View $\rightarrow$ View
View

When replacing Fragment 1 with Fragment 2, TalkBack erroneously focuses on the View that corresponds with the View of the previous layout.

Additional notes

The same thing happens in the opposite direction if you use the back stack. In this scenario, if you move to the 3rd View and go back, you end up on the 3rd View in the previous fragment. Strangely, when modifying JumpText as a test, the 2nd View mapped to the 1st View of the previous fragment.

Summary

This issue exhibits some exceptionally unusual behaviour in Android and I do not know how to fix it in this case. The solution used elsewhere to resolve this kind of problem is a hack, as focus is still going to the wrong place initially. There's a chance that this issue is caused by a bug in Android or TalkBack.

A quick fix would be to add more Views to the previous fragment so that the criteria for the bug are no longer met.

mcrossman commented 2 years ago

A quick fix (1 second time delay for sendAccessibilityEvent) was implemented in 302d38d9e3f25fc92f041151fad43b81126f6048.