Fix ViewPager behavior with Nodes

Summary: @public Add a batch addition operation for ViewPager.

Differential Revision: D3597840
This commit is contained in:
Ahmed El-Helw 2016-07-22 15:30:58 -07:00
parent 520f70bd57
commit b8313b282b
3 changed files with 42 additions and 6 deletions

View File

@ -11,7 +11,9 @@ package com.facebook.react.flat;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import android.graphics.Rect;
import android.view.View;
@ -90,10 +92,15 @@ import com.facebook.react.uimanager.ViewManagerRegistry;
ViewGroup viewGroup = (ViewGroup) view;
ViewGroupManager viewManager = (ViewGroupManager) resolveViewManager(reactTag);
for (int i = 0; i < viewsToAdd.length; ++i) {
int tag = Math.abs(viewsToAdd[i]);
viewManager.addView(viewGroup, resolveView(tag), i);
List<View> listOfViews = new ArrayList<>(viewsToAdd.length);
// batch the set of additions - some view managers can take advantage of the batching to
// decrease operations, etc.
for (int viewIdToAdd : viewsToAdd) {
int tag = Math.abs(viewIdToAdd);
listOfViews.add(resolveView(tag));
}
viewManager.addViews(viewGroup, listOfViews);
}
/**
@ -171,9 +178,7 @@ import com.facebook.react.uimanager.ViewManagerRegistry;
ViewGroup viewGroup = (ViewGroup) view;
ViewGroupManager viewManager = (ViewGroupManager) resolveViewManager(viewTag);
for (int i = viewManager.getChildCount(viewGroup) - 1; i >= 0; --i) {
viewManager.removeViewAt(viewGroup, i);
}
viewManager.removeAllViews(viewGroup);
}
}
}

View File

@ -57,6 +57,7 @@ public class FlatUIImplementation extends UIImplementation {
viewManagers.add(new RCTTextInlineImageManager());
viewManagers.add(new RCTImageViewManager());
viewManagers.add(new RCTTextInputManager());
viewManagers.add(new RCTViewPagerManager());
viewManagers.add(new RCTModalHostManager(reactContext));
ViewManagerRegistry viewManagerRegistry = new ViewManagerRegistry(viewManagers);

View File

@ -0,0 +1,30 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.facebook.react.flat;
import java.util.List;
import android.view.View;
import com.facebook.react.views.viewpager.ReactViewPager;
import com.facebook.react.views.viewpager.ReactViewPagerManager;
/* package */ class RCTViewPagerManager extends ReactViewPagerManager {
@Override
public void addViews(ReactViewPager parent, List<View> views) {
parent.setViews(views);
}
@Override
public void removeAllViews(ReactViewPager parent) {
parent.removeAllViewsFromAdapter();
}
}