Skip to content

Commit 70d3d9e

Browse files
Add comments
1 parent a116aed commit 70d3d9e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewGroupDrawingOrderHelper.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121
import javax.annotation.Nullable;
2222

23+
/**
24+
* Helper to handle implementing ViewGroups with custom drawing order based on z-index.
25+
*/
2326
public class ViewGroupDrawingOrderHelper {
2427
private final ViewGroup mViewGroup;
2528
private int mNumberOfChildrenWithZIndex = 0;
@@ -29,6 +32,10 @@ public ViewGroupDrawingOrderHelper(ViewGroup viewGroup) {
2932
mViewGroup = viewGroup;
3033
}
3134

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+
*/
3239
public void handleAddView(View view) {
3340
if (ReactViewManager.getViewZIndex(view) != null) {
3441
mNumberOfChildrenWithZIndex++;
@@ -37,6 +44,11 @@ public void handleAddView(View view) {
3744
mDrawingOrderIndices = null;
3845
}
3946

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+
*/
4052
public void handleRemoveView(View view) {
4153
if (ReactViewManager.getViewZIndex(view) != null) {
4254
mNumberOfChildrenWithZIndex--;
@@ -45,10 +57,19 @@ public void handleRemoveView(View view) {
4557
mDrawingOrderIndices = null;
4658
}
4759

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+
*/
4865
public boolean shouldEnableCustomDrawingOrder() {
4966
return mNumberOfChildrenWithZIndex > 0;
5067
}
5168

69+
/**
70+
* The index of the child view that should be drawn. This should be used in
71+
* {@link ViewGroup#getChildDrawingOrder}.
72+
*/
5273
public int getChildDrawingOrder(int childCount, int index) {
5374
if (mDrawingOrderIndices == null) {
5475
ArrayList<View> viewsToSort = new ArrayList<>();

0 commit comments

Comments
 (0)