Skip to content

Commit

Permalink
fix: measure and layout after adding a view to the container (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
danilobuerger authored and ferrannp committed Feb 12, 2019
1 parent d0a3116 commit 6f7f963
Showing 1 changed file with 1 addition and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,11 @@ private class Adapter extends PagerAdapter {
void addView(View child, int index) {
mViews.add(index, child);
notifyDataSetChanged();
// This will prevent view pager from detaching views for pages that are not currently selected
// We need to do that since {@link ViewPager} relies on layout passes to position those views
// in a right way (also thanks to {@link ReactViewPagerManager#needsCustomLayoutForChildren}
// returning {@code true}). Currently we only call {@link View#measure} and
// {@link View#layout} after yoga step.

// TODO(7323049): Remove this workaround once we figure out a way to re-layout some views on
// request
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());
}

/**
Expand Down Expand Up @@ -102,6 +89,7 @@ public int getItemPosition(Object object) {
public Object instantiateItem(ViewGroup container, int position) {
View view = mViews.get(position);
container.addView(view, 0, generateDefaultLayoutParams());
post(measureAndLayout);
return view;
}

Expand Down

0 comments on commit 6f7f963

Please sign in to comment.