Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
janicduplessis committed Mar 23, 2017
1 parent 205a7f9 commit b1d7857
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

import javax.annotation.Nullable;

/**
* Helper to handle implementing ViewGroups with custom drawing order based on z-index.
*/
public class ViewGroupDrawingOrderHelper {
private final ViewGroup mViewGroup;
private int mNumberOfChildrenWithZIndex = 0;
Expand All @@ -29,6 +32,10 @@ public ViewGroupDrawingOrderHelper(ViewGroup viewGroup) {
mViewGroup = viewGroup;
}

/**
* This should be called every time a view is added to the ViewGroup in {@link ViewGroup#addView}.
* @param view The view that is being added
*/
public void handleAddView(View view) {
if (ReactViewManager.getViewZIndex(view) != null) {
mNumberOfChildrenWithZIndex++;
Expand All @@ -37,6 +44,11 @@ public void handleAddView(View view) {
mDrawingOrderIndices = null;
}

/**
* This should be called every time a view is removed from the ViewGroup in {@link ViewGroup#removeView}
* and {@link ViewGroup#removeViewAt}.
* @param view The view that is being removed.
*/
public void handleRemoveView(View view) {
if (ReactViewManager.getViewZIndex(view) != null) {
mNumberOfChildrenWithZIndex--;
Expand All @@ -45,10 +57,19 @@ public void handleRemoveView(View view) {
mDrawingOrderIndices = null;
}

/**
* If the ViewGroup should enable drawing order. ViewGroups should call
* {@link ViewGroup#setChildrenDrawingOrderEnabled} with the value returned from this method when
* a view is added or removed.
*/
public boolean shouldEnableCustomDrawingOrder() {
return mNumberOfChildrenWithZIndex > 0;
}

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

0 comments on commit b1d7857

Please sign in to comment.