20
20
21
21
import javax .annotation .Nullable ;
22
22
23
+ /**
24
+ * Helper to handle implementing ViewGroups with custom drawing order based on z-index.
25
+ */
23
26
public class ViewGroupDrawingOrderHelper {
24
27
private final ViewGroup mViewGroup ;
25
28
private int mNumberOfChildrenWithZIndex = 0 ;
@@ -29,6 +32,10 @@ public ViewGroupDrawingOrderHelper(ViewGroup viewGroup) {
29
32
mViewGroup = viewGroup ;
30
33
}
31
34
35
+ /**
36
+ * This should be called every time a view is added to the ViewGroup in {@link ViewGroup#addView}.
37
+ * @param view The view that is being added
38
+ */
32
39
public void handleAddView (View view ) {
33
40
if (ReactViewManager .getViewZIndex (view ) != null ) {
34
41
mNumberOfChildrenWithZIndex ++;
@@ -37,6 +44,11 @@ public void handleAddView(View view) {
37
44
mDrawingOrderIndices = null ;
38
45
}
39
46
47
+ /**
48
+ * This should be called every time a view is removed from the ViewGroup in {@link ViewGroup#removeView}
49
+ * and {@link ViewGroup#removeViewAt}.
50
+ * @param view The view that is being removed.
51
+ */
40
52
public void handleRemoveView (View view ) {
41
53
if (ReactViewManager .getViewZIndex (view ) != null ) {
42
54
mNumberOfChildrenWithZIndex --;
@@ -45,10 +57,19 @@ public void handleRemoveView(View view) {
45
57
mDrawingOrderIndices = null ;
46
58
}
47
59
60
+ /**
61
+ * If the ViewGroup should enable drawing order. ViewGroups should call
62
+ * {@link ViewGroup#setChildrenDrawingOrderEnabled} with the value returned from this method when
63
+ * a view is added or removed.
64
+ */
48
65
public boolean shouldEnableCustomDrawingOrder () {
49
66
return mNumberOfChildrenWithZIndex > 0 ;
50
67
}
51
68
69
+ /**
70
+ * The index of the child view that should be drawn. This should be used in
71
+ * {@link ViewGroup#getChildDrawingOrder}.
72
+ */
52
73
public int getChildDrawingOrder (int childCount , int index ) {
53
74
if (mDrawingOrderIndices == null ) {
54
75
ArrayList <View > viewsToSort = new ArrayList <>();
0 commit comments