Update ViewGroupManager interface to use index for remove method.

Differential Revision: D2610700

fb-gh-sync-id: b59dfc581d9ca8d29203b5915fb743f3270989ab
This commit is contained in:
Krzysztof Magiera 2015-11-03 08:54:12 -08:00 committed by facebook-github-bot-5
parent e63fb0e8c9
commit 6c204dcbea
7 changed files with 56 additions and 26 deletions

View File

@ -310,19 +310,7 @@ import com.facebook.react.touch.JSResponderHandler;
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;
}
}

View File

@ -44,8 +44,8 @@ public abstract class ViewGroupManager <T extends ViewGroup>
return parent.getChildAt(index);
}
public void removeView(T parent, View child) {
parent.removeView(child);
public void removeViewAt(T parent, int index) {
parent.removeViewAt(index);
}
/**

View File

@ -169,8 +169,10 @@ public class RecyclerViewBackedScrollView extends RecyclerView {
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();
@ -271,8 +273,8 @@ public class RecyclerViewBackedScrollView extends RecyclerView {
((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) {

View File

@ -48,8 +48,8 @@ public class RecyclerViewBackedScrollViewManager extends
}
@Override
public void removeView(RecyclerViewBackedScrollView parent, View child) {
parent.removeViewFromAdapter(child);
public void removeViewAt(RecyclerViewBackedScrollView parent, int index) {
parent.removeViewFromAdapter(index);
}
/**

View File

@ -195,16 +195,16 @@ public class ReactViewManager extends ViewGroupManager<ReactViewGroup> {
}
@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);
}
}
}

View File

@ -49,6 +49,19 @@ import com.facebook.react.uimanager.events.NativeGestureUtil;
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();
@ -120,11 +133,23 @@ import com.facebook.react.uimanager.events.NativeGestureUtil;
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;

View File

@ -58,4 +58,19 @@ public class ReactViewPagerManager extends ViewGroupManager<ReactViewPager> {
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);
}
}