-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathInvertedScrollContentView.java
More file actions
55 lines (48 loc) · 1.7 KB
/
InvertedScrollContentView.java
File metadata and controls
55 lines (48 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package chat.rocket.reactnative.scroll;
import android.view.View;
import com.facebook.react.views.view.ReactViewGroup;
import java.util.ArrayList;
import java.util.Collections;
/**
* Content view for inverted FlatLists. Reports its children to accessibility in reversed order so
* TalkBack traversal matches the visual order (newest-first) when used inside InvertedScrollView.
*/
public class InvertedScrollContentView extends ReactViewGroup {
private boolean mIsInvertedContent = false;
public InvertedScrollContentView(android.content.Context context) {
super(context);
}
public void setIsInvertedContent(boolean isInverted) {
mIsInvertedContent = isInverted;
}
@Override
public void addChildrenForAccessibility(ArrayList<View> outChildren) {
super.addChildrenForAccessibility(outChildren);
if (mIsInvertedContent) {
Collections.reverse(outChildren);
}
}
@Override
public void addFocusables(ArrayList<View> views, int direction, int focusableMode) {
super.addFocusables(views, direction, focusableMode);
if (mIsInvertedContent) {
// Find indices of focusables that are children of this view
ArrayList<Integer> childIndices = new ArrayList<>();
for (int i = 0; i < views.size(); i++) {
View v = views.get(i);
if (v.getParent() == this) {
childIndices.add(i);
}
}
// Reverse only the sublist of children focusables
int n = childIndices.size();
for (int i = 0; i < n / 2; i++) {
int idx1 = childIndices.get(i);
int idx2 = childIndices.get(n - 1 - i);
View temp = views.get(idx1);
views.set(idx1, views.get(idx2));
views.set(idx2, temp);
}
}
}
}