Skip to content

Commit

Permalink
Update ViewGroupManager interface to use index for remove method.
Browse files Browse the repository at this point in the history
Differential Revision: D2610700

fb-gh-sync-id: b59dfc581d9ca8d29203b5915fb743f3270989ab
  • Loading branch information
kmagiera authored and facebook-github-bot-5 committed Nov 3, 2015
1 parent e63fb0e commit 6c204dc
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -310,19 +310,7 @@ public void manageChildren(
viewsToAdd,
tagsToDelete));
}
View childView = viewManager.getChildAt(viewToManage, indicesToRemove[i]);
if (childView == null) {
throw new IllegalViewOperationException(
"Trying to remove a null view at index:"
+ indexToRemove + " view tag: " + tag + "\n detail: " +
constructManageChildrenErrorMessage(
viewToManage,
viewManager,
indicesToRemove,
viewsToAdd,
tagsToDelete));
}
viewManager.removeView(viewToManage, childView);
viewManager.removeViewAt(viewToManage, indicesToRemove[i]);
lastIndexToRemove = indexToRemove;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public View getChildAt(T parent, int index) {
return parent.getChildAt(index);
}

public void removeView(T parent, View child) {
parent.removeView(child);
public void removeViewAt(T parent, int index) {
parent.removeViewAt(index);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,10 @@ public void addView(View child, int index) {
notifyDataSetChanged();
}

public void removeView(View child) {
if (mViews.remove(child)) {
public void removeViewAt(int index) {
View child = mViews.get(index);
if (child != null) {
mViews.remove(index);
mTopOffsetsFromLayout.remove(child);
child.removeOnLayoutChangeListener(mChildLayoutChangeListener);
mTotalChildrenHeight -= child.getMeasuredHeight();
Expand Down Expand Up @@ -271,8 +273,8 @@ public RecyclerViewBackedScrollView(Context context) {
((ReactListAdapter) getAdapter()).addView(child, index);
}

/*package*/ void removeViewFromAdapter(View child) {
((ReactListAdapter) getAdapter()).removeView(child);
/*package*/ void removeViewFromAdapter(int index) {
((ReactListAdapter) getAdapter()).removeViewAt(index);
}

/*package*/ View getChildAtFromAdapter(int index) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public View getChildAt(RecyclerViewBackedScrollView parent, int index) {
}

@Override
public void removeView(RecyclerViewBackedScrollView parent, View child) {
parent.removeViewFromAdapter(child);
public void removeViewAt(RecyclerViewBackedScrollView parent, int index) {
parent.removeViewFromAdapter(index);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,16 @@ public View getChildAt(ReactViewGroup parent, int index) {
}

@Override
public void removeView(ReactViewGroup parent, View child) {
public void removeViewAt(ReactViewGroup parent, int index) {
boolean removeClippedSubviews = parent.getRemoveClippedSubviews();
if (removeClippedSubviews) {
View child = getChildAt(parent, index);
if (child.getParent() != null) {
parent.removeView(child);
}
parent.removeViewWithSubviewClippingEnabled(child);
} else {
parent.removeView(child);
parent.removeViewAt(index);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ void addView(View child, int index) {
setOffscreenPageLimit(mViews.size());
}

void removeViewAt(int index) {
mViews.remove(index);
notifyDataSetChanged();

// TODO(7323049): Remove this workaround once we figure out a way to re-layout some views on
// request
setOffscreenPageLimit(mViews.size());
}

View getViewAt(int index) {
return mViews.get(index);
}

@Override
public int getCount() {
return mViews.size();
Expand Down Expand Up @@ -120,11 +133,23 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
return false;
}

/* package */ void addViewToAdapter(View child, int index) {
/*package*/ void addViewToAdapter(View child, int index) {
getAdapter().addView(child, index);
}

/* package */ void setCurrentItemFromJs(int item) {
/*package*/ void removeViewFromAdapter(int index) {
getAdapter().removeViewAt(index);
}

/*package*/ int getViewCountInAdapter() {
return getAdapter().getCount();
}

/*package*/ View getViewFromAdapter(int index) {
return getAdapter().getViewAt(index);
}

/*package*/ void setCurrentItemFromJs(int item) {
mIsCurrentItemFromJs = true;
setCurrentItem(item);
mIsCurrentItemFromJs = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,19 @@ public Map getExportedCustomDirectEventTypeConstants() {
public void addView(ReactViewPager parent, View child, int index) {
parent.addViewToAdapter(child, index);
}

@Override
public int getChildCount(ReactViewPager parent) {
return parent.getViewCountInAdapter();
}

@Override
public View getChildAt(ReactViewPager parent, int index) {
return parent.getViewFromAdapter(index);
}

@Override
public void removeViewAt(ReactViewPager parent, int index) {
parent.removeViewFromAdapter(index);
}
}

0 comments on commit 6c204dc

Please sign in to comment.