Skip to content

Commit 6f7f963

Browse files
danilobuergerferrannp
authored andcommitted
fix: measure and layout after adding a view to the container (#2)
1 parent d0a3116 commit 6f7f963

File tree

1 file changed

+1
-13
lines changed

1 file changed

+1
-13
lines changed

android/src/main/java/com/reactnativecommunity/viewpager/ReactViewPager.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,11 @@ private class Adapter extends PagerAdapter {
3636
void addView(View child, int index) {
3737
mViews.add(index, child);
3838
notifyDataSetChanged();
39-
// This will prevent view pager from detaching views for pages that are not currently selected
40-
// We need to do that since {@link ViewPager} relies on layout passes to position those views
41-
// in a right way (also thanks to {@link ReactViewPagerManager#needsCustomLayoutForChildren}
42-
// returning {@code true}). Currently we only call {@link View#measure} and
43-
// {@link View#layout} after yoga step.
44-
45-
// TODO(7323049): Remove this workaround once we figure out a way to re-layout some views on
46-
// request
47-
setOffscreenPageLimit(mViews.size());
4839
}
4940

5041
void removeViewAt(int index) {
5142
mViews.remove(index);
5243
notifyDataSetChanged();
53-
54-
// TODO(7323049): Remove this workaround once we figure out a way to re-layout some views on
55-
// request
56-
setOffscreenPageLimit(mViews.size());
5744
}
5845

5946
/**
@@ -102,6 +89,7 @@ public int getItemPosition(Object object) {
10289
public Object instantiateItem(ViewGroup container, int position) {
10390
View view = mViews.get(position);
10491
container.addView(view, 0, generateDefaultLayoutParams());
92+
post(measureAndLayout);
10593
return view;
10694
}
10795

0 commit comments

Comments
 (0)