Fix TB lose focus when recyclerview notify*Changed
- Override getItemId(), set setHasStableIds to true and setItemAnimator
to null to fix TalkBack when lose focus when receive notify*Changed()
- Issue's history and workaround all from b/37088814
video: https://drive.google.com/file/d/1gEDOUTY3A2OMDWKgPGvxourXmW-p9D9K/view?usp=sharing
Bug: 157007291
Test: manually, enable TB and test the result
Change-Id: I042f65bbc8f26f5685d83f3253b3ffff8d78ca73
diff --git a/src/com/android/customization/widget/OptionSelectorController.java b/src/com/android/customization/widget/OptionSelectorController.java
index 5b76b36..ef97385 100644
--- a/src/com/android/customization/widget/OptionSelectorController.java
+++ b/src/com/android/customization/widget/OptionSelectorController.java
@@ -160,6 +160,11 @@
return mOptions.get(position).getLayoutResId();
}
+ @Override
+ public long getItemId(int position) {
+ return position;
+ }
+
@NonNull
@Override
public TileViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
@@ -225,6 +230,11 @@
mContainer.setLayoutManager(new LinearLayoutManager(mContainer.getContext(),
LinearLayoutManager.HORIZONTAL, false));
Resources res = mContainer.getContext().getResources();
+
+ // A workaround from b/37088814, fix TalkBack will lose focus when receive notify*Changed()
+ mAdapter.setHasStableIds(true);
+ mContainer.setItemAnimator(null);
+
mContainer.setAdapter(mAdapter);
// Measure RecyclerView to get to the total amount of space used by all options.